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 18145e7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src_assets/common/assets/web/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,28 @@ <h1 class="mb-2">
methods: {
onLogin() {
const searchParams = new URLSearchParams(window.location.search);
let newPath = '/';
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);
} else {
newPath = '/';
}
}
}

document.location.href = newPath;
}
}
Expand Down

0 comments on commit 18145e7

Please sign in to comment.