turva-llms-txt-validator 0.8.1 → 0.8.2
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 -2
- package/dist/src/index.js +29 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -253,12 +253,12 @@ The strict type check found two inputs that could leave `undefined` in a check's
|
|
|
253
253
|
GitHub Actions publishes every version from 0.1.3 on with npm trusted publishing, and each one carries a provenance attestation. To check one, install it in an empty directory and ask npm to verify the signatures. Replace the version with the one you want to check.
|
|
254
254
|
|
|
255
255
|
```sh
|
|
256
|
-
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.8.
|
|
256
|
+
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.8.2 --ignore-scripts && npm audit signatures
|
|
257
257
|
```
|
|
258
258
|
|
|
259
259
|
`npm audit signatures` checks the registry signature and the provenance attestation of each installed package that has one. The attestation of this package names three things to compare with what you expect: the repository `github.com/erekola/llms-txt-validator`, the workflow file `.github/workflows/publish.yml` and the commit that produced the tarball. The npm version page shows them under Provenance.
|
|
260
260
|
|
|
261
|
-
Tag `v0.8.
|
|
261
|
+
Tag `v0.8.2` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.8.2 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves which workflow built a release and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
|
|
262
262
|
|
|
263
263
|
## Development
|
|
264
264
|
|
package/dist/src/index.js
CHANGED
|
@@ -23,6 +23,32 @@ export function cut(s, n) {
|
|
|
23
23
|
s = String(s).slice(0, n);
|
|
24
24
|
return /[\uD800-\uDBFF]$/.test(s) ? s.slice(0, -1) : s;
|
|
25
25
|
}
|
|
26
|
+
// Removes a run of the characters strip accepts from each end of s, with two index loops. The regex form
|
|
27
|
+
// s.replace(/^[set]+|[set]+$/g, "") tries the trailing alternative again from every position inside a long run of
|
|
28
|
+
// those characters that does not reach the end, so its time grows with the square of the run (CodeQL
|
|
29
|
+
// js/polynomial-redos, 2026-11-22). The result is the same string.
|
|
30
|
+
function trimEnds(s, strip) {
|
|
31
|
+
let a = 0;
|
|
32
|
+
let b = s.length;
|
|
33
|
+
while (a < b && strip(s.charCodeAt(a)))
|
|
34
|
+
a++;
|
|
35
|
+
while (b > a && strip(s.charCodeAt(b - 1)))
|
|
36
|
+
b--;
|
|
37
|
+
return s.slice(a, b);
|
|
38
|
+
}
|
|
39
|
+
// The characters maskLocation() removes at either end of an address: C0 controls and spaces, which a URL parser
|
|
40
|
+
// drops, and the Unicode white space, U+0085, U+180E, U+200B and U+FFFD, which a reader does not see.
|
|
41
|
+
function isUrlEdge(c) {
|
|
42
|
+
return c <= 0x20 || c === 0x85 || c === 0x180e || c === 0x200b || c === 0xfffd || /\s/.test(String.fromCharCode(c));
|
|
43
|
+
}
|
|
44
|
+
// C0 controls and spaces, the characters a URL parser removes at either end of an address.
|
|
45
|
+
function isC0OrSpace(c) {
|
|
46
|
+
return c <= 0x20;
|
|
47
|
+
}
|
|
48
|
+
// HTTP white space: tab, LF, CR and space.
|
|
49
|
+
function isHttpSpace(c) {
|
|
50
|
+
return c === 0x09 || c === 0x0a || c === 0x0d || c === 0x20;
|
|
51
|
+
}
|
|
26
52
|
// A redirect target the way a report may show it. The scheme, the host and the path stay readable,
|
|
27
53
|
// and the parts that can carry a secret do not: the user name and the password are removed, every
|
|
28
54
|
// query value becomes ***, and the fragment is dropped. The caller cuts the result to length
|
|
@@ -47,8 +73,7 @@ export function maskLocation(href, base, written) {
|
|
|
47
73
|
// The same reading also removes, at either end, the invisible characters that a URL parser keeps: the Unicode
|
|
48
74
|
// white space, U+0085, U+180E, U+200B and U+FFFD. A reader does not see them, so a value that starts with U+2003
|
|
49
75
|
// and then https:/user:pw@host is read as the address it shows (L3 of the third independent check).
|
|
50
|
-
const
|
|
51
|
-
const parserInput = (t) => t.replace(/[\t\n\r]/g, "").replace(new RegExp("^" + edge + "|" + edge + "$", "g"), "");
|
|
76
|
+
const parserInput = (t) => trimEnds(t.replace(/[\t\n\r]/g, ""), isUrlEdge);
|
|
52
77
|
const text = parserInput(String(href));
|
|
53
78
|
// Where an authority starts in a text, read from the text and not from the parser: after a scheme and two slashes, the
|
|
54
79
|
// scheme being whatever stands before "://" with no / \ ? or # in it. invalid is true when that "scheme" is not one.
|
|
@@ -99,7 +124,7 @@ export function maskLocation(href, base, written) {
|
|
|
99
124
|
const w = parserInput(String(written));
|
|
100
125
|
// A written form that lost invisible characters at its ends was resolved by the parser with them, so href is not the
|
|
101
126
|
// address the reading sees, and the written form is masked instead (differential fuzz against 3.260.6).
|
|
102
|
-
const parserOwn = String(written).replace(/[\t\n\r]/g, "")
|
|
127
|
+
const parserOwn = trimEnds(String(written).replace(/[\t\n\r]/g, ""), isC0OrSpace);
|
|
103
128
|
if (ambiguous(w) || shapeOf(w).invalid || (w !== parserOwn && w.includes("@")))
|
|
104
129
|
return maskLocation(written, base);
|
|
105
130
|
}
|
|
@@ -1741,7 +1766,7 @@ export function validateLlmsTxt(f) {
|
|
|
1741
1766
|
}
|
|
1742
1767
|
// The media type is compared whole, without its parameters. A substring test passed
|
|
1743
1768
|
// application/x-text/plain and text/markdownish until 2026-09-27 (Tek-496).
|
|
1744
|
-
const mediaType = ct.split(";")[0]
|
|
1769
|
+
const mediaType = trimEnds(ct.split(";")[0], isHttpSpace);
|
|
1745
1770
|
if (mediaType === "text/plain" || mediaType === "text/markdown") {
|
|
1746
1771
|
add("content-type", "pass", "Response is plain text", mediaType);
|
|
1747
1772
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turva-llms-txt-validator",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Validate a site's llms.txt structure: eight checks as pass/warn/fail plus two llms.txt v2 discovery checks that read pass or info and never move the summary, JSON output. Same checks as the hosted validator at turva.dev/llms-txt-validator.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|