Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tech/ex UI 2249 content security #256

Merged
merged 15 commits into from
Jan 6, 2025
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-node-lib",
"version": "2.29.7",
"version": "2.29.8",
"description": "Common nodejs library components for XUI",
"main": "dist/index",
"types": "dist/index.d.ts",
Expand Down
13 changes: 13 additions & 0 deletions src/common/util/contentSecurityPolicy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getContentSecurityPolicy } from './'
import { SECURITY_POLICY } from './contentSecurityPolicy'

describe('getContentSecurityPolicy(helmet)', () => {
it('should correctly call the content security policy', () => {
const helmet: any = {
contentSecurityPolicy: (policy: any) => {
return policy
},
}
expect(getContentSecurityPolicy(helmet)).toBe(SECURITY_POLICY)
})
})
53 changes: 53 additions & 0 deletions src/common/util/contentSecurityPolicy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export const SECURITY_POLICY = {
directives: {
connectSrc: [
"'self' blob: data:",
'*.gov.uk',
'dc.services.visualstudio.com',
'*.launchdarkly.com',
'https://*.google-analytics.com',
'https://*.googletagmanager.com',
'https://*.analytics.google.com',
'*.hmcts.net',
'wss://*.webpubsub.azure.com',
'https://*.in.applicationinsights.azure.com',
'https://*.monitor.azure.com',
],
defaultSrc: ["'self'"],
fontSrc: ["'self'", 'https://fonts.gstatic.com', 'data:'],
formAction: ["'none'"],
frameAncestors: ["'self'"],
frameSrc: ["'self'"],
imgSrc: [
"'self'",
'data:',
'https://*.google-analytics.com',
'https://*.googletagmanager.com',
'https://raw.githubusercontent.com/hmcts/',
'https://stats.g.doubleclick.net/',
'https://ssl.gstatic.com/',
'https://www.gstatic.com/',
'https://fonts.gstatic.com',
],
mediaSrc: ["'self'"],
scriptSrc: [
"'self'",
"'unsafe-inline'",
"'unsafe-eval'",
'https://*.google-analytics.com',
'https://*.googletagmanager.com',
'az416426.vo.msecnd.net',
],
styleSrc: [
"'self'",
"'unsafe-inline'",
'https://fonts.googleapis.com',
'https://fonts.gstatic.com',
'https://www.googletagmanager.com',
],
},
}

export const getContentSecurityPolicy = (helmet: any) => {
andywilkinshmcts marked this conversation as resolved.
Show resolved Hide resolved
return helmet.contentSecurityPolicy(SECURITY_POLICY)
}
1 change: 1 addition & 0 deletions src/common/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { hasKey } from './hasKey'
export { getLogger, XuiLogger } from './debug.logger'
export { getContentSecurityPolicy } from './contentSecurityPolicy'
export { sortArray } from './sortArray'
export { isStringPatternMatch } from './stringPatternMatch'
export { arrayPatternMatch } from './arrayPatternMatch'
Expand Down
Loading