Skip to content

Commit 6b9ed2c

Browse files
iQQBotclaude
andauthored
fix: prevent XSS in returnToPath parameter by validating protocol (#20965)
The returnToPath parameter validation was vulnerable to XSS attacks using javascript: protocol URLs with matching hostnames (e.g., javascript://gitpod.io/). This fix ensures only HTTPS URLs with matching hostnames are trusted. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent c3d5051 commit 6b9ed2c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

components/dashboard/src/utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ test("urlHash and isTrustedUrlOrPath", () => {
4545
{ location: "/", trusted: true },
4646
// eslint-disable-next-line no-script-url
4747
{ location: "javascript:alert(1)", trusted: false },
48+
// XSS bypass attempt with javascript: protocol and matching hostname
49+
// eslint-disable-next-line no-script-url
50+
{ location: "javascript://example.org/%250aalert(1)", trusted: false },
51+
// Other protocol attempts
52+
{ location: "data:text/html,<script>alert(1)</script>", trusted: false },
53+
{ location: "vbscript:alert(1)", trusted: false },
4854
];
4955
isTrustedUrlOrPathCases.forEach(({ location, trusted }) => {
5056
expect(isTrustedUrlOrPath(location)).toBe(trusted);

components/dashboard/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ export function parseUrl(url: string): URL | null {
227227

228228
export function isTrustedUrlOrPath(urlOrPath: string) {
229229
const url = parseUrl(urlOrPath);
230-
const isTrusted = url ? window.location.hostname === url.hostname : urlOrPath.startsWith("/");
230+
const isTrusted = url
231+
? window.location.hostname === url.hostname && url.protocol === "https:"
232+
: urlOrPath.startsWith("/");
231233
if (!isTrusted) {
232234
console.warn("Untrusted URL", urlOrPath);
233235
}

0 commit comments

Comments
 (0)