main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | /**
|
---|
| 2 | * Original by Scott Helme.
|
---|
| 3 | *
|
---|
| 4 | * Reference: https://scotthelme.co.uk/csp-cheat-sheet/
|
---|
| 5 | *
|
---|
| 6 | * Supports the following:
|
---|
| 7 | * - https://www.w3.org/TR/CSP1/
|
---|
| 8 | * - https://www.w3.org/TR/CSP2/
|
---|
| 9 | * - https://www.w3.org/TR/CSP3/
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | (function (Prism) {
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | * @param {string} source
|
---|
| 16 | * @returns {RegExp}
|
---|
| 17 | */
|
---|
| 18 | function value(source) {
|
---|
| 19 | return RegExp(/([ \t])/.source + '(?:' + source + ')' + /(?=[\s;]|$)/.source, 'i');
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | Prism.languages.csp = {
|
---|
| 23 | 'directive': {
|
---|
| 24 | pattern: /(^|[\s;])(?: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)(?=[\s;]|$)/i,
|
---|
| 25 | lookbehind: true,
|
---|
| 26 | alias: 'property'
|
---|
| 27 | },
|
---|
| 28 | 'scheme': {
|
---|
| 29 | pattern: value(/[a-z][a-z0-9.+-]*:/.source),
|
---|
| 30 | lookbehind: true
|
---|
| 31 | },
|
---|
| 32 | 'none': {
|
---|
| 33 | pattern: value(/'none'/.source),
|
---|
| 34 | lookbehind: true,
|
---|
| 35 | alias: 'keyword'
|
---|
| 36 | },
|
---|
| 37 | 'nonce': {
|
---|
| 38 | pattern: value(/'nonce-[-+/\w=]+'/.source),
|
---|
| 39 | lookbehind: true,
|
---|
| 40 | alias: 'number'
|
---|
| 41 | },
|
---|
| 42 | 'hash': {
|
---|
| 43 | pattern: value(/'sha(?:256|384|512)-[-+/\w=]+'/.source),
|
---|
| 44 | lookbehind: true,
|
---|
| 45 | alias: 'number'
|
---|
| 46 | },
|
---|
| 47 | 'host': {
|
---|
| 48 | pattern: value(
|
---|
| 49 | /[a-z][a-z0-9.+-]*:\/\/[^\s;,']*/.source +
|
---|
| 50 | '|' +
|
---|
| 51 | /\*[^\s;,']*/.source +
|
---|
| 52 | '|' +
|
---|
| 53 | /[a-z0-9-]+(?:\.[a-z0-9-]+)+(?::[\d*]+)?(?:\/[^\s;,']*)?/.source
|
---|
| 54 | ),
|
---|
| 55 | lookbehind: true,
|
---|
| 56 | alias: 'url',
|
---|
| 57 | inside: {
|
---|
| 58 | 'important': /\*/
|
---|
| 59 | }
|
---|
| 60 | },
|
---|
| 61 | 'keyword': [
|
---|
| 62 | {
|
---|
| 63 | pattern: value(/'unsafe-[a-z-]+'/.source),
|
---|
| 64 | lookbehind: true,
|
---|
| 65 | alias: 'unsafe'
|
---|
| 66 | },
|
---|
| 67 | {
|
---|
| 68 | pattern: value(/'[a-z-]+'/.source),
|
---|
| 69 | lookbehind: true,
|
---|
| 70 | alias: 'safe'
|
---|
| 71 | },
|
---|
| 72 | ],
|
---|
| 73 | 'punctuation': /;/
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | }(Prism));
|
---|
Note:
See
TracBrowser
for help on using the repository browser.