-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
265 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@enalmada/next-secure': minor | ||
--- | ||
|
||
move next-safe into library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
inputs: | ||
target_url: | ||
description: 'Deployment target URL' | ||
required: true | ||
|
||
jobs: | ||
test-unit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
- run: bun install | ||
- run: bun run test:unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
await Bun.build({ | ||
entrypoints: ['./src/index.ts'], | ||
outdir: './dist', | ||
target: 'node', | ||
external: ['*'], | ||
root: './src', | ||
}); | ||
entrypoints: ['./src/index.ts'], | ||
outdir: './dist', | ||
target: 'node', | ||
external: ['next-safe'], | ||
root: './src', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { generateCspTemplates, type ContentSecurityPolicyTemplate, type CspRule } from '../src'; | ||
|
||
function getCspConfig(isDev: boolean): ContentSecurityPolicyTemplate { | ||
return { | ||
isDev: isDev, | ||
contentSecurityPolicy: { | ||
mergeDefaultDirectives: true, | ||
'prefetch-src': false, | ||
}, | ||
referrerPolicy: 'strict-origin-when-cross-origin', | ||
permissionsPolicy: { | ||
'ambient-light-sensor': false, | ||
battery: false, | ||
'document-domain': false, | ||
'execution-while-not-rendered': false, | ||
'execution-while-out-of-viewport': false, | ||
'navigation-override': false, | ||
'speaker-selection': false, | ||
}, | ||
permissionsPolicyDirectiveSupport: ['proposed', 'standard'], | ||
}; | ||
} | ||
|
||
// https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid#cross_origin_opener_policy | ||
export const cspRules: CspRule[] = [ | ||
{ | ||
description: 'nextjs', | ||
'script-src': 'http://testscript', | ||
source: '/:path*', | ||
}, | ||
]; | ||
|
||
describe('CSP Template Generation', () => { | ||
it('basic dev test', () => { | ||
const templates = generateCspTemplates(getCspConfig(true), cspRules); | ||
|
||
const expectedTemplates = [ | ||
{ | ||
source: '/:path*', | ||
headers: [ | ||
{ | ||
key: 'Content-Security-Policy', | ||
value: | ||
"base-uri 'none';child-src 'none';connect-src 'self' webpack://*;default-src 'self';font-src 'self';form-action 'self';frame-ancestors 'none';frame-src 'none';img-src 'self';manifest-src 'self';media-src 'self';object-src 'none';script-src 'self' http://testscript 'unsafe-eval';style-src 'self' 'unsafe-inline';worker-src 'self';block-all-mixed-content ;upgrade-insecure-requests ;", | ||
}, | ||
{ | ||
key: 'Permissions-Policy', | ||
value: | ||
'clipboard-read=(),clipboard-write=(),gamepad=(),accelerometer=(),autoplay=(),camera=(),cross-origin-isolated=(),display-capture=(),encrypted-media=(),fullscreen=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),midi=(),payment=(),picture-in-picture=(),publickey-credentials-get=(),screen-wake-lock=(),sync-xhr=(),usb=(),web-share=(),xr-spatial-tracking=()', | ||
}, | ||
{ | ||
key: 'Referrer-Policy', | ||
value: 'strict-origin-when-cross-origin', | ||
}, | ||
{ | ||
key: 'X-Content-Type-Options', | ||
value: 'nosniff', | ||
}, | ||
{ | ||
key: 'X-Frame-Options', | ||
value: 'DENY', | ||
}, | ||
{ | ||
key: 'X-XSS-Protection', | ||
value: '1; mode=block', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
expect(templates).toEqual(expectedTemplates); | ||
}); | ||
|
||
it('basic prod test', () => { | ||
const templates = generateCspTemplates(getCspConfig(false), cspRules); | ||
|
||
const expectedTemplates = [ | ||
{ | ||
source: '/:path*', | ||
headers: [ | ||
{ | ||
key: 'Content-Security-Policy', | ||
value: | ||
"base-uri 'none';child-src 'none';connect-src 'self';default-src 'self';font-src 'self';form-action 'self';frame-ancestors 'none';frame-src 'none';img-src 'self';manifest-src 'self';media-src 'self';object-src 'none';script-src 'self' http://testscript;style-src 'self';worker-src 'self';block-all-mixed-content ;upgrade-insecure-requests ;", | ||
}, | ||
{ | ||
key: 'Permissions-Policy', | ||
value: | ||
'clipboard-read=(),clipboard-write=(),gamepad=(),accelerometer=(),autoplay=(),camera=(),cross-origin-isolated=(),display-capture=(),encrypted-media=(),fullscreen=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),midi=(),payment=(),picture-in-picture=(),publickey-credentials-get=(),screen-wake-lock=(),sync-xhr=(),usb=(),web-share=(),xr-spatial-tracking=()', | ||
}, | ||
{ | ||
key: 'Referrer-Policy', | ||
value: 'strict-origin-when-cross-origin', | ||
}, | ||
{ | ||
key: 'X-Content-Type-Options', | ||
value: 'nosniff', | ||
}, | ||
{ | ||
key: 'X-Frame-Options', | ||
value: 'DENY', | ||
}, | ||
{ | ||
key: 'X-XSS-Protection', | ||
value: '1; mode=block', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
expect(templates).toEqual(expectedTemplates); | ||
}); | ||
}); |
Oops, something went wrong.