-
Notifications
You must be signed in to change notification settings - Fork 117
Prevent XSS via unsafe href protocols in WebFetchToolCall #3403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,18 @@ interface NormalizedResult { | |
| error?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Allowlist http/https for clickable hrefs. Blocks javascript:, data:, vbscript:, etc. | ||
| */ | ||
| function isSafeHref(url: string): boolean { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 [CRF-2] This function duplicates the protocol allowlist already defined in More importantly, the file-local placement means Extract a boolean predicate to export function isSafeHref(url: string): boolean {
try {
return ALLOWED_BROWSER_URL_PROTOCOLS.has(new URL(url).protocol);
} catch {
return false;
}
}Then apply it here and at
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 [CRF-1] No test coverage for a security boundary function. The function is correct (verified by 7 reviewers against
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 [CRF-3] The
|
||
| try { | ||
| const protocol = new URL(url).protocol; | ||
| return protocol === "http:" || protocol === "https:"; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extract domain from URL for compact display | ||
| */ | ||
|
|
@@ -144,14 +156,18 @@ export const WebFetchToolCall: React.FC<WebFetchToolCallProps> = ({ | |
| <div className="bg-code-bg flex flex-wrap gap-4 rounded px-2 py-1.5 text-[11px] leading-[1.4]"> | ||
| <div className="flex min-w-0 gap-1.5"> | ||
| <span className="text-secondary font-medium">URL:</span> | ||
| <a | ||
| href={args.url} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="text-link font-monospace truncate hover:underline" | ||
| > | ||
| {args.url} | ||
| </a> | ||
| {isSafeHref(args.url) ? ( | ||
| <a | ||
| href={args.url} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="text-link font-monospace truncate hover:underline" | ||
| > | ||
| {args.url} | ||
| </a> | ||
| ) : ( | ||
| <span className="font-monospace truncate">{args.url}</span> | ||
| )} | ||
| </div> | ||
| {normalized?.success && normalized.title && ( | ||
| <div className="flex min-w-0 gap-1.5"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.