π‘οΈ Sentinel: [HIGH] Fix XSS vulnerability in custom Markdown link renderer#54
π‘οΈ Sentinel: [HIGH] Fix XSS vulnerability in custom Markdown link renderer#54AashishH15 wants to merge 1 commit into
Conversation
Removed `sanitizeHrefUrl` from `LatexBlock.tsx` and placed it into `markdownUtils.tsx`. Updated the custom `a` tag rendering for Markdown to properly sanitize `href` fields to prevent Javascript execution via `javascript:` links.
|
π 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. |
There was a problem hiding this comment.
Code Review
This pull request centralizes the sanitizeHrefUrl utility in markdownUtils.tsx and applies it to custom Markdown anchor tags to prevent XSS vulnerabilities. The review feedback correctly points out that using window.location.href directly can cause runtime errors in environments without a global window object (such as SSR or Node.js tests). Additionally, returning parsed.href converts relative paths to absolute URLs, which can break local routing; returning the original trimmed URL instead is recommended.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| export function sanitizeHrefUrl(raw: string): string { | ||
| const trimmed = raw.trim(); | ||
| try { | ||
| const parsed = new URL(trimmed, window.location.href); | ||
| const safeProtocols = ["http:", "https:", "mailto:"]; | ||
| if (safeProtocols.includes(parsed.protocol)) { | ||
| return parsed.href; | ||
| } | ||
| } catch { | ||
| // Not a valid URL β fall through | ||
| } | ||
| // Block unsafe or malformed URLs entirely | ||
| return "about:blank"; | ||
| } |
There was a problem hiding this comment.
Using window.location.href directly as the base URL for parsing can cause runtime errors in environments where window is not defined (such as Server-Side Rendering (SSR) or unit testing environments like Node.js).
Additionally, returning parsed.href converts relative URLs (e.g., /about or #section) into absolute URLs based on the current window location. This can break relative routing or portability. Returning the original trimmed URL when the protocol is safe preserves relative paths while still ensuring security.
| export function sanitizeHrefUrl(raw: string): string { | |
| const trimmed = raw.trim(); | |
| try { | |
| const parsed = new URL(trimmed, window.location.href); | |
| const safeProtocols = ["http:", "https:", "mailto:"]; | |
| if (safeProtocols.includes(parsed.protocol)) { | |
| return parsed.href; | |
| } | |
| } catch { | |
| // Not a valid URL β fall through | |
| } | |
| // Block unsafe or malformed URLs entirely | |
| return "about:blank"; | |
| } | |
| export function sanitizeHrefUrl(raw: string): string { | |
| const trimmed = raw.trim(); | |
| try { | |
| const base = typeof window !== "undefined" ? window.location.href : "http://localhost"; | |
| const parsed = new URL(trimmed, base); | |
| const safeProtocols = ["http:", "https:", "mailto:"]; | |
| if (safeProtocols.includes(parsed.protocol)) { | |
| return trimmed; | |
| } | |
| } catch { | |
| // Not a valid URL β fall through | |
| } | |
| // Block unsafe or malformed URLs entirely | |
| return "about:blank"; | |
| } |
π¨ Severity: HIGH
π‘ Vulnerability: XSS in un-sanitized Markdown links.
π― Impact: Attackers can inject
javascript:links into notes that execute arbitrarily when clicked.π§ Fix: Extracted
sanitizeHrefUrland applied it to the standardatag component renderer inui/utils/markdownUtils.tsx.β Verification:
npm run preflightpasses.PR created automatically by Jules for task 13949277134668210962 started by @AashishH15