Skip to content

Commit f154134

Browse files
authored
CSP: Added missing directives and keywords (#2664)
This adds missing CSP and UISecurity directives and keywords.
1 parent a7ccc16 commit f154134

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

components/prism-csp.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
*/
1111

1212
Prism.languages.csp = {
13-
'directive': {
14-
pattern: /(^|[^-\da-z])(?:base-uri|block-all-mixed-content|(?:child|connect|default|font|frame|img|manifest|media|object|script|style|worker)-src|disown-opener|form-action|frame-ancestors|plugin-types|referrer|reflected-xss|report-to|report-uri|require-sri-for|sandbox|upgrade-insecure-requests)(?=[^-\da-z]|$)/i,
13+
'directive': {
14+
pattern: /(^|[^-\da-z])(?:base-uri|block-all-mixed-content|(?:child|connect|default|font|frame|img|manifest|media|object|prefetch|script|style|worker)-src|disown-opener|form-action|frame-(?:ancestors|options)|input-protection(?:-(?:clip|selectors))?|navigate-to|plugin-types|policy-uri|referrer|reflected-xss|report-(?:to|uri)|require-sri-for|sandbox|(?:script|style)-src-(?:attr|elem)|upgrade-insecure-requests)(?=[^-\da-z]|$)/i,
1515
lookbehind: true,
1616
alias: 'keyword'
1717
},
1818
'safe': {
19-
pattern: /'(?:self|none|strict-dynamic|(?:nonce-|sha(?:256|384|512)-)[a-zA-Z\d+=/]+)'/,
19+
// CSP2 hashes and nonces are base64 values. CSP3 accepts both base64 and base64url values.
20+
// See https://tools.ietf.org/html/rfc4648#section-4
21+
// See https://tools.ietf.org/html/rfc4648#section-5
22+
pattern: /'(?:deny|none|report-sample|self|strict-dynamic|top-only|(?:nonce|sha(?:256|384|512))-[-+/\d=_a-z]+)'/i,
2023
alias: 'selector'
2124
},
2225
'unsafe': {
23-
pattern: /(?:'unsafe-inline'|'unsafe-eval'|'unsafe-hashed-attributes'|\*)/,
26+
pattern: /(?:'unsafe-(?:allow-redirects|dynamic|eval|hash-attributes|hashed-attributes|hashes|inline)'|\*)/i,
2427
alias: 'function'
2528
}
2629
};

components/prism-csp.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/csp/directive_with_source_expression_feature.test

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
script-src example.com;
1+
input-protection tolerance=50; input-protection-clip before=60; input-protection-selectors div; policy-uri https://example.com; script-src example.com; script-src-attr 'none'; style-src-elem 'none';
22

33
----------------------------------------------------
44

55
[
6+
["directive", "input-protection"],
7+
" tolerance=50; ",
8+
["directive", "input-protection-clip"],
9+
" before=60; ",
10+
["directive", "input-protection-selectors"],
11+
" div; ",
12+
["directive", "policy-uri"],
13+
" https://example.com; ",
614
["directive", "script-src"],
7-
" example.com;"
15+
" example.com; ",
16+
["directive", "script-src-attr"],
17+
["safe", "'none'"],
18+
"; ",
19+
["directive", "style-src-elem"],
20+
["safe", "'none'"],
21+
";"
822
]
923

1024
----------------------------------------------------

tests/languages/csp/safe_feature.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
default-src 'none'; style-src 'self' 'strict-dynamic' 'nonce-yeah' 'sha256-EpOpN/ahUF6jhWShDUdy+NvvtaGcu5F7qM6+x2mfkh4=';
1+
default-src 'none' 'report-sample'; style-src 'self' 'strict-dynamic' 'nonce-yeah' 'sha256-EpOpN/ahUF6jhWShDUdy+NvvtaGcu5F7qM6+x2mfkh4=';
22

33
----------------------------------------------------
44

55
[
66
["directive", "default-src"],
77
["safe", "'none'"],
8+
["safe", "'report-sample'"],
89
"; ",
910
["directive", "style-src"],
1011
["safe", "'self'"],

tests/languages/csp/unsafe_feature.test

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
script-src 'unsafe-inline' 'unsafe-eval' 'unsafe-hashed-attributes';
1+
navigate-to 'unsafe-allow-redirects'; script-src 'unsafe-dynamic' 'unsafe-eval' 'unsafe-hash-attributes' 'unsafe-hashed-attributes' 'unsafe-hashes' 'unsafe-inline';
22

33
----------------------------------------------------
44

55
[
6+
["directive", "navigate-to"],
7+
["unsafe", "'unsafe-allow-redirects'"],
8+
"; ",
69
["directive", "script-src"],
7-
["unsafe", "'unsafe-inline'"],
10+
["unsafe", "'unsafe-dynamic'"],
811
["unsafe", "'unsafe-eval'"],
12+
["unsafe", "'unsafe-hash-attributes'"],
913
["unsafe", "'unsafe-hashed-attributes'"],
14+
["unsafe", "'unsafe-hashes'"],
15+
["unsafe", "'unsafe-inline'"],
1016
";"
1117
]
1218

0 commit comments

Comments
 (0)