Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-hounds-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Updates the default middleware config matcher to be more restrictive in how it detects static files. Paths with `.` in them are now allowed, as long as the `.` is not in the final path segment.
13 changes: 12 additions & 1 deletion packages/nextjs/src/server/authMiddleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,20 @@ const validRoutes = [
'/protected',
'/protected/',
'/protected/hello',
'/protected/hello.example/hello',
'/my-protected-page',
'/my/$special/$pages',
];

const invalidRoutes = ['/_next', '/favicon.ico', '/_next/test.json', '/files/api.pdf', '/test/api/test.pdf'];
const invalidRoutes = [
'/_next',
'/favicon.ico',
'/_next/test.json',
'/files/api.pdf',
'/test/api/test.pdf',
'/imgs/img.png',
'/imgs/img-dash.jpg',
];

describe('default config matcher', () => {
it('compiles to regex using path-to-regex', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const INFINITE_REDIRECTION_LOOP_COOKIE = '__clerk_redirection_loop';
* The default ideal matcher that excludes the _next directory (internals) and all static files,
* but it will match the root route (/) and any routes that start with /api or /trpc.
*/
export const DEFAULT_CONFIG_MATCHER = ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'];
export const DEFAULT_CONFIG_MATCHER = ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'];

/**
* Any routes matching this path will be ignored by the middleware.
* This is the inverted version of DEFAULT_CONFIG_MATCHER.
*/
export const DEFAULT_IGNORED_ROUTES = ['/((?!api|trpc))(_next|.+\\..+)(.*)'];
export const DEFAULT_IGNORED_ROUTES = [`/((?!api|trpc))(_next.*|.+\\.[\\w]+$)`];
/**
* Any routes matching this path will be treated as API endpoints by the middleware.
*/
Expand Down