🛡️ Sentinel: [CRITICAL] Fix XSS in blog markdown parser - #1082
google-labs-jules[bot] wants to merge 2 commits into
Conversation
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
| // Prevent javascript: URIs (XSS vector) | ||
| if (unescapedHref.trim().toLowerCase().startsWith("javascript:")) { | ||
| return label; | ||
| } |
There was a problem hiding this comment.
A Markdown URL such as [link](java\tscript:alert(document.domain)) bypasses this check because the link parser preserves the embedded tab and trim() removes only surrounding whitespace. The generated value is then placed in an anchor rendered through dangerouslySetInnerHTML. Standard URL parsing strips the tab and recognizes the javascript: scheme, so activating the link can execute script. Normalize the URL with a standards-compliant parser and allow only safe protocols instead of checking the raw prefix.
How this was verified: The unrestricted post body reaches processInline, whose tab-preserving href capture emits the unchecked value into an anchor consumed by dangerouslySetInnerHTML, while standard URL parsing recognizes it as the javascript: scheme.
Knowledge Base Used: Blog and feed publishing
|



🚨 Severity: CRITICAL
💡 Vulnerability: The custom markdown parsing logic in
src/app/blog/[slug]/page.tsxdirectly used user input for HTML string formatting without escaping characters. This allowed for both raw HTML injection (e.g.<script>) and maliciousjavascript:URI injections via link tags.🎯 Impact: XSS execution on any rendered blog post, potentially leading to unauthorized actions or data exfiltration if malicious input were provided.
🔧 Fix: Added a comprehensive
escapeHtmlutility. Sanitized the text before replacing markdown syntax tokens, enforcedescapeHtmlin code blocks, and strippedjavascript:protocol links in the markdown link parser.✅ Verification: Run
pnpm testandpnpm lintto verify that there are no regressions.PR created automatically by Jules for task 1057208448077118796 started by @thegdsks