-
Notifications
You must be signed in to change notification settings - Fork 0
Admin page post-login redirect #33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,25 @@ import { | |
| nextjsMiddlewareRedirect, | ||
| } from "@convex-dev/auth/nextjs/server"; | ||
|
|
||
| const HOME_PATH = "/"; | ||
| const SIGN_IN_PATH = "/signin"; | ||
|
|
||
| const getSafeRedirectPath = (path: string | null) => { | ||
| if (!path?.startsWith("/")) { | ||
| return HOME_PATH; | ||
| } | ||
|
|
||
| if (path.startsWith("//")) { | ||
| return HOME_PATH; | ||
| } | ||
|
|
||
| if (path === SIGN_IN_PATH || path.startsWith(`${SIGN_IN_PATH}?`)) { | ||
| return HOME_PATH; | ||
| } | ||
|
|
||
| return path; | ||
| }; | ||
|
Comment on lines
+10
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated
Prompt To Fix With AIThis is a comment left during a code review.
Path: proxy.ts
Line: 10-24
Comment:
**Duplicated `getSafeRedirectPath` utility**
`getSafeRedirectPath` is defined identically in both `proxy.ts` and `app/signin/page.tsx`. If the validation logic ever needs to change (e.g., to patch a security bypass), it must be updated in both places, which is easy to miss. Consider extracting it to a shared utility such as `lib/redirect.ts` and importing it from both call sites.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| const isSignInPage = createRouteMatcher(["/signin"]); | ||
| const isProtectedRoute = createRouteMatcher([ | ||
| "/server", | ||
|
|
@@ -13,7 +32,10 @@ const isProtectedRoute = createRouteMatcher([ | |
|
|
||
| export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => { | ||
| if (isSignInPage(request) && (await convexAuth.isAuthenticated())) { | ||
| return nextjsMiddlewareRedirect(request, "/"); | ||
| const redirectPath = getSafeRedirectPath( | ||
| request.nextUrl.searchParams.get("redirect") | ||
| ); | ||
| return nextjsMiddlewareRedirect(request, redirectPath); | ||
| } | ||
| if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) { | ||
| return nextjsMiddlewareRedirect(request, "/signin"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential open redirect via
/\bypassThe guard blocks
//(protocol-relative URLs) but does not catch/\followed by a domain. Some browsers and HTTP clients normalize a backslash to a forward slash, so a crafted query param like?redirect=%2F%5Cevil.comcould decode to/\evil.com, pass all three checks, and potentially redirect to an external host depending on the runtime's URL normalization.Adding an explicit check for
path.startsWith("/\\")(or, more robustly, parsing the path withnew URL(path, window.location.origin)and verifying theoriginmatches) would close this gap:The same applies to the identical function in
proxy.ts.Prompt To Fix With AI