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:
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 };
|
||||
Reference in new issue
Block a user