Skip to content

🛡️ Sentinel: [HIGH] Fix Regex-based XSS evasion in SVG validation - #1113

Merged
thegdsks merged 2 commits into
mainfrom
sentinel-svg-validation-xss-11245609607414445165
Sep 20, 2026
Merged

thegdsks merged 2 commits into
mainfrom
sentinel-svg-validation-xss-11245609607414445165

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

🚨 Severity: HIGH
💡 Vulnerability: validateSvg in src/lib/svg-validation.ts relied on Regex tests against the raw SVG string (/href\s*=\s*["']javascript:/i) to prevent malicious attributes. This is vulnerable to evasion using HTML entity encoding (e.g., javascript:alert(1)) or control characters, which Regex fails to catch but the browser will execute when parsed.
🎯 Impact: An attacker could submit a malicious SVG with entity-encoded XSS payloads that bypasses the validation and executes javascript when opened or rendered.
🔧 Fix: Changed the logic to use DOMParser to parse the SVG and traverse all elements, inspecting el.attributes after stripping whitespace/control characters. This ensures that the validation sees the same normalized attributes that the browser does.
✅ Verification: Verify by running pnpm test and pnpm lint. Attempting to validate <a href="&#x6A;avascript:alert(1)"> will now correctly fail validation.


PR created automatically by Jules for task 11245609607414445165 started by @thegdsks

@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b667df55-f984-4a51-8bcf-be4bd2195f34

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for opening your first pull request to thesvg! We appreciate you taking the time to contribute. Please make sure you've read the README for contribution guidelines. A maintainer will take a look soon.

@github-actions github-actions Bot added documentation Improvements or additions to documentation ui User interface changes labels Sep 19, 2026
@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The implementation appears safe to merge, although the existing non-blocking request for security regression tests remains outstanding.

Findings

  1. P2 Security fix lacks tests ▶

Summary

This PR strengthens SVG validation by inspecting attributes from the parsed SVG DOM rather than applying security checks to the raw source string.

  • Detects event-handler attributes across parsed SVG elements.
  • Normalizes href and namespaced *:href values before rejecting javascript: URLs.
  • Refactors the attribute inspection into a dedicated helper.
  • Documents the vulnerability and prevention guidance in the Sentinel record.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Raw SVG content] --> B[DOMParser]
  B --> C[Parsed SVG document]
  C --> D[Traverse all elements and attributes]
  D --> E{Event handler, script, or normalized javascript href?}
  E -->|Yes| F[Reject embedded-script check]
  E -->|No| G[Pass embedded-script check]
Loading

Reviews (2) · Last reviewed commit: "🛡️ Sentinel: Fix SonarCloud cognitive c..."

Comment thread src/lib/svg-validation.ts Outdated
Comment on lines +78 to +94
const allElements = doc.querySelectorAll("*");
for (let i = 0; i < allElements.length; i++) {
const el = allElements[i];
for (let j = 0; j < el.attributes.length; j++) {
const attr = el.attributes[j];
const name = attr.name.toLowerCase();
if (name.startsWith("on")) {
hasOnHandlers = true;
}
if (name === "href" || name.endsWith(":href")) {
const val = attr.value.replace(/[\s\x00-\x1F\x7F]+/g, "").toLowerCase();
if (val.startsWith("javascript:")) {
hasJavascriptHref = true;
}
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Security fix lacks tests

This security-sensitive rewrite has no regression test covering the behavior it introduces. Please add cases for numeric-entity-encoded and control-character-obfuscated javascript: values, namespaced xlink:href, ordinary JavaScript URLs, and event-handler attributes. Without these tests, a future refactor could silently reintroduce the documented XSS bypass.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@sonarqubecloud

Copy link
Copy Markdown

@thegdsks
thegdsks merged commit 72edef0 into main Sep 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ui User interface changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant