Skip to content

Commit bda32a6

Browse files
fix: sanitize SVG content by stripping masks, filters, and attributes for Cloudflare Edge stability
1 parent 9b27e2f commit bda32a6

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎scripts/updateBadgeLogo.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ async function updateBadgeLogo() {
1616
logoSvgContent = svgMatch[1]
1717
.replace(/<\?xml.*\?>/g, '')
1818
.replace(/<!DOCTYPE.*?>/g, '')
19-
.replace(/<metadata[\s\S]*?<\/metadata>/gi, '') // Strip metadata blocks causing namespace errors
19+
.replace(/<metadata[\s\S]*?<\/metadata>/gi, '')
20+
.replace(/<defs[\s\S]*?<\/defs>/gi, '')
21+
.replace(/<mask[\s\S]*?<\/mask>/gi, '')
22+
.replace(/\s(id|mask|filter|viewBox)="[^"]*"/gi, ' ') // Strip problematic attributes
23+
.replace(/\sstyle="[^"]*"/gi, (match) => match.includes('fill') ? match : ' ') // Keep styles only if they define fill
24+
.replace(/>\s+</g, '><') // Minify whitespace
2025
.trim();
2126

2227
const outputContent = `// Auto-generated build-time asset. Do not edit manually.
28+
// Sanitized to remove masks, filters, and metadata for Cloudflare Edge stability.
2329
export const logoSvgContent = \`${logoSvgContent}\`;
2430
`;
2531

0 commit comments

Comments
 (0)