fix(safe-markdown): do not mutate the shared sanitization schema#41298
fix(safe-markdown): do not mutate the shared sanitization schema#41298rusackas wants to merge 1 commit into
Conversation
getOverrideHtmlSchema passed the module-level defaultSchema import from rehype-sanitize as the first argument to lodash mergeWith, which mutates it. Because the array customizer concatenates, the allowed tags/attributes/protocols arrays grew on each call, progressively widening the sanitization allowlist for every SafeMarkdown instance app-wide. Merge into a fresh cloneDeep of the schema so the shared singleton is never modified. Adds tests asserting the original schema is not mutated and that repeated calls do not accumulate overrides. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Code Review Agent Run #f598a6Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41298 +/- ##
=======================================
Coverage 64.34% 64.34%
=======================================
Files 2653 2653
Lines 144952 144952
Branches 33433 33433
=======================================
+ Hits 93272 93273 +1
+ Misses 49996 49995 -1
Partials 1684 1684
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
SUMMARY
getOverrideHtmlSchemapassed the module-leveldefaultSchemaimport fromrehype-sanitizeas the first argument to lodashmergeWith, which mutates its first argument in place. Because the array customizer concatenates rather than replaces, the allowed tags/attributes/protocols arrays grew on each call — progressively widening the sanitization allowlist for everySafeMarkdowninstance across the app, not just the one with overrides.This merges into a fresh
cloneDeepof the schema so the shared singleton is never modified and repeated calls do not accumulate overrides.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — internal behavior.
TESTING INSTRUCTIONS
Tests added in
superset-frontend/packages/superset-ui-core/test/components/SafeMarkdown.test.tsx:defaultSchemaimport is unchanged after calls, and repeated calls do not accumulate the override (arrays do not grow).Run:
cd superset-frontend && npm run test -- packages/superset-ui-core/test/components/SafeMarkdown.test.tsxADDITIONAL INFORMATION