Skip to content

Commit

Permalink
chore: made the path redir safer just in case
Browse files Browse the repository at this point in the history
This value comes from the backend, but in case someone may try to lure some user somehow, we add a layer of protection
  • Loading branch information
Hazer committed Aug 9, 2024
1 parent af17523 commit 448d83c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src_assets/common/assets/web/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ <h1 class="mb-2">
let newPath = '/';
if (searchParams.has('redirect')) {
const redirect = searchParams.get('redirect');
if (redirect.startsWith('/')) {
newPath = redirect;
} else {
newPath = newPath + redirect;
const encodePath = (path) => {
return path.split('').map(char => {
if (char === '/') return char; // Keep '/' unencoded
return encodeURIComponent(char);
}).join('');
};

try {
const redirectUrl = new URL(redirect);
newPath = redirectUrl.pathname;
} catch (error) {
if (redirect.startsWith('/')) {
newPath = encodePath(redirect);
}
}
}

document.location.href = newPath;

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.
}
}
Expand Down

0 comments on commit 448d83c

Please sign in to comment.