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
10 changes: 7 additions & 3 deletions src/legacy/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import {
import {
getData
} from '../path';
import { DEFAULT_CSP_RULES } from '../csp';
import {
DEFAULT_CSP_RULES,
DEFAULT_CSP_STRICT,
DEFAULT_CSP_WARN_LEGACY_BROWSERS,
} from '../csp';

export default () => Joi.object({
pkg: Joi.object({
Expand All @@ -56,8 +60,8 @@ export default () => Joi.object({

csp: Joi.object({
rules: Joi.array().items(Joi.string()).default(DEFAULT_CSP_RULES),
strict: Joi.boolean().default(false),
warnLegacyBrowsers: Joi.boolean().default(true),
strict: Joi.boolean().default(DEFAULT_CSP_STRICT),
warnLegacyBrowsers: Joi.boolean().default(DEFAULT_CSP_WARN_LEGACY_BROWSERS),
}).default(),

cpu: Joi.object({
Expand Down
16 changes: 15 additions & 1 deletion src/legacy/server/csp/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
* under the License.
*/

import { createCSPRuleString, DEFAULT_CSP_RULES, generateCSPNonce } from './';
import {
createCSPRuleString,
generateCSPNonce,
DEFAULT_CSP_RULES,
DEFAULT_CSP_STRICT,
DEFAULT_CSP_WARN_LEGACY_BROWSERS,
} from './';

// CSP rules aren't strictly additive, so any change can potentially expand or
// restrict the policy in a way we consider a breaking change. For that reason,
Expand All @@ -41,6 +47,14 @@ Array [
`);
});

test('CSP strict mode defaults to disabled', () => {
expect(DEFAULT_CSP_STRICT).toBe(false);
});

test('CSP legacy browser warning defaults to enabled', () => {
expect(DEFAULT_CSP_WARN_LEGACY_BROWSERS).toBe(true);
});

test('generateCSPNonce() creates a 16 character string', async () => {
const nonce = await generateCSPNonce();

Expand Down
4 changes: 4 additions & 0 deletions src/legacy/server/csp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const DEFAULT_CSP_RULES = Object.freeze([
'child-src blob:',
]);

export const DEFAULT_CSP_STRICT = false;

export const DEFAULT_CSP_WARN_LEGACY_BROWSERS = true;

export async function generateCSPNonce() {
return (await randomBytesAsync(12)).toString('base64');
}
Expand Down