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

Add CSP headers to the karma run #1893

Merged
merged 11 commits into from
Apr 15, 2024
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
17 changes: 16 additions & 1 deletion angular-workspace/projects/example-client-app/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ module.exports = function (config) {
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false,
restartOnFileChange: true
restartOnFileChange: true,
customHeaders: [
// Test under the OWASP Basic non-strict CSP Policy
// See: https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#basic-non-strict-csp-policy
// Need script-src 'unsafe-inline' to support karma behavior
// See https://github.com/karma-runner/karma/issues/3260
// Need script-src 'unsafe-eval' to support running in Angular tests
// Need style-src 'unsafe-inline' to support FAST
// See: https://github.com/microsoft/fast/issues/4510
// Need worker-src blob: to support current worker loading pattern
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "default-src 'self'; frame-ancestors 'self'; form-action 'self'; object-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; worker-src 'self' blob: ;"
}
]
});
};
17 changes: 16 additions & 1 deletion angular-workspace/projects/ni/nimble-angular/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ module.exports = config => {
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false,
restartOnFileChange: true
restartOnFileChange: true,
customHeaders: [
// Test under the OWASP Basic non-strict CSP Policy
// See: https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#basic-non-strict-csp-policy
// Need script-src 'unsafe-inline' to support karma behavior
// See https://github.com/karma-runner/karma/issues/3260
// Need script-src 'unsafe-eval' to support running in Angular tests
// Need style-src 'unsafe-inline' to support FAST
// See: https://github.com/microsoft/fast/issues/4510
// Need worker-src blob: to support current worker loading pattern
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "default-src 'self'; frame-ancestors 'self'; form-action 'self'; object-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; worker-src 'self' blob: ;"
}
]
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Add CSP headers to the karma run",
"packageName": "@ni/jasmine-parameterized",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Add CSP headers to the karma run",
"packageName": "@ni/nimble-angular",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Add CSP headers to the karma run",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "none"
}
13 changes: 12 additions & 1 deletion packages/jasmine-parameterized/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ module.exports = config => {
captureConsole: true
},
// to disable the WARN 404 for image requests
logLevel: config.LOG_ERROR
logLevel: config.LOG_ERROR,
customHeaders: [
// Test under the OWASP Basic non-strict CSP Policy
// See: https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#basic-non-strict-csp-policy
// Need script-src 'unsafe-inline' to support karma behavior
// See https://github.com/karma-runner/karma/issues/3260
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "default-src 'self'; frame-ancestors 'self'; form-action 'self'; object-src 'none'; script-src 'self' 'unsafe-inline';"
}
]
};

config.set(options);
Expand Down
7 changes: 7 additions & 0 deletions packages/nimble-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ If a client is localized, it should:
```
- For each label token on the label provider API, localize the English string, and set the corresponding HTML attribute or JS property on the label provider to the localized values. A list of all label tokens for each label provider (and their corresponding attribute/property names and English strings) can be found in the [Tokens/Label Providers section of Storybook](http://nimble.ni.dev/storybook/?path=/docs/tokens-label-providers--docs).

## Content Security Policy

When using Nimble in an environment with a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) enabled, the following are known required settings beyond "common" settings (such as the [OWASP Basic non-Strict CSP Policy](https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#basic-non-strict-csp-policy)) for using Nimble:

- `style-src 'unsafe-inline'` is [needed to support style patterns in the FAST library](https://github.com/microsoft/fast/issues/4510) leveraged by Nimble.
- `worker-src blob:` is needed to support controls that leverage Web Workers (for example the Wafer Map).

## Accessibility

For accessibility information related to nimble components, see [accessibility.md](/packages/nimble-components/docs/accessibility.md).
Expand Down
16 changes: 15 additions & 1 deletion packages/nimble-components/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,21 @@ module.exports = config => {
},
captureConsole: true
},
logLevel: config.LOG_ERROR // to disable the WARN 404 for image requests
logLevel: config.LOG_ERROR, // to disable the WARN 404 for image requests
customHeaders: [
// Test under the OWASP Basic non-strict CSP Policy
// See: https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#basic-non-strict-csp-policy
// Need script-src 'unsafe-inline' to support karma behavior
// See: https://github.com/karma-runner/karma/issues/3260
// Need style-src 'unsafe-inline' to support FAST
// See: https://github.com/microsoft/fast/issues/4510
// Need worker-src blob: to support current worker loading pattern
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "default-src 'self'; frame-ancestors 'self'; form-action 'self'; object-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; worker-src 'self' blob: ;"
}
]
};

config.set(options);
Expand Down
Loading