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
Binary file not shown.
266 changes: 266 additions & 0 deletions frontend/public/lib/assets/fonts/FrutigerLTW01-55Roman.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
265 changes: 265 additions & 0 deletions frontend/public/lib/assets/fonts/FrutigerLTW01-65Bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions frontend/src/__tests__/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('middleware function', () => {
]);
});

it('when running in development mode, CSP script-src allows unsafe-eval', async () => {
it('when running in development mode, CSP script-src allows unsafe-eval and does not upgrade insecure requests', async () => {
// @ts-expect-error assignment to const
process.env.NODE_ENV = 'development';

Expand All @@ -189,7 +189,6 @@ describe('middleware function', () => {
/^script-src 'self' 'nonce-[\dA-Za-z]+' 'unsafe-eval'$/
),
expect.stringMatching(/^style-src 'self' 'nonce-[\dA-Za-z]+'$/),
'upgrade-insecure-requests',
'',
]);
});
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const publicPaths = [
];

function getContentSecurityPolicy(nonce: string) {
const contentSecurityPolicyDirective = {
const contentSecurityPolicyDirective: Record<string, string[]> = {
'base-uri': [`'self'`],
'default-src': [`'none'`],
'frame-ancestors': [`'none'`],
Expand All @@ -64,16 +64,18 @@ function getContentSecurityPolicy(nonce: string) {
'object-src': [`'none'`],
'script-src': [`'self'`, `'nonce-${nonce}'`],
'style-src': [`'self'`, `'nonce-${nonce}'`],
'upgrade-insecure-requests;': [],
};

if (process.env.NODE_ENV === 'development') {
contentSecurityPolicyDirective['script-src'].push(`'unsafe-eval'`);
} else {
contentSecurityPolicyDirective['upgrade-insecure-requests'] = [];
}

return Object.entries(contentSecurityPolicyDirective)
.map(([key, value]) => `${key} ${value.join(' ')}`)
.join('; ');
.join('; ')
.concat(';');
}

export async function middleware(request: NextRequest) {
Expand Down
30 changes: 30 additions & 0 deletions frontend/src/styles/app.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
@use 'nhsuk-frontend/dist/nhsuk';

// CCM-9916 - Override @font-face rules from nhsuk-frontend to reference self-hosted fonts
@font-face {
font-display: swap;
font-family: Frutiger W01;
font-style: normal;
font-weight: 400;
src: url(/templates/lib/assets/fonts/FrutigerLTW01-55Roman.eot);
src:
url(/templates/lib/assets/fonts/FrutigerLTW01-55Roman.eot) format('eot'),
url(/templates/lib/assets/fonts/FrutigerLTW01-55Roman.woff2) format('woff2'),
url(/templates/lib/assets/fonts/FrutigerLTW01-55Roman.woff) format('woff'),
url(/templates/lib/assets/fonts/FrutigerLTW01-55Roman.ttf)
format('truetype'),
url(/templates/lib/assets/fonts/FrutigerLTW01-55Roman.svg) format('svg');
}

@font-face {
font-display: swap;
font-family: Frutiger W01;
font-style: normal;
font-weight: 600;
src: url(/templates/lib/assets/fonts/FrutigerLTW01-65Bold.eot);
src:
url(/templates/lib/assets/fonts/FrutigerLTW01-65Bold.eot) format('eot'),
url(/templates/lib/assets/fonts/FrutigerLTW01-65Bold.woff2) format('woff2'),
url(/templates/lib/assets/fonts/FrutigerLTW01-65Bold.woff) format('woff'),
url(/templates/lib/assets/fonts/FrutigerLTW01-65Bold.ttf) format('truetype'),
url(/templates/lib/assets/fonts/FrutigerLTW01-65Bold.svg) format('svg');
}

body {
// This is here because amplify applies a min height which overwrites nhsuk causing a white space
min-height: auto !important;
Expand Down
Loading