fix: content-based SVG detection, guard tests, document REDIS_CACHE_DB

- Detect SVG by content (magic bytes) in addition to MIME type to prevent
  sanitization bypass via mislabeled uploads
- Add guard test verifying DOMPurify actually strips dirty payloads
- Add looksLikeSvg detection test
- Document REDIS_CACHE_DB in .env.example
This commit is contained in:
Thomas Camlong committed 2026-08-07 21:22:25 +02:00
1 parent 33293ba1cf
commit e836d07d4c
4 files changed
+31 -4

No files matched your search

@@ -91,4 +91,11 @@ export const sanitizeSvg = (svgText: string) => {
return svgMatch ? svgMatch[0] : "";
};
// ponytail: content-based SVG detection — catches mislabeled MIME types.
// Ceiling: only checks first 512 bytes; deeply embedded SVG in other XML won't match.
export function looksLikeSvg(content: Uint8Array): boolean {
const head = new TextDecoder().decode(content.subarray(0, 512));
return /<svg[\s>]/i.test(head);
}
export { svgSanitizeOptions, purify };