fix: sanitize SVG without HTML reparsing#3707
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR refactors SVG sanitization in the page-icons plugin by removing the ChangesSVG Sanitization Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 Pull request artifacts
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/plugins/page-icons/page-icons.js`:
- Around line 45-48: The regexes that scrub on* attributes from rawInnerSVG only
match when '=' immediately follows the attribute name, so attributes like
`onload = "..."` slip through; update the three replace calls that operate on
rawInnerSVG (the ones currently matching /\son[\w-]+="[^"]*"/gi,
/\son[\w-]+='[^']*'/gi, and /\son[\w-]+=[^\s"'=<>`]+/gi) to allow optional
whitespace around the '=' (e.g. match `\s*=\s*`), and apply the same change to
the identical scrub at the later occurrence around line 84 to ensure attributes
with spaces are removed consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8952b20b-83ae-45ee-b6a6-d5a568bbdc64
📒 Files selected for processing (1)
src/plugins/page-icons/page-icons.js
fixes #3705
safeHTML()is incompatible here because it sanitizes by parsing the input as HTML, not as SVG/XML.It transforms:
into:
which makes it invalid. What we did is to get the the
safeHTMLcode fromwordpress/domand only mimic the removal ofscript(already done) andon. For reference, this is the original implementation:Summary by CodeRabbit