handle trailing slashes in protected routes
This commit is contained in:
parent
7853fce887
commit
9af1ef4f47
1 changed files with 6 additions and 2 deletions
|
@ -82,9 +82,12 @@ export async function getAccessToken(): Promise<string> {
|
||||||
* @returns Path to required auth token. If not required, return empty string.
|
* @returns Path to required auth token. If not required, return empty string.
|
||||||
*/
|
*/
|
||||||
export function getAuthTokenPath(path: string) {
|
export function getAuthTokenPath(path: string) {
|
||||||
|
// Ensure trailing slashes to compare paths component by component. Same for protectedRoutes.
|
||||||
|
path += '/'
|
||||||
const protectedRoutes = siteConfig.protectedRoutes
|
const protectedRoutes = siteConfig.protectedRoutes
|
||||||
let authTokenPath = ''
|
let authTokenPath = ''
|
||||||
for (const r of protectedRoutes) {
|
for (let r of protectedRoutes) {
|
||||||
|
r = r.replace(/\/$/, '') + '/'
|
||||||
if (path.startsWith(r)) {
|
if (path.startsWith(r)) {
|
||||||
authTokenPath = `${r}/.password`
|
authTokenPath = `${r}/.password`
|
||||||
break
|
break
|
||||||
|
@ -185,7 +188,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
res.status(400).json({ error: 'Path query invalid.' })
|
res.status(400).json({ error: 'Path query invalid.' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const cleanPath = pathPosix.resolve('/', pathPosix.normalize(path))
|
// Besides normalizing and making absolute, trailing slashes are trimmed
|
||||||
|
const cleanPath = pathPosix.resolve('/', pathPosix.normalize(path)).replace(/\/$/, '')
|
||||||
|
|
||||||
// Validate sort param
|
// Validate sort param
|
||||||
if (typeof sort !== 'string') {
|
if (typeof sort !== 'string') {
|
||||||
|
|
Loading…
Reference in a new issue