Skip to content
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

Handle relative paths when sanitizing URLs #41995

Merged
merged 5 commits into from
Sep 4, 2024
Merged
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
10 changes: 8 additions & 2 deletions airflow/www/static/js/dag/details/taskInstance/ExtraLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ const ExtraLinks = ({
if (!url) {
return true;
}
const urlRegex = /^(https?:)/i;
return urlRegex.test(url);
const path = new URL(url, "http://localhost");
// Allow Absolute/Relative URL and prevent javascript:() from executing when passed as path.
// Example - `javascript:alert("Hi");`. Protocol for absolute and relative urls will either be `http:`/`https:`.
// Where as for javascript it will be `javascript:`.
if (path.protocol === "http:" || path.protocol === "https:") {
return true; // Absolute/Relative URLs are allowed
}
return false;
};

return (
Expand Down