File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ describe('middleware function', () => {
165165 ] ) ;
166166 } ) ;
167167
168- it ( 'when running in development mode, CSP script-src allows unsafe-eval' , async ( ) => {
168+ it ( 'when running in development mode, CSP script-src allows unsafe-eval and does not upgrade insecure requests ' , async ( ) => {
169169 // @ts -expect-error assignment to const
170170 process . env . NODE_ENV = 'development' ;
171171
@@ -189,8 +189,6 @@ describe('middleware function', () => {
189189 / ^ s c r i p t - s r c ' s e l f ' ' n o n c e - [ \d A - Z a - z ] + ' ' u n s a f e - e v a l ' $ /
190190 ) ,
191191 expect . stringMatching ( / ^ s t y l e - s r c ' s e l f ' ' n o n c e - [ \d A - Z a - z ] + ' $ / ) ,
192- 'upgrade-insecure-requests' ,
193- '' ,
194192 ] ) ;
195193 } ) ;
196194} ) ;
Original file line number Diff line number Diff line change @@ -57,6 +57,22 @@ export default function RootLayout({
5757 return (
5858 < html lang = 'en' >
5959 < head >
60+ < link
61+ rel = 'preload'
62+ as = 'font'
63+ href = 'https://assets.nhs.uk/fonts/FrutigerLTW01-55Roman.woff2'
64+ type = 'font/woff2'
65+ crossOrigin = 'anonymous'
66+ />
67+
68+ < link
69+ rel = 'preload'
70+ as = 'font'
71+ href = 'https://assets.nhs.uk/fonts/FrutigerLTW01-65Bold.woff2'
72+ type = 'font/woff2'
73+ crossOrigin = 'anonymous'
74+ />
75+
6076 < script
6177 src = { `${ getBasePath ( ) } /lib/nhsuk-frontend-10.0.0.min.js` }
6278 defer
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ const publicPaths = [
5151] ;
5252
5353function getContentSecurityPolicy ( nonce : string ) {
54- const contentSecurityPolicyDirective = {
54+ const contentSecurityPolicyDirective : Record < string , string [ ] > = {
5555 'base-uri' : [ `'self'` ] ,
5656 'default-src' : [ `'none'` ] ,
5757 'frame-ancestors' : [ `'none'` ] ,
@@ -64,16 +64,18 @@ function getContentSecurityPolicy(nonce: string) {
6464 'object-src' : [ `'none'` ] ,
6565 'script-src' : [ `'self'` , `'nonce-${ nonce } '` ] ,
6666 'style-src' : [ `'self'` , `'nonce-${ nonce } '` ] ,
67- 'upgrade-insecure-requests;' : [ ] ,
6867 } ;
6968
7069 if ( process . env . NODE_ENV === 'development' ) {
7170 contentSecurityPolicyDirective [ 'script-src' ] . push ( `'unsafe-eval'` ) ;
71+ } else {
72+ contentSecurityPolicyDirective [ 'upgrade-insecure-requests' ] = [ ] ;
7273 }
7374
7475 return Object . entries ( contentSecurityPolicyDirective )
7576 . map ( ( [ key , value ] ) => `${ key } ${ value . join ( ' ' ) } ` )
76- . join ( '; ' ) ;
77+ . join ( '; ' )
78+ . concat ( ';' ) ;
7779}
7880
7981export async function middleware ( request : NextRequest ) {
You can’t perform that action at this time.
0 commit comments