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