@jamesbrightman/pretty-csp 0.0.0-stage → 0.2.0
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 +61 -0
- package/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-JAXLODN4.js +559 -0
- package/dist/chunk-JAXLODN4.js.map +1 -0
- package/dist/chunk-KWWYRHIP.js +224 -0
- package/dist/chunk-KWWYRHIP.js.map +1 -0
- package/dist/chunk-YMAXUCI4.js +66 -0
- package/dist/chunk-YMAXUCI4.js.map +1 -0
- package/dist/cli.cjs +1049 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +328 -0
- package/dist/cli.js.map +1 -0
- package/dist/index-CvwFjLiu.d.cts +426 -0
- package/dist/index-CvwFjLiu.d.ts +426 -0
- package/dist/index.cjs +830 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.cjs +309 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +38 -0
- package/dist/testing.d.ts +38 -0
- package/dist/testing.js +10 -0
- package/dist/testing.js.map +1 -0
- package/package.json +102 -4
- package/website/static/img/how-it-works.svg +34 -0
- package/website/static/img/pretty-csp-icon.svg +6 -0
- package/website/static/img/pretty-csp-logo.svg +12 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { P as Policy, M as MatchOptions, S as Severity } from './index-CvwFjLiu.cjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/** Matchers can be registered with either Jest's or Vitest's `expect.extend`. */
|
|
5
|
+
declare const cspMatchers: {
|
|
6
|
+
toAllow(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message: () => string;
|
|
9
|
+
};
|
|
10
|
+
toBlock(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message: () => string;
|
|
13
|
+
};
|
|
14
|
+
toMatchCspSnapshot(this: {
|
|
15
|
+
equals(actual: unknown, expected: unknown): boolean;
|
|
16
|
+
}, policy: Policy, expected: ReturnType<typeof cspSnapshot>): {
|
|
17
|
+
pass: boolean;
|
|
18
|
+
message: () => "Expected CSP snapshot to differ from the supplied snapshot" | "CSP snapshot differs; review and update the committed snapshot";
|
|
19
|
+
};
|
|
20
|
+
toPassAudit(policy: Policy, options?: {
|
|
21
|
+
maxSeverity?: Severity;
|
|
22
|
+
}): {
|
|
23
|
+
pass: boolean;
|
|
24
|
+
message: () => string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Assertion signatures for a test runner's TypeScript module augmentation. */
|
|
28
|
+
type CspAssertions<Received = unknown> = {
|
|
29
|
+
[Name in keyof typeof cspMatchers]: (...args: (typeof cspMatchers)[Name] extends (policy: Policy, ...args: infer Arguments) => unknown ? Arguments : never) => Received extends Promise<unknown> ? Promise<void> : void;
|
|
30
|
+
};
|
|
31
|
+
/** Stable, provenance-aware input for a test runner's built-in snapshot matcher. */
|
|
32
|
+
declare function cspSnapshot(policy: Policy): {
|
|
33
|
+
schemaVersion: 2;
|
|
34
|
+
directives: Record<string, string[]>;
|
|
35
|
+
contributors: ReturnType<Policy['explain']>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { type CspAssertions, cspMatchers, cspSnapshot };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { P as Policy, M as MatchOptions, S as Severity } from './index-CvwFjLiu.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/** Matchers can be registered with either Jest's or Vitest's `expect.extend`. */
|
|
5
|
+
declare const cspMatchers: {
|
|
6
|
+
toAllow(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message: () => string;
|
|
9
|
+
};
|
|
10
|
+
toBlock(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message: () => string;
|
|
13
|
+
};
|
|
14
|
+
toMatchCspSnapshot(this: {
|
|
15
|
+
equals(actual: unknown, expected: unknown): boolean;
|
|
16
|
+
}, policy: Policy, expected: ReturnType<typeof cspSnapshot>): {
|
|
17
|
+
pass: boolean;
|
|
18
|
+
message: () => "Expected CSP snapshot to differ from the supplied snapshot" | "CSP snapshot differs; review and update the committed snapshot";
|
|
19
|
+
};
|
|
20
|
+
toPassAudit(policy: Policy, options?: {
|
|
21
|
+
maxSeverity?: Severity;
|
|
22
|
+
}): {
|
|
23
|
+
pass: boolean;
|
|
24
|
+
message: () => string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Assertion signatures for a test runner's TypeScript module augmentation. */
|
|
28
|
+
type CspAssertions<Received = unknown> = {
|
|
29
|
+
[Name in keyof typeof cspMatchers]: (...args: (typeof cspMatchers)[Name] extends (policy: Policy, ...args: infer Arguments) => unknown ? Arguments : never) => Received extends Promise<unknown> ? Promise<void> : void;
|
|
30
|
+
};
|
|
31
|
+
/** Stable, provenance-aware input for a test runner's built-in snapshot matcher. */
|
|
32
|
+
declare function cspSnapshot(policy: Policy): {
|
|
33
|
+
schemaVersion: 2;
|
|
34
|
+
directives: Record<string, string[]>;
|
|
35
|
+
contributors: ReturnType<Policy['explain']>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { type CspAssertions, cspMatchers, cspSnapshot };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,104 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamesbrightman/pretty-csp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "CSP as code: readable, extendable, testable policies in TypeScript",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"packageManager": "pnpm@10.17.1",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"website/static/img/*.svg"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"default": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./testing": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/testing.d.ts",
|
|
35
|
+
"default": "./dist/testing.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/testing.d.cts",
|
|
39
|
+
"default": "./dist/testing.cjs"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"docs:dev": "pnpm build && docusaurus start website --host 127.0.0.1 --no-open",
|
|
46
|
+
"docs:build": "pnpm build && docusaurus build website",
|
|
47
|
+
"docs:preview": "pnpm build && docusaurus serve website --build",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"format:check": "prettier --check .",
|
|
51
|
+
"format": "prettier --write .",
|
|
52
|
+
"test": "vitest run --passWithNoTests",
|
|
53
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
54
|
+
"changeset": "changeset",
|
|
55
|
+
"release": "npm publish --provenance --access public",
|
|
56
|
+
"prepublishOnly": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build",
|
|
57
|
+
"prepare": "node --input-type=module -e \"if (!process.env.CI && process.env.NODE_ENV !== 'production') (await import('husky')).default()\""
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"jiti": "^2.7.0",
|
|
61
|
+
"zod": "^4.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@babel/parser": "^7.29.17",
|
|
65
|
+
"@changesets/cli": "^2.29.0",
|
|
66
|
+
"@codemirror/lang-javascript": "^6.2.5",
|
|
67
|
+
"@codemirror/language": "^6.13.1",
|
|
68
|
+
"@codemirror/state": "^6.7.6",
|
|
69
|
+
"@codemirror/theme-one-dark": "^6.1.3",
|
|
70
|
+
"@codemirror/view": "^6.44.2",
|
|
71
|
+
"@commitlint/cli": "20.0.0",
|
|
72
|
+
"@commitlint/config-conventional": "20.0.0",
|
|
73
|
+
"@docusaurus/core": "3.10.2",
|
|
74
|
+
"@docusaurus/preset-classic": "3.10.2",
|
|
75
|
+
"@easyops-cn/docusaurus-search-local": "0.55.3",
|
|
76
|
+
"@eslint/js": "^9.0.0",
|
|
77
|
+
"@mdx-js/react": "3.1.1",
|
|
78
|
+
"@types/estree": "^1.0.11",
|
|
79
|
+
"@types/node": "^20.0.0",
|
|
80
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
81
|
+
"codemirror": "^6.0.2",
|
|
82
|
+
"eslint": "^9.0.0",
|
|
83
|
+
"husky": "9.1.7",
|
|
84
|
+
"prettier": "^3.0.0",
|
|
85
|
+
"react": "18.3.1",
|
|
86
|
+
"react-dom": "18.3.1",
|
|
87
|
+
"tsup": "^8.0.0",
|
|
88
|
+
"tsx": "^4.23.15",
|
|
89
|
+
"typescript": "^5.0.0",
|
|
90
|
+
"typescript-eslint": "^8.0.0",
|
|
91
|
+
"vitest": "^3.0.0"
|
|
92
|
+
},
|
|
93
|
+
"bin": {
|
|
94
|
+
"pretty-csp": "dist/cli.js"
|
|
95
|
+
},
|
|
96
|
+
"repository": {
|
|
97
|
+
"type": "git",
|
|
98
|
+
"url": "git+https://github.com/JamesBrightman/pretty-csp.git"
|
|
99
|
+
},
|
|
100
|
+
"homepage": "https://jamesbrightman.github.io/pretty-csp/",
|
|
101
|
+
"bugs": {
|
|
102
|
+
"url": "https://github.com/JamesBrightman/pretty-csp/issues"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 470" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">How pretty-csp works</title>
|
|
3
|
+
<desc id="desc">Start with a base policy, add named rule sets, then review the resulting Content Security Policy header and audit findings.</desc>
|
|
4
|
+
<rect width="1200" height="470" rx="24" fill="#F5E8C8"/>
|
|
5
|
+
<text x="600" y="68" text-anchor="middle" fill="#941F2B" font-family="Lobster, Pacifico, 'Brush Script MT', cursive" font-size="48" font-style="italic">From building blocks to a policy you can review</text>
|
|
6
|
+
<g font-family="Arial, sans-serif" text-anchor="middle">
|
|
7
|
+
<rect x="42" y="132" width="270" height="230" rx="18" fill="#FFF9EA" stroke="#D8B765" stroke-width="3"/>
|
|
8
|
+
<text x="177" y="184" fill="#78313A" font-size="25" font-weight="700">BASE POLICY</text>
|
|
9
|
+
<text x="177" y="228" fill="#3A302D" font-size="18">Set safe defaults</text>
|
|
10
|
+
<text x="177" y="258" fill="#3A302D" font-size="18">and core directives</text>
|
|
11
|
+
<text x="177" y="319" fill="#941F2B" font-family="monospace" font-size="17">default-src 'self'</text>
|
|
12
|
+
|
|
13
|
+
<rect x="350" y="132" width="270" height="230" rx="18" fill="#FFF9EA" stroke="#D8B765" stroke-width="3"/>
|
|
14
|
+
<text x="485" y="184" fill="#78313A" font-size="25" font-weight="700">NAMED RULE SETS</text>
|
|
15
|
+
<text x="485" y="228" fill="#3A302D" font-size="18">Group permissions</text>
|
|
16
|
+
<text x="485" y="258" fill="#3A302D" font-size="18">by purpose and owner</text>
|
|
17
|
+
<text x="485" y="319" fill="#941F2B" font-family="monospace" font-size="17">Images CDN · web team</text>
|
|
18
|
+
|
|
19
|
+
<rect x="658" y="132" width="220" height="230" rx="18" fill="#941F2B"/>
|
|
20
|
+
<text x="768" y="205" fill="#F5E8C8" font-family="Lobster, Pacifico, 'Brush Script MT', cursive" font-size="42" font-style="italic">pretty-csp</text>
|
|
21
|
+
<text x="768" y="250" fill="#FFF9EA" font-size="18" font-weight="700">MERGE & EXPLAIN</text>
|
|
22
|
+
<text x="768" y="294" fill="#FFF9EA" font-size="17">Build · test · audit</text>
|
|
23
|
+
|
|
24
|
+
<rect x="916" y="132" width="242" height="230" rx="18" fill="#FFF9EA" stroke="#D8B765" stroke-width="3"/>
|
|
25
|
+
<text x="1037" y="184" fill="#78313A" font-size="25" font-weight="700">REVIEW OUTPUT</text>
|
|
26
|
+
<text x="1037" y="228" fill="#3A302D" font-size="18">Header string, readable</text>
|
|
27
|
+
<text x="1037" y="258" fill="#3A302D" font-size="18">explanation and findings</text>
|
|
28
|
+
<text x="1037" y="319" fill="#941F2B" font-family="monospace" font-size="17">policy.explain() · audit()</text>
|
|
29
|
+
</g>
|
|
30
|
+
<g fill="none" stroke="#941F2B" stroke-width="7" stroke-linecap="round" stroke-linejoin="round">
|
|
31
|
+
<path d="M315 247h27m-10-11 11 11-11 11"/><path d="M623 247h27m-10-11 11 11-11 11"/><path d="M881 247h27m-10-11 11 11-11 11"/>
|
|
32
|
+
</g>
|
|
33
|
+
<text x="600" y="425" text-anchor="middle" fill="#78313A" font-family="Arial, sans-serif" font-size="16" letter-spacing="1">The app still owns response headers, nonce propagation and reporting endpoints.</text>
|
|
34
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
|
2
|
+
<title>pretty-csp</title>
|
|
3
|
+
<rect width="32" height="32" rx="6" fill="#991F2D"/>
|
|
4
|
+
<path fill="#F5E8C8" d="M10.67 6H14.69L14.25 8.1Q15.64 6.89 17.52 6.89Q19.08 6.89 20.01 7.93Q20.93 8.96 20.93 11.31Q20.93 13.52 20.28 15.77Q19.64 18.02 18.1 19.6Q16.57 21.18 14.05 21.18Q12.26 21.18 11.67 20.17L10.22 26.99L6 28ZM17.1 11.23Q17.1 8.91 15.7 8.91Q15.2 8.91 14.68 9.27Q14.16 9.63 13.77 10.28L12.12 18.1Q12.35 18.75 13.18 18.75Q14.53 18.75 15.41 17.49Q16.29 16.23 16.69 14.48Q17.1 12.74 17.1 11.23Z"/>
|
|
5
|
+
<path fill="#F5E8C8" d="m25 3.4 1.1 2.4 2.6.3-1.9 1.8.5 2.6L25 9.2l-2.3 1.3.5-2.6-1.9-1.8 2.6-.3Z"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 430" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">pretty-csp</title>
|
|
3
|
+
<desc id="desc">A retro Americana wordmark in scarlet brush script on a warm cream background, framed by stars.</desc>
|
|
4
|
+
<rect width="1200" height="430" rx="28" fill="#F4E6C3"/>
|
|
5
|
+
<rect x="14" y="14" width="1172" height="402" rx="20" fill="none" stroke="#D8B765" stroke-width="3"/>
|
|
6
|
+
<path d="m105 50 8 18 19 1-15 12 5 19-17-11-16 11 5-19-15-12 19-1zM1090 50l8 18 19 1-15 12 5 19-17-11-16 11 5-19-15-12 19-1z" fill="#941F2B"/>
|
|
7
|
+
<text x="152" y="108" fill="#78313A" font-family="Arial, sans-serif" font-size="22" font-weight="700" letter-spacing="7">A FRIENDLIER LOOK AT</text>
|
|
8
|
+
<text x="46" y="293" fill="#8F1724" font-family="Lobster, Pacifico, 'Brush Script MT', cursive" font-size="208" font-style="italic" font-weight="700" letter-spacing="-8">pretty</text>
|
|
9
|
+
<text x="743" y="276" fill="#78313A" font-family="Georgia, serif" font-size="132" font-weight="700" letter-spacing="-4">CSP</text>
|
|
10
|
+
<path d="M70 334 C230 375 442 376 644 350 C793 331 941 299 1124 298 C1001 345 857 382 675 393 C423 408 202 389 70 334Z" fill="#8F1724"/>
|
|
11
|
+
<text x="752" y="352" fill="#F4E6C3" font-family="Arial, sans-serif" font-size="18" font-weight="700" letter-spacing="3">POLICY TOOLKIT</text>
|
|
12
|
+
</svg>
|