Skip to content

Commit 18145e7

Browse files
committed
chore: made the path redir safer just in case
This value comes from the backend, but in case someone may try to lure some user somehow, we add a layer of protection
1 parent af17523 commit 18145e7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src_assets/common/assets/web/login.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,28 @@ <h1 class="mb-2">
4141
methods: {
4242
onLogin() {
4343
const searchParams = new URLSearchParams(window.location.search);
44-
let newPath = '/';
44+
let newPath;
4545
if (searchParams.has('redirect')) {
4646
const redirect = searchParams.get('redirect');
47-
if (redirect.startsWith('/')) {
48-
newPath = redirect;
49-
} else {
50-
newPath = newPath + redirect;
47+
const encodePath = (path) => {
48+
return path.split('').map(char => {
49+
if (char === '/') return char; // Keep '/' unencoded
50+
return encodeURIComponent(char);
51+
}).join('');
52+
};
53+
54+
try {
55+
const redirectUrl = new URL(redirect);
56+
newPath = redirectUrl.pathname;
57+
} catch (error) {
58+
if (redirect.startsWith('/')) {
59+
newPath = encodePath(redirect);
60+
} else {
61+
newPath = '/';
62+
}
5163
}
5264
}
65+
5366
document.location.href = newPath;
5467
}
5568
}

0 commit comments

Comments
 (0)