csprefabricate 2.0.22 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,118 +1,21 @@
1
1
  # Changelog
2
2
 
3
- ## [2.0.22](https://github.com/JamesToohey/csprefabricate/compare/v2.0.21...v2.0.22) (2026-01-30)
4
-
5
-
6
- ### Bug Fixes
7
-
8
- * try again ([7fb1d2a](https://github.com/JamesToohey/csprefabricate/commit/7fb1d2abf2fb7f9cf7994c19e503c60fa0e577f4))
9
-
10
- ## [2.0.21](https://github.com/JamesToohey/csprefabricate/compare/v2.0.20...v2.0.21) (2026-01-30)
11
-
12
-
13
- ### Bug Fixes
14
-
15
- * try again ([cdcd28d](https://github.com/JamesToohey/csprefabricate/commit/cdcd28d9fdd32cf80e2ffbb21bc2f9da44a360d4))
16
-
17
- ## [2.0.20](https://github.com/JamesToohey/csprefabricate/compare/v2.0.19...v2.0.20) (2026-01-30)
18
-
19
-
20
- ### Bug Fixes
21
-
22
- * try again ([7f58f49](https://github.com/JamesToohey/csprefabricate/commit/7f58f49c5bc6af0687ad3c941f5886ab3b86db4a))
23
-
24
- ## [2.0.19](https://github.com/JamesToohey/csprefabricate/compare/v2.0.18...v2.0.19) (2026-01-30)
25
-
26
-
27
- ### Bug Fixes
28
-
29
- * try again ([d2172c3](https://github.com/JamesToohey/csprefabricate/commit/d2172c39e3f575bbf4b439fc63a862e1097d1735))
30
-
31
- ## [2.0.18](https://github.com/JamesToohey/csprefabricate/compare/v2.0.17...v2.0.18) (2026-01-30)
32
-
33
-
34
- ### Bug Fixes
35
-
36
- * try again ([6c58a59](https://github.com/JamesToohey/csprefabricate/commit/6c58a592cd1421ad95edf714bb5aba0d3305dc09))
37
-
38
- ## [2.0.17](https://github.com/JamesToohey/csprefabricate/compare/v2.0.16...v2.0.17) (2026-01-30)
39
-
40
-
41
- ### Bug Fixes
42
-
43
- * try again ([c1c0cec](https://github.com/JamesToohey/csprefabricate/commit/c1c0cecbbed2d20df29271c5df5b91305e28e04d))
44
-
45
- ## [2.0.16](https://github.com/JamesToohey/csprefabricate/compare/v2.0.15...v2.0.16) (2026-01-30)
46
-
47
-
48
- ### Bug Fixes
49
-
50
- * try again ([e7358d0](https://github.com/JamesToohey/csprefabricate/commit/e7358d0039fc55ffc500f2a0cc587de9e53acd93))
51
-
52
- ## [2.0.15](https://github.com/JamesToohey/csprefabricate/compare/v2.0.14...v2.0.15) (2026-01-30)
53
-
54
-
55
- ### Bug Fixes
56
-
57
- * try again ([7a3b173](https://github.com/JamesToohey/csprefabricate/commit/7a3b17372d0cff5d00654897593237fac833cc49))
58
-
59
- ## [2.0.14](https://github.com/JamesToohey/csprefabricate/compare/v2.0.13...v2.0.14) (2026-01-30)
60
-
61
-
62
- ### Bug Fixes
63
-
64
- * try again ([06028e6](https://github.com/JamesToohey/csprefabricate/commit/06028e6b81fadadfe34833ad09816daed024c4fd))
65
-
66
- ## [2.0.13](https://github.com/JamesToohey/csprefabricate/compare/v2.0.12...v2.0.13) (2026-01-30)
67
-
68
-
69
- ### Bug Fixes
70
-
71
- * try again ([618e057](https://github.com/JamesToohey/csprefabricate/commit/618e0572ebf57e124a9d206bab9e84c24f62f24f))
72
-
73
- ## [2.0.12](https://github.com/JamesToohey/csprefabricate/compare/v2.0.11...v2.0.12) (2026-01-30)
74
-
75
-
76
- ### Bug Fixes
77
-
78
- * try again ([fc14047](https://github.com/JamesToohey/csprefabricate/commit/fc140477fd270d5d525e14989cf5354d9660346c))
79
-
80
- ## [2.0.11](https://github.com/JamesToohey/csprefabricate/compare/v2.0.10...v2.0.11) (2026-01-30)
3
+ ## [2.1.1](https://github.com/JamesToohey/csprefabricate/compare/v2.1.0...v2.1.1) (2026-02-21)
81
4
 
82
5
 
83
6
  ### Bug Fixes
84
7
 
85
- * try again ([1fbc507](https://github.com/JamesToohey/csprefabricate/commit/1fbc50742191362517c772b911f639af61d9d6a1))
8
+ * Update npm-publish.yaml to fix OIDC error ([#72](https://github.com/JamesToohey/csprefabricate/issues/72)) ([7f77e3b](https://github.com/JamesToohey/csprefabricate/commit/7f77e3b4d7b8447b79d927d521f8d1042ec83655))
86
9
 
87
- ## [2.0.10](https://github.com/JamesToohey/csprefabricate/compare/v2.0.9...v2.0.10) (2026-01-30)
10
+ ## [2.1.0](https://github.com/JamesToohey/csprefabricate/compare/v2.0.22...v2.1.0) (2026-02-21)
88
11
 
89
12
 
90
- ### Bug Fixes
91
-
92
- * try again ([5e728ae](https://github.com/JamesToohey/csprefabricate/commit/5e728aeaeb4c13f2572e70f7b61dca6fde32f243))
93
-
94
- ## [2.0.9](https://github.com/JamesToohey/csprefabricate/compare/v2.0.8...v2.0.9) (2026-01-30)
95
-
96
-
97
- ### Bug Fixes
98
-
99
- * try again ([bf0266f](https://github.com/JamesToohey/csprefabricate/commit/bf0266fb8f968602bc2bc4bab5eeb3632197a289))
100
-
101
- ## [2.0.8](https://github.com/JamesToohey/csprefabricate/compare/v2.0.7...v2.0.8) (2026-01-30)
102
-
103
-
104
- ### Bug Fixes
105
-
106
- * try again ([93a8888](https://github.com/JamesToohey/csprefabricate/commit/93a8888c8a435a8befca4bd60cb830ba1260b040))
107
-
108
- ## [2.0.7](https://github.com/JamesToohey/csprefabricate/compare/v2.0.6...v2.0.7) (2026-01-30)
109
-
110
-
111
- ### Bug Fixes
13
+ ### Features
112
14
 
113
- * trigger release please ([57c16d6](https://github.com/JamesToohey/csprefabricate/commit/57c16d606ef27635a3a3a0427a9e187a69722411))
15
+ * Add CSP Level 3 directives and deprecation warnings ([#68](https://github.com/JamesToohey/csprefabricate/issues/68)) ([35e91fa](https://github.com/JamesToohey/csprefabricate/commit/35e91fa51374794dc6a6cb5d661fb39558605ba8))
16
+ * Improve exposed types ([#66](https://github.com/JamesToohey/csprefabricate/issues/66)) ([71028e2](https://github.com/JamesToohey/csprefabricate/commit/71028e293673353b1b966fd9acf0c59c15b54383))
114
17
 
115
- ## [2.0.6](https://github.com/JamesToohey/csprefabricate/compare/v2.0.5...v2.0.6) (2026-01-30)
18
+ ## [2.0.22](https://github.com/JamesToohey/csprefabricate/compare/v2.0.21...v2.0.22) (2026-01-30)
116
19
 
117
20
 
118
21
  ### Bug Fixes
package/README.md CHANGED
@@ -13,8 +13,11 @@ This project aims to make creating useful and secure CSPs a more pleasant experi
13
13
  Currently `csprefabricate`:
14
14
 
15
15
  - Validates directive names
16
+ - Supports CSP Level 3 directives (`script-src-elem`, `script-src-attr`, `style-src-elem`, `style-src-attr`, `webrtc`)
17
+ - Supports CSP Level 3 keyword sources (`'wasm-unsafe-eval'`, `'inline-speculation-rules'`, `'unsafe-allow-redirects'`, `'trusted-types-eval'`, `'report-sample'`, `'report-sha256'`, `'report-sha384'`, `'report-sha512'`, `'unsafe-webtransport-hashes'`)
16
18
  - Supports providing a list of TLDs for a given domain name
17
19
  - Provides warnings for insecure or incomplete CSP configurations, with options to disable specific warnings
20
+ - Warns about deprecated directives (`plugin-types`, `report-uri`, `block-all-mixed-content`)
18
21
 
19
22
  ## Common CSP Issues
20
23
 
@@ -25,6 +28,7 @@ By default, `csprefabricate` will warn you about common CSP issues, such as:
25
28
  - Use of `'unsafe-inline'` in `script-src`, even if nonces or hashes are present
26
29
  - Missing nonces or hashes when using `'unsafe-inline'` in `script-src`
27
30
  - Allowing `data:` in `img-src` or `media-src`
31
+ - Use of deprecated directives (`plugin-types`, `report-uri`, `block-all-mixed-content`)
28
32
 
29
33
  You can control which warnings are shown by passing an optional `WarningOptions` object to the `create` function:
30
34
 
@@ -48,6 +52,7 @@ const warningOptions: WarningOptions = {
48
52
  unsafeInline: false,
49
53
  missingNonceOrHash: false,
50
54
  dataUri: false,
55
+ deprecatedDirectives: false,
51
56
  };
52
57
 
53
58
  create(csp, warningOptions);
@@ -118,6 +123,55 @@ const cspString = create(csp);
118
123
  // "img-src 'self' *.example.com *.example.co.uk *.example.net;"
119
124
  ```
120
125
 
126
+ ### Example 4: Using CSP Level 3 Directives and Keywords
127
+
128
+ CSP Level 3 introduced more granular control over scripts and styles, plus new keyword sources:
129
+
130
+ ```typescript
131
+ import {create, Directive, ContentSecurityPolicy} from "csprefabricate";
132
+
133
+ const csp: ContentSecurityPolicy = {
134
+ [Directive.DEFAULT_SRC]: ["self"],
135
+ // Control <script> elements separately from inline event handlers
136
+ [Directive.SCRIPT_SRC_ELEM]: ["self", "https://cdn.example.com"],
137
+ [Directive.SCRIPT_SRC_ATTR]: ["none"],
138
+ // Control <style> elements separately from inline styles
139
+ [Directive.STYLE_SRC_ELEM]: ["self"],
140
+ [Directive.STYLE_SRC_ATTR]: ["unsafe-inline"],
141
+ // Allow WebAssembly compilation (but not eval)
142
+ [Directive.SCRIPT_SRC]: ["self", "wasm-unsafe-eval"],
143
+ // Control WebRTC connections
144
+ [Directive.WEBRTC]: ["allow"],
145
+ [Directive.OBJECT_SRC]: ["none"],
146
+ [Directive.BASE_URI]: ["self"],
147
+ };
148
+
149
+ const cspString = create(csp);
150
+ // "default-src 'self'; script-src-elem 'self' https://cdn.example.com; script-src-attr 'none'; style-src-elem 'self'; style-src-attr 'unsafe-inline'; script-src 'self' 'wasm-unsafe-eval'; webrtc 'allow'; object-src 'none'; base-uri 'self';"
151
+ ```
152
+
153
+ #### CSP Level 3 Keyword Sources
154
+
155
+ CSP Level 3 introduces several new keyword sources that are automatically wrapped in single quotes:
156
+
157
+ - **`'wasm-unsafe-eval'`** - Allows WebAssembly compilation without allowing JavaScript eval
158
+ - **`'inline-speculation-rules'`** - Allows inline speculation rules for prefetching
159
+ - **`'unsafe-allow-redirects'`** - Allows redirects in navigation (experimental)
160
+ - **`'trusted-types-eval'`** - Allows eval when combined with Trusted Types
161
+ - **`'report-sample'`** - Includes code samples in violation reports
162
+ - **`'report-sha256'`, `'report-sha384'`, `'report-sha512'`** - Generates hash-based reports for subresources
163
+ - **`'unsafe-webtransport-hashes'`** - Allows WebTransport connections with certificate hashes
164
+
165
+ ## Deprecated Directives
166
+
167
+ Some CSP directives have been deprecated in favor of newer alternatives. `csprefabricate` will warn you when using these directives:
168
+
169
+ - **`plugin-types`** - Never widely supported, scheduled for removal
170
+ - **`report-uri`** - Use `report-to` instead
171
+ - **`block-all-mixed-content`** - Use `upgrade-insecure-requests` instead
172
+
173
+ These directives are still functional but may be removed from future CSP specifications. You can disable these warnings by setting `deprecatedDirectives: false` in your `WarningOptions`.
174
+
121
175
  ## Baseline Recommended CSPs
122
176
 
123
177
  You can quickly generate a recommended Content Security Policy for common use cases using built-in baselines.
package/dist/helpers.d.ts CHANGED
@@ -5,6 +5,7 @@ export interface WarningOptions {
5
5
  unsafeInline?: boolean;
6
6
  missingNonceOrHash?: boolean;
7
7
  dataUri?: boolean;
8
+ deprecatedDirectives?: boolean;
8
9
  }
9
10
  export declare function warnOnCspIssues(csp: ContentSecurityPolicy, overrides?: WarningOptions): void;
10
11
  export declare const isValidDirective: (directive: string) => boolean;
package/dist/helpers.js CHANGED
@@ -9,6 +9,7 @@ const DEFAULT_WARNINGS = {
9
9
  unsafeInline: true,
10
10
  missingNonceOrHash: true,
11
11
  dataUri: true,
12
+ deprecatedDirectives: true,
12
13
  };
13
14
  const validDirectives = [
14
15
  "default-src",
@@ -36,6 +37,12 @@ const validDirectives = [
36
37
  "trusted-types",
37
38
  "upgrade-insecure-requests",
38
39
  "block-all-mixed-content",
40
+ "script-src-elem",
41
+ "script-src-attr",
42
+ "style-src-elem",
43
+ "style-src-attr",
44
+ "webrtc",
45
+ "fenced-frame-src",
39
46
  ];
40
47
  const specialRules = [
41
48
  "none",
@@ -44,6 +51,18 @@ const specialRules = [
44
51
  "unsafe-eval",
45
52
  "strict-dynamic",
46
53
  "unsafe-hashes",
54
+ "wasm-unsafe-eval",
55
+ "inline-speculation-rules",
56
+ "unsafe-allow-redirects",
57
+ "trusted-types-eval",
58
+ "report-sample",
59
+ "report-sha256",
60
+ "report-sha384",
61
+ "report-sha512",
62
+ "unsafe-webtransport-hashes",
63
+ "allow",
64
+ "block",
65
+ "script",
47
66
  ];
48
67
  function warnOnCspIssues(csp, overrides = {}) {
49
68
  const options = { ...DEFAULT_WARNINGS, ...overrides };
@@ -102,6 +121,18 @@ function warnOnCspIssues(csp, overrides = {}) {
102
121
  }
103
122
  });
104
123
  }
124
+ // 6. Deprecated directives
125
+ if (options.deprecatedDirectives) {
126
+ if (types_1.Directive.PLUGIN_TYPES in csp) {
127
+ console.warn(`[CSPrefabricate] Directive 'plugin-types' is deprecated and may be removed in future CSP versions. This directive was never widely supported.`);
128
+ }
129
+ if (types_1.Directive.REPORT_URI in csp) {
130
+ console.warn(`[CSPrefabricate] Directive 'report-uri' is deprecated and may be removed in future CSP versions. Use 'report-to' instead.`);
131
+ }
132
+ if (types_1.Directive.BLOCK_ALL_MIXED_CONTENT in csp) {
133
+ console.warn(`[CSPrefabricate] Directive 'block-all-mixed-content' is deprecated and may be removed in future CSP versions. Use 'upgrade-insecure-requests' instead.`);
134
+ }
135
+ }
105
136
  }
106
137
  const isValidDirective = (directive) => validDirectives.includes(directive);
107
138
  exports.isValidDirective = isValidDirective;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Directive } from "./types";
2
1
  import { create } from "./utils";
3
2
  import * as Baseline from "./baseline";
4
3
  export { Baseline };
5
- export { create, Directive };
6
- export type { ContentSecurityPolicy } from "./types";
4
+ export { create };
5
+ export { Directive } from "./types";
6
+ export type { ContentSecurityPolicy, Rules, BasicDirectiveRule, BlankDirectiveRule, AllowBlockRule, RequireTrustedTypesForRule, CSPDirective, CSP, } from "./types";
7
+ export type { WarningOptions } from "./helpers";
package/dist/index.js CHANGED
@@ -34,9 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Directive = exports.create = exports.Baseline = void 0;
37
- const types_1 = require("./types");
38
- Object.defineProperty(exports, "Directive", { enumerable: true, get: function () { return types_1.Directive; } });
39
37
  const utils_1 = require("./utils");
40
38
  Object.defineProperty(exports, "create", { enumerable: true, get: function () { return utils_1.create; } });
41
39
  const Baseline = __importStar(require("./baseline"));
42
40
  exports.Baseline = Baseline;
41
+ var types_1 = require("./types");
42
+ Object.defineProperty(exports, "Directive", { enumerable: true, get: function () { return types_1.Directive; } });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../index");
4
+ const rules = ["self", "example.com"];
5
+ const basicRule = ["self", "example.com"];
6
+ const blankRule = null;
7
+ const allowBlockRule = ["allow"];
8
+ const requireTrustedTypesForRule = ["script"];
9
+ const directive = index_1.Directive.DEFAULT_SRC;
10
+ const csp = { [directive]: rules };
11
+ const cspByName = { [index_1.Directive.SCRIPT_SRC]: basicRule };
12
+ const options = { overlyPermissive: false };
13
+ void rules;
14
+ void basicRule;
15
+ void blankRule;
16
+ void allowBlockRule;
17
+ void requireTrustedTypesForRule;
18
+ void directive;
19
+ void csp;
20
+ void cspByName;
21
+ void options;
package/dist/types.d.ts CHANGED
@@ -23,11 +23,19 @@ declare enum Directive {
23
23
  REQUIRE_TRUSTED_TYPES_FOR = "require-trusted-types-for",
24
24
  TRUSTED_TYPES = "trusted-types",
25
25
  UPGRADE_INSECURE_REQUESTS = "upgrade-insecure-requests",
26
- BLOCK_ALL_MIXED_CONTENT = "block-all-mixed-content"
26
+ BLOCK_ALL_MIXED_CONTENT = "block-all-mixed-content",
27
+ SCRIPT_SRC_ELEM = "script-src-elem",
28
+ SCRIPT_SRC_ATTR = "script-src-attr",
29
+ STYLE_SRC_ELEM = "style-src-elem",
30
+ STYLE_SRC_ATTR = "style-src-attr",
31
+ WEBRTC = "webrtc",
32
+ FENCED_FRAME_SRC = "fenced-frame-src"
27
33
  }
28
34
  type BasicDirectiveRule = Array<string | Record<string, Array<string>>>;
29
35
  type BlankDirectiveRule = null;
30
- type Rules = BasicDirectiveRule | BlankDirectiveRule;
36
+ type AllowBlockRule = Array<"allow" | "block">;
37
+ type RequireTrustedTypesForRule = ["script"];
38
+ type Rules = BasicDirectiveRule | BlankDirectiveRule | AllowBlockRule | RequireTrustedTypesForRule;
31
39
  interface ContentSecurityPolicy {
32
40
  [Directive.DEFAULT_SRC]?: BasicDirectiveRule;
33
41
  [Directive.SCRIPT_SRC]?: BasicDirectiveRule;
@@ -50,9 +58,17 @@ interface ContentSecurityPolicy {
50
58
  [Directive.MANIFEST_SRC]?: BasicDirectiveRule;
51
59
  [Directive.PREFETCH_SRC]?: BasicDirectiveRule;
52
60
  [Directive.NAVIGATE_TO]?: BasicDirectiveRule;
53
- [Directive.REQUIRE_TRUSTED_TYPES_FOR]?: BasicDirectiveRule;
61
+ [Directive.REQUIRE_TRUSTED_TYPES_FOR]?: RequireTrustedTypesForRule;
54
62
  [Directive.TRUSTED_TYPES]?: BasicDirectiveRule;
55
63
  [Directive.UPGRADE_INSECURE_REQUESTS]?: BlankDirectiveRule;
56
64
  [Directive.BLOCK_ALL_MIXED_CONTENT]?: BlankDirectiveRule;
65
+ [Directive.SCRIPT_SRC_ELEM]?: BasicDirectiveRule;
66
+ [Directive.SCRIPT_SRC_ATTR]?: BasicDirectiveRule;
67
+ [Directive.STYLE_SRC_ELEM]?: BasicDirectiveRule;
68
+ [Directive.STYLE_SRC_ATTR]?: BasicDirectiveRule;
69
+ [Directive.WEBRTC]?: AllowBlockRule;
70
+ [Directive.FENCED_FRAME_SRC]?: BasicDirectiveRule;
57
71
  }
58
- export { ContentSecurityPolicy, Rules, Directive, BasicDirectiveRule };
72
+ type CSPDirective = Directive;
73
+ type CSP = ContentSecurityPolicy;
74
+ export { ContentSecurityPolicy, Rules, Directive, BasicDirectiveRule, BlankDirectiveRule, AllowBlockRule, RequireTrustedTypesForRule, CSPDirective, CSP, };
package/dist/types.js CHANGED
@@ -28,4 +28,10 @@ var Directive;
28
28
  Directive["TRUSTED_TYPES"] = "trusted-types";
29
29
  Directive["UPGRADE_INSECURE_REQUESTS"] = "upgrade-insecure-requests";
30
30
  Directive["BLOCK_ALL_MIXED_CONTENT"] = "block-all-mixed-content";
31
+ Directive["SCRIPT_SRC_ELEM"] = "script-src-elem";
32
+ Directive["SCRIPT_SRC_ATTR"] = "script-src-attr";
33
+ Directive["STYLE_SRC_ELEM"] = "style-src-elem";
34
+ Directive["STYLE_SRC_ATTR"] = "style-src-attr";
35
+ Directive["WEBRTC"] = "webrtc";
36
+ Directive["FENCED_FRAME_SRC"] = "fenced-frame-src";
31
37
  })(Directive || (exports.Directive = Directive = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "csprefabricate",
3
- "version": "2.0.22",
3
+ "version": "2.1.1",
4
4
  "description": "Generate valid and secure Content Security Policies (CSP) with TypeScript.",
5
5
  "keywords": [
6
6
  "csp",
@@ -23,6 +23,12 @@
23
23
  "name": "James Toohey",
24
24
  "url": "https://github.com/JamesToohey"
25
25
  },
26
+ "funding": {
27
+ "type": "github",
28
+ "url": "https://github.com/sponsors/JamesToohey"
29
+ },
30
+ "type": "commonjs",
31
+ "sideEffects": false,
26
32
  "packageManager": "yarn@4.12.0",
27
33
  "exports": {
28
34
  ".": {
@@ -41,6 +47,8 @@
41
47
  ],
42
48
  "scripts": {
43
49
  "build": "tsc --project tsconfig.build.json",
50
+ "format": "prettier --write .",
51
+ "format:check": "prettier --check .",
44
52
  "functional-test": "yarn build && tsx --test src/test/functional/functional.test.js",
45
53
  "lint": "eslint .",
46
54
  "pack": "npm pack",