File tree Expand file tree Collapse file tree
packages/core/src/pages/api/fs/auth Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ import {
1111const COOKIE_NAME = '__fs_auth_token'
1212const TOKEN_TTL_SECONDS = 10 * 60
1313
14+ const isSafeReturnToPath = ( value : string ) : boolean => {
15+ return value . startsWith ( '/' ) && ! value . startsWith ( '//' )
16+ }
17+
1418const handler : NextApiHandler = async (
1519 request : NextApiRequest ,
1620 response : NextApiResponse
@@ -55,6 +59,7 @@ const handler: NextApiHandler = async (
5559 typeof request . query . returnTo === 'string'
5660 ? request . query . returnTo
5761 : '/'
62+ const sanitizedReturnTo = isSafeReturnToPath ( returnTo ) ? returnTo : '/'
5863
5964 const securePart = isSecureAuthCookieForPagesApi ( request )
6065 ? '; Secure'
@@ -66,7 +71,7 @@ const handler: NextApiHandler = async (
6671
6772 response . status ( 200 ) . json ( {
6873 success : true ,
69- redirectUrl : returnTo ,
74+ redirectUrl : sanitizedReturnTo ,
7075 } )
7176 } else {
7277 response . status ( 401 ) . json ( {
You can’t perform that action at this time.
0 commit comments