Skip to content

Commit

Permalink
added excludePathPrefixes option and bumped version number to 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
amorey committed Apr 27, 2023
1 parent b383ff4 commit 32645ab
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ Here are the default configuration values:
httpOnly: true,
sameSite: 'strict'
},
excludePathPrefixes: ['/_next/'],
ignoreMethods: ['GET', 'HEAD', 'OPTIONS'],
ignorePathPrefixes: ['/_next/'],
saltByteLength: 8,
secretByteLength: 18,
token: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "edge-csrf",
"description": "CSRF protection for Next.js middleware",
"version": "1.0.2",
"version": "1.0.3",
"author": "Andres Morey",
"license": "MIT",
"repository": "amorey/edge-csrf",
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class TokenOptions {

export class Config {
cookie: CookieOptions = new CookieOptions()
excludePathPrefixes: string[] = ['/_next/']
ignoreMethods: string[] = ['GET', 'HEAD', 'OPTIONS']
ignorePathPrefixes: string[] = ['/_next/']
saltByteLength: number = 8
secretByteLength: number = 18
token: TokenOptions = new TokenOptions()
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function CreateMiddleware(opts?: Partial<ConfigOptions>): CSRFMid
let secret: Uint8Array;
let secretStr: string | undefined;

// check ignorePathPrefixes
for (const pathPrefix of config.ignorePathPrefixes) {
// check excludePathPrefixes
for (const pathPrefix of config.excludePathPrefixes) {
if (request.nextUrl.pathname.startsWith(pathPrefix)) return null;
}

Expand Down
6 changes: 3 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ describe('config option tests', () => {
})
})

describe('ignorePathPrefixes', () => {
it('should respect configured ignorePathPrefixes', async () => {
const csrfProtect = csrf({ignorePathPrefixes: ['/ignore-me/sub-path/']})
describe('excludePathPrefixes', () => {
it('should respect configured excludePathPrefixes', async () => {
const csrfProtect = csrf({excludePathPrefixes: ['/ignore-me/sub-path/']})

const request = new NextRequest('http://example.com/ignore-me/sub-path/file.jpg')
const response = NextResponse.next()
Expand Down

0 comments on commit 32645ab

Please sign in to comment.