-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public assets test suite and configuration for security headers
- Loading branch information
1 parent
77b48d3
commit d0dc70f
Showing
8 changed files
with
109 additions
and
0 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 @@ | ||
imports.autoImport=true |
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 @@ | ||
<template> | ||
<div> | ||
<NuxtPage /> | ||
</div> | ||
</template> |
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,42 @@ | ||
export default defineNuxtConfig({ | ||
modules: [ | ||
'../../../src/module' | ||
], | ||
routeRules: { | ||
'/test/**': { | ||
security: { | ||
headers: { | ||
referrerPolicy: 'no-referrer', | ||
strictTransportSecurity: { | ||
maxAge: 15552000, | ||
includeSubdomains: true, | ||
}, | ||
xContentTypeOptions: 'nosniff', | ||
xDownloadOptions: 'noopen', | ||
xFrameOptions: 'SAMEORIGIN', | ||
xPermittedCrossDomainPolicies: 'none', | ||
xXSSProtection: '0', | ||
} | ||
} | ||
} | ||
}, | ||
security: { | ||
headers: { | ||
referrerPolicy: false, | ||
strictTransportSecurity: false, | ||
xContentTypeOptions: false, | ||
xDownloadOptions: false, | ||
xFrameOptions: false, | ||
xPermittedCrossDomainPolicies: false, | ||
xXSSProtection: false, | ||
contentSecurityPolicy: { | ||
'script-src': [ | ||
"'self'", | ||
'https:', | ||
"'unsafe-inline'", | ||
"'strict-dynamic'" | ||
] | ||
} | ||
} | ||
} | ||
}) |
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 @@ | ||
{ | ||
"private": true, | ||
"name": "basic", | ||
"type": "module" | ||
} |
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,3 @@ | ||
<template> | ||
<div>basic</div> | ||
</template> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,53 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, fetch } from '@nuxt/test-utils' | ||
|
||
describe('[nuxt-security] Public Assets', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/publicAssets', import.meta.url)), | ||
}) | ||
|
||
it('does not set all-resources security headers when disabled in config', async () => { | ||
const { headers } = await fetch('/icon.png') | ||
expect(headers).toBeDefined() | ||
|
||
// Security headers that are always set on all resources | ||
const rp = headers.get('referrer-policy') | ||
const sts = headers.get('strict-transport-security') | ||
const xcto = headers.get('x-content-type-options') | ||
const xdo = headers.get('x-download-options') | ||
const xfo = headers.get('x-frame-options') | ||
const xpcdp = headers.get('x-permitted-cross-domain-policies') | ||
const xxp = headers.get('x-xss-protection') | ||
|
||
expect(rp).toBeNull() | ||
expect(sts).toBeNull() | ||
expect(xcto).toBeNull() | ||
expect(xdo).toBeNull() | ||
expect(xfo).toBeNull() | ||
expect(xpcdp).toBeNull() | ||
expect(xxp).toBeNull() | ||
}) | ||
|
||
it('sets security headers on routes when specified in routeRules', async () => { | ||
const { headers } = await fetch('/test') | ||
expect(headers).toBeDefined() | ||
|
||
// Security headers that are always set on all resources | ||
const rp = headers.get('referrer-policy') | ||
const sts = headers.get('strict-transport-security') | ||
const xcto = headers.get('x-content-type-options') | ||
const xdo = headers.get('x-download-options') | ||
const xfo = headers.get('x-frame-options') | ||
const xpcdp = headers.get('x-permitted-cross-domain-policies') | ||
const xxp = headers.get('x-xss-protection') | ||
|
||
expect(rp).toBe('no-referrer') | ||
expect(sts).toBe('max-age=15552000; includeSubDomains;') | ||
expect(xcto).toBe('nosniff') | ||
expect(xdo).toBe('noopen') | ||
expect(xfo).toBe('SAMEORIGIN') | ||
expect(xpcdp).toBe('none') | ||
expect(xxp).toBe('0') | ||
}) | ||
}) |