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 and UISecurity directives and keywords #2664

Merged
merged 2 commits into from Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/prism-csp.js
Expand Up @@ -10,17 +10,17 @@
*/

Prism.languages.csp = {
'directive': {
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,
'directive': {
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,
lookbehind: true,
alias: 'keyword'
},
'safe': {
pattern: /'(?:self|none|strict-dynamic|(?:nonce-|sha(?:256|384|512)-)[a-zA-Z\d+=/]+)'/,
pattern: /'(?:deny|none|report-sample|self|strict-dynamic|top-only|(?:nonce|sha(?:256|384|512))-[-+/\d=_a-z]+)'/i,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
alias: 'selector'
},
'unsafe': {
pattern: /(?:'unsafe-inline'|'unsafe-eval'|'unsafe-hashed-attributes'|\*)/,
pattern: /(?:'unsafe-(?:allow-redirects|dynamic|eval|hash-attributes|hashed-attributes|hashes|inline)'|\*)/i,
alias: 'function'
}
};
2 changes: 1 addition & 1 deletion components/prism-csp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions tests/languages/csp/directive_with_source_expression_feature.test
@@ -1,10 +1,24 @@
script-src example.com;
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';

----------------------------------------------------

[
["directive", "input-protection"],
" tolerance=50; ",
["directive", "input-protection-clip"],
" before=60; ",
["directive", "input-protection-selectors"],
" div; ",
["directive", "policy-uri"],
" https://example.com; ",
["directive", "script-src"],
" example.com;"
" example.com; ",
["directive", "script-src-attr"],
["safe", "'none'"],
"; ",
["directive", "style-src-elem"],
["safe", "'none'"],
";"
]

----------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion tests/languages/csp/safe_feature.test
@@ -1,10 +1,11 @@
default-src 'none'; style-src 'self' 'strict-dynamic' 'nonce-yeah' 'sha256-EpOpN/ahUF6jhWShDUdy+NvvtaGcu5F7qM6+x2mfkh4=';
default-src 'none' 'report-sample'; style-src 'self' 'strict-dynamic' 'nonce-yeah' 'sha256-EpOpN/ahUF6jhWShDUdy+NvvtaGcu5F7qM6+x2mfkh4=';

----------------------------------------------------

[
["directive", "default-src"],
["safe", "'none'"],
["safe", "'report-sample'"],
"; ",
["directive", "style-src"],
["safe", "'self'"],
Expand Down
10 changes: 8 additions & 2 deletions tests/languages/csp/unsafe_feature.test
@@ -1,12 +1,18 @@
script-src 'unsafe-inline' 'unsafe-eval' 'unsafe-hashed-attributes';
navigate-to 'unsafe-allow-redirects'; script-src 'unsafe-dynamic' 'unsafe-eval' 'unsafe-hash-attributes' 'unsafe-hashed-attributes' 'unsafe-hashes' 'unsafe-inline';

----------------------------------------------------

[
["directive", "navigate-to"],
["unsafe", "'unsafe-allow-redirects'"],
"; ",
["directive", "script-src"],
["unsafe", "'unsafe-inline'"],
["unsafe", "'unsafe-dynamic'"],
["unsafe", "'unsafe-eval'"],
["unsafe", "'unsafe-hash-attributes'"],
["unsafe", "'unsafe-hashed-attributes'"],
["unsafe", "'unsafe-hashes'"],
["unsafe", "'unsafe-inline'"],
";"
]

Expand Down