Skip to content

Commit c63ef1c

Browse files
committed
[MNY-310] Dashboard: Improve login redirect path validation (#8422)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR modifies the `isValidEncodedRedirectPath` function to enhance its validation logic for decoded paths, ensuring they start with a single slash and belong to the `thirdweb.com` domain. ### Detailed summary - Removed comments about decoding URI components and path validation. - Added a check to ensure `decodedPath` starts with a single slash. - Introduced a `URL` object to validate that the hostname is `thirdweb.com`. - Simplified the return logic for invalid paths. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced login redirect validation to ensure redirects are properly verified and authenticated for the correct domain. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c7ff3b1 commit c63ef1c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

apps/dashboard/src/app/login/isValidEncodedRedirectPath.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
export function isValidEncodedRedirectPath(encodedPath: string): boolean {
22
try {
3-
// Decode the URI component
43
const decodedPath = decodeURIComponent(encodedPath);
5-
// ensure the path always starts with a _single_ slash
6-
// double slash could be interpreted as `//example.com` which is not allowed
7-
return decodedPath.startsWith("/") && !decodedPath.startsWith("//");
4+
if (!decodedPath.startsWith("/")) {
5+
return false;
6+
}
7+
const url = new URL(decodedPath, "https://thirdweb.com");
8+
return url.hostname === "thirdweb.com";
89
} catch {
910
// If decoding fails, return false
1011
return false;

0 commit comments

Comments
 (0)