mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
fix(packages): escape HTML special chars in serializeAttributes to prevent XSS (#1670)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Wesley Luyten <me@wesleyluyten.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
Wesley Luyten
parent
9170a5879e
commit
accf4bfa34
@@ -72,12 +72,14 @@ function buildRenderModule(icons: { name: string; content: string }[]): string {
|
||||
return [
|
||||
`const icons = {\n${entries},\n};`,
|
||||
``,
|
||||
`function esc(v) { return String(v).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); }`,
|
||||
``,
|
||||
`export function renderIcon(name, attrs) {`,
|
||||
` const svg = icons[name];`,
|
||||
` if (!svg) return '';`,
|
||||
` if (!attrs) return svg;`,
|
||||
` const attrStr = Object.entries(attrs)`,
|
||||
` .map(([k, v]) => \` \${k}="\${v}"\`)`,
|
||||
` .map(([k, v]) => \` \${k}="\${esc(v)}"\`)`,
|
||||
` .join('');`,
|
||||
` return svg.replace('<svg', \`<svg\${attrStr}\`);`,
|
||||
`}`,
|
||||
|
||||
Reference in New Issue
Block a user