@botiverse/porthole 0.3.4 → 0.4.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/README.md +2 -0
- package/dist/check/lint.js +17 -0
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +14 -0
- package/dist/conformance/harness-source.js +1 -1
- package/dist/guide/guide.d.ts +2 -0
- package/dist/guide/guide.js +40 -12
- package/dist/presets/presets.d.ts +3 -2
- package/dist/presets/presets.js +7 -2
- package/docs/ADOPTING.md +43 -0
- package/docs/DECISIONS.md +52 -0
- package/docs/DESIGN.md +6 -3
- package/package.json +1 -1
- package/src/check/lint.ts +27 -0
- package/src/check/page.ts +16 -0
- package/src/guide/guide.ts +49 -12
- package/src/presets/presets.ts +7 -2
package/README.md
CHANGED
|
@@ -69,6 +69,8 @@ width, light and dark, before anyone sees it, and tells the agent what broke in
|
|
|
69
69
|
|
|
70
70
|
- [docs/ADOPTING.md](docs/ADOPTING.md): getting started, step by step: the server, the page, its
|
|
71
71
|
CSP, Workers, local development, the agent's tools, conformance, troubleshooting.
|
|
72
|
+
- [Choosing egress](docs/ADOPTING.md#choosing-egress): what content may load (closed, library
|
|
73
|
+
CDNs, passive media from any https site), what each level opens and the risk it re-opens.
|
|
72
74
|
- [docs/DESIGN.md](docs/DESIGN.md): how it works. [docs/DECISIONS.md](docs/DECISIONS.md): why,
|
|
73
75
|
by P-number (the code cites them).
|
|
74
76
|
|
package/dist/check/lint.js
CHANGED
|
@@ -40,6 +40,19 @@ const REACHES = [
|
|
|
40
40
|
},
|
|
41
41
|
];
|
|
42
42
|
const CDN_PACKAGE = /^https:\/\/(?:cdn\.jsdelivr\.net\/npm|unpkg\.com|esm\.sh)\/((?:@[^/]+\/)?[^/@]+)(@[^/]*)?/u;
|
|
43
|
+
/**
|
|
44
|
+
* Libraries' own CDNs (P078): the version is in the path (`/3.4.17`, `jquery-3.7.1.min.js`,
|
|
45
|
+
* `plotly-3.4.0.min.js`); without it the host serves its latest (Tailwind redirects to it).
|
|
46
|
+
*/
|
|
47
|
+
const OWN_CDN = [
|
|
48
|
+
{
|
|
49
|
+
name: "Tailwind",
|
|
50
|
+
host: /^https:\/\/cdn\.tailwindcss\.com(?:[/?#]|$)/u,
|
|
51
|
+
pinned: /^\/\d+\.\d+\.\d+/u,
|
|
52
|
+
},
|
|
53
|
+
{ name: "jQuery", host: /^https:\/\/code\.jquery\.com\//u, pinned: /\d+\.\d+\.\d+/u },
|
|
54
|
+
{ name: "Plotly", host: /^https:\/\/cdn\.plot\.ly\/plotly/u, pinned: /\d+\.\d+\.\d+/u },
|
|
55
|
+
];
|
|
43
56
|
export function lintContent(config, content) {
|
|
44
57
|
if (config.mode === "url") {
|
|
45
58
|
return [];
|
|
@@ -111,6 +124,10 @@ export function lintContent(config, content) {
|
|
|
111
124
|
reported.add(`${kind} ${origin}`);
|
|
112
125
|
add("egress", "warning", `Nothing loads from ${origin} here (${kind}): ${kind === "script" || kind === "style" ? "write it inline, or use a library from an allowed CDN" : kind === "connect" ? "the content can't call it; work from data in the content" : "put it inline as a data: URL"}.`, match.index);
|
|
113
126
|
}
|
|
127
|
+
const own = OWN_CDN.find((each) => each.host.test(address));
|
|
128
|
+
if (own !== undefined && kind === "script" && !own.pinned.test(new URL(address).pathname)) {
|
|
129
|
+
add("unpinned", "warning", `Pin an exact version of ${own.name} (its version in the URL's path), never its latest: the code then can't change under the ${it}.`, match.index);
|
|
130
|
+
}
|
|
114
131
|
const pinned = CDN_PACKAGE.exec(address);
|
|
115
132
|
if (pinned !== null && (pinned[2] === undefined || !/^@\d+\.\d+\.\d+/u.test(pinned[2]))) {
|
|
116
133
|
add("unpinned", "warning", `Pin an exact version of ${pinned[1]} (${pinned[1]}@1.2.3 in its URL), never @latest or a range: the code then can't change under the ${it}.`, match.index);
|