Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/dashboard/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ test("urlHash and isTrustedUrlOrPath", () => {
{ location: "/", trusted: true },
// eslint-disable-next-line no-script-url
{ location: "javascript:alert(1)", trusted: false },
// XSS bypass attempt with javascript: protocol and matching hostname
// eslint-disable-next-line no-script-url
{ location: "javascript://example.org/%250aalert(1)", trusted: false },
// Other protocol attempts
{ location: "data:text/html,<script>alert(1)</script>", trusted: false },
{ location: "vbscript:alert(1)", trusted: false },
];
isTrustedUrlOrPathCases.forEach(({ location, trusted }) => {
expect(isTrustedUrlOrPath(location)).toBe(trusted);
Expand Down
4 changes: 3 additions & 1 deletion components/dashboard/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export function parseUrl(url: string): URL | null {

export function isTrustedUrlOrPath(urlOrPath: string) {
const url = parseUrl(urlOrPath);
const isTrusted = url ? window.location.hostname === url.hostname : urlOrPath.startsWith("/");
const isTrusted = url
? window.location.hostname === url.hostname && url.protocol === "https:"
: urlOrPath.startsWith("/");
if (!isTrusted) {
console.warn("Untrusted URL", urlOrPath);
}
Expand Down
Loading