Skip to content

Commit 3c38035

Browse files
committed
security: replace innerHTML with textContent and DOM API to prevent XSS
1 parent 6f1f0ca commit 3c38035

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

JavaScript/2630. Memoize II/Claude Code Sonnet 4.6 extended/README_react.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,12 +2190,16 @@ <h3 className="text-teal-800 text-lg font-bold m-0">
21902190
document.querySelectorAll('header nav').forEach((nav) => {
21912191
const labels = ['概要', '解説', 'コード', 'フロー', '計算量'];
21922192
const ids = ['overview', 'steps', 'code', 'diagram', 'complexity'];
2193-
nav.innerHTML = labels
2194-
.map(
2195-
(l, i) =>
2196-
`<a href="#${ids[i]}" class="inline-block px-5 py-2 font-semibold text-slate-700 no-underline rounded-xl border-2 border-slate-200 bg-white/80 transition-all hover:shadow-[0_8px_20px_rgba(15,118,110,0.20)] hover:-translate-y-0.5 hover:bg-[linear-gradient(180deg,#e8fff6,#c8f1e1)] hover:border-teal-600">${l}</a>`,
2197-
)
2198-
.join('');
2193+
const frag = document.createDocumentFragment();
2194+
labels.forEach((label, i) => {
2195+
const link = document.createElement('a');
2196+
link.href = `#${ids[i]}`;
2197+
link.className =
2198+
'inline-block px-5 py-2 font-semibold text-slate-700 no-underline rounded-xl border-2 border-slate-200 bg-white/80 transition-all hover:shadow-[0_8px_20px_rgba(15,118,110,0.20)] hover:-translate-y-0.5 hover:bg-[linear-gradient(180deg,#e8fff6,#c8f1e1)] hover:border-teal-600';
2199+
link.textContent = label;
2200+
frag.appendChild(link);
2201+
});
2202+
nav.replaceChildren(frag);
21992203
});
22002204
Prism.highlightAll();
22012205
</script>

public/JavaScript/2630. Memoize II/Claude Code Sonnet 4.6 extended/README_react.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,12 +2190,16 @@ <h3 className="text-teal-800 text-lg font-bold m-0">
21902190
document.querySelectorAll('header nav').forEach((nav) => {
21912191
const labels = ['概要', '解説', 'コード', 'フロー', '計算量'];
21922192
const ids = ['overview', 'steps', 'code', 'diagram', 'complexity'];
2193-
nav.innerHTML = labels
2194-
.map(
2195-
(l, i) =>
2196-
`<a href="#${ids[i]}" class="inline-block px-5 py-2 font-semibold text-slate-700 no-underline rounded-xl border-2 border-slate-200 bg-white/80 transition-all hover:shadow-[0_8px_20px_rgba(15,118,110,0.20)] hover:-translate-y-0.5 hover:bg-[linear-gradient(180deg,#e8fff6,#c8f1e1)] hover:border-teal-600">${l}</a>`,
2197-
)
2198-
.join('');
2193+
const frag = document.createDocumentFragment();
2194+
labels.forEach((label, i) => {
2195+
const link = document.createElement('a');
2196+
link.href = `#${ids[i]}`;
2197+
link.className =
2198+
'inline-block px-5 py-2 font-semibold text-slate-700 no-underline rounded-xl border-2 border-slate-200 bg-white/80 transition-all hover:shadow-[0_8px_20px_rgba(15,118,110,0.20)] hover:-translate-y-0.5 hover:bg-[linear-gradient(180deg,#e8fff6,#c8f1e1)] hover:border-teal-600';
2199+
link.textContent = label;
2200+
frag.appendChild(link);
2201+
});
2202+
nav.replaceChildren(frag);
21992203
});
22002204
Prism.highlightAll();
22012205
</script>

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ <h1 class="site-title">
789789

790790
<footer>
791791
<span class="footer-icon">🧪</span>
792-
Generated on 2026-02-23 03:29:42 UTC
792+
Generated on 2026-02-23 03:38:33 UTC
793793
</footer>
794794

795795
<script>

0 commit comments

Comments
 (0)