turva-llms-txt-validator 0.8.0 → 0.8.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/README.md CHANGED
@@ -91,9 +91,10 @@ With `--json`, an invalid domain or a failed fetch returns `{ "error": "...", "t
91
91
  In an error report the `target` is the address given on the command line. When it parses as a URL with a host, the user name and password are removed and each query value becomes `***`. Other values follow these cases:
92
92
 
93
93
  - In a value such as `user:secret@example.com` or `example.org:8443#a@b`, the part before the colon reads as a URL scheme and no authority follows it, so only `//***` is shown.
94
- - A value with no scheme and no slash is read as user information when a colon comes before its last `@`, so `user_name:secret@example.com` is shown as `***@example.com`.
94
+ - A value with no scheme and no slash is read as user information when a colon comes before its last `@` and before its first `?` or `#`. So `user_name:secret@example.com` and `user_name:se#cret@example.com` are shown as `***@example.com`. A backslash counts as part of the user name, as in a Windows domain account, so `CORP\erik:se#cret@example.com` is shown as `***@example.com` too. The same reading holds when such a value is a relative redirect target that is resolved against the request address, so the password does not come back in the path of the shown address. There a `?` or `#` before the last `@` shows only `***`, because the text after it could also be read as a query or a fragment. When a `?` or `#` comes before the colon, as in `user?x:secret@example.com`, the text from that character on is masked or cut, so the part before it is shown and the password is not.
95
95
  - Without that colon, as in `path@2x.png` or an e-mail address, the value is shown as given and holds no password.
96
- - An address that holds an `@` shows only `***`, with the scheme in front when a slash follows its colon and with no host, when a URL parser and a person would read it differently. That covers a backslash, a `?` or a `#` before the `@` and before any `/`, and a start that is not exactly a scheme, two slashes and a character other than a slash. `https://user:pa?ss@example.com/`, `https://example.org?e=a@b.com` and `https:///host?e=a@b.com` are shown as `https://***`. `user:secret@host.example://dd`, where no slash follows the scheme colon, is shown as `//***`. A redirect to such an address is reported as "a different host that this report does not name". A `/` before the `@` makes it a path, and a relative reference such as `/a@b` or `docs/@name` is masked as before.
96
+ - An address that holds an `@` shows only `***`, with the scheme in front when a slash follows its colon and with no host, when a URL parser and a person would read it differently. That covers a backslash, a `?` or a `#` before the `@` and before any `/`, and a start that is not exactly a scheme, two slashes and a character other than a slash. `https://user:pa?ss@example.com/`, `https://example.org?e=a@b.com` and `https:///host?e=a@b.com` are shown as `https://***`. `user:secret@host.example://dd`, where no slash follows the scheme colon, is shown as `//***`. The same holds for a word that a URL parser refuses as a scheme when a slash or a backslash follows its colon, as in `my_app:/user:secret@host`, and for an address that the parser refuses when a `?` or `#` comes before its last `@`, as in `https://user:pa/ss?secret@example.com`. A redirect to such an address is reported as "a different host that this report does not name". A `/` before the `@` makes it a path, and a relative reference such as `/a@b` or `docs/@name` is masked as before.
97
+ - Spaces, C0 control characters, Unicode spaces and invisible characters such as U+200B at either end of a value are removed before it is read, so a value that starts with U+2003 before `https:/user:secret@example.com` is read as `https:/user:secret@example.com` and shown as `https://***`.
97
98
  - Text before `://` that a URL parser does not accept as a scheme, such as `my_app://user:secret@host/p`, `1app://user:secret@host/p` or `ht tps://user:secret@host/p`, is masked from the text: everything up to the last `@` is shown as `***`.
98
99
 
99
100
  ## What it checks
@@ -103,7 +104,7 @@ In an error report the `target` is the address given on the command line. When i
103
104
  | # | Check | Failure | Warning |
104
105
  | --- | --- | --- | --- |
105
106
  | 1 | `/llms.txt` returns HTTP 200 | Non-200 response, rejected or excessive redirects | none |
106
- | 2 | Response is plain text | Body looks like an HTML page | The media type, read without its parameters, is neither `text/plain` nor `text/markdown` |
107
+ | 2 | Response is plain text | Body looks like an HTML page | The media type, read without its parameters, with only spaces, tabs and line breaks removed from its ends and only ASCII letters lowercased, is neither `text/plain` nor `text/markdown` |
107
108
  | 3 | First non-empty line is a Markdown H1, written `# Title` or as one line of text underlined with `=` | Missing H1, a title indented as a code block, or an H1 with no text | none |
108
109
  | 4 | Blockquote summary follows the title | none | Missing summary, a blockquote block in which no line has text after the `>`, or a blockquote after other text but before the first H2, named by its line |
109
110
  | 5 | H2 sections group the content | none | No H2 sections, no section with a Markdown link list, a heading between the title and the first H2, or a second H1 |
@@ -252,12 +253,12 @@ The strict type check found two inputs that could leave `undefined` in a check's
252
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.
253
254
 
254
255
  ```sh
255
- mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.8.0 --ignore-scripts && npm audit signatures
256
+ mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.8.1 --ignore-scripts && npm audit signatures
256
257
  ```
257
258
 
258
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.
259
260
 
260
- Tag `v0.8.0` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.8.0 --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.
261
+ Tag `v0.8.1` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.8.1 --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.
261
262
 
262
263
  ## Development
263
264
 
package/dist/src/index.js CHANGED
@@ -40,8 +40,16 @@ export function cut(s, n) {
40
40
  // When a parser and a reader would disagree about where the user information ends, only the scheme and "//***" are
41
41
  // shown, so no host is named either. The decision is made once, from the written text, at the top of the function.
42
42
  export function maskLocation(href, base, written) {
43
- // The characters a URL parser drops before it reads anything.
44
- const text = String(href).replace(/[\t\n\r]/g, "");
43
+ // The characters a URL parser drops before it reads anything: tab, CR and LF wherever they stand, and C0 controls
44
+ // and spaces at either end. Until 2026-11-22 only the first three went, so a leading space or control character hid
45
+ // a scheme from the ambiguity test below, and " https:/user:pw@@host" against a base printed the password in the
46
+ // resolved path (V4-3, outside fuzz run 2026-11-22).
47
+ // The same reading also removes, at either end, the invisible characters that a URL parser keeps: the Unicode
48
+ // 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
+ // and then https:/user:pw@host is read as the address it shows (L3 of the third independent check).
50
+ const edge = "[\\x00-\\x20\\s" + String.fromCharCode(0x85, 0x180e, 0x200b, 0xfffd) + "]+";
51
+ const parserInput = (t) => t.replace(/[\t\n\r]/g, "").replace(new RegExp("^" + edge + "|" + edge + "$", "g"), "");
52
+ const text = parserInput(String(href));
45
53
  // Where an authority starts in a text, read from the text and not from the parser: after a scheme and two slashes, the
46
54
  // scheme being whatever stands before "://" with no / \ ? or # in it. invalid is true when that "scheme" is not one.
47
55
  const shapeOf = (t) => {
@@ -71,7 +79,9 @@ export function maskLocation(href, base, written) {
71
79
  return false;
72
80
  const m = /^[a-z][a-z0-9+.-]*:/i.exec(t);
73
81
  const sep = t.indexOf("://");
74
- const lead = m ? m[0] : sep >= 0 && !/[\/\\?#]/.test(t.slice(0, sep)) ? t.slice(0, t.indexOf(":") + 1) : "";
82
+ // A word the URL parser refuses as a scheme, followed directly by a slash or a backslash, as in my_app:/user:pw@host,
83
+ // reads as a scheme to a person and as a relative path to the parser (L2 of the third independent check).
84
+ const lead = m ? m[0] : sep >= 0 && !/[\/\\?#]/.test(t.slice(0, sep)) ? t.slice(0, t.indexOf(":") + 1) : ((/^[^\/\\?#@:]+:(?=[\/\\])/.exec(t)) || [""])[0];
75
85
  if (lead.includes("@"))
76
86
  return true;
77
87
  if (lead === "" && !/^[\/\\]{2}/.test(t))
@@ -86,8 +96,11 @@ export function maskLocation(href, base, written) {
86
96
  return /[\\?#]/.test(t.slice(p + 2, slash >= 0 && slash < lastAt ? slash : lastAt));
87
97
  };
88
98
  if (written !== undefined) {
89
- const w = String(written).replace(/[\t\n\r]/g, "");
90
- if (ambiguous(w) || shapeOf(w).invalid)
99
+ const w = parserInput(String(written));
100
+ // A written form that lost invisible characters at its ends was resolved by the parser with them, so href is not the
101
+ // 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, "").replace(/^[\x00-\x20]+|[\x00-\x20]+$/g, "");
103
+ if (ambiguous(w) || shapeOf(w).invalid || (w !== parserOwn && w.includes("@")))
91
104
  return maskLocation(written, base);
92
105
  }
93
106
  if (ambiguous(text)) {
@@ -96,10 +109,94 @@ export function maskLocation(href, base, written) {
96
109
  return (scheme ? scheme[1] + ":" : "") + "//***";
97
110
  }
98
111
  const shape = shapeOf(text);
112
+ // The reading from the text alone. It is the answer when the URL parser finds no host, and for a text with no
113
+ // scheme-like start and no authority start (two leading slashes or backslashes) it is tried before the parser, below.
114
+ // masked records whether it hid user information.
115
+ let masked = false;
116
+ const fromText = () => {
117
+ let s = text;
118
+ const stop = s.search(/[?#]/);
119
+ // A ? or # before the last @ can still belong to the user information of a text that has no scheme-like start
120
+ // ("user_name:pa?ss@host"). When a colon and no slash stands before that ?, everything up to the last @ is shown as
121
+ // ***, and the cut at the ? or # applies to what follows it. A backslash is no slash here: in a text with no scheme a
122
+ // person reads a backslash between a Windows domain and a user name as part of the user name, and until 2026-11-22
123
+ // a backslash before the # showed the text up to it, the start of the password included (V4-1, outside fuzz run
124
+ // 2026-11-22). A scheme or an authority with a ? before the @ is ambiguous and has returned above.
125
+ if (stop >= 0 && stop >= shape.from) {
126
+ const lastAt = s.lastIndexOf("@");
127
+ if (lastAt > stop && shape.from - shape.start < 2 && s.slice(0, stop).includes(":") && !s.slice(shape.start, stop).includes("/")) {
128
+ const rest = s.slice(lastAt + 1);
129
+ const rs = rest.search(/[?#]/);
130
+ masked = true;
131
+ return s.slice(0, shape.from) + "***@" + (rs >= 0 ? rest.slice(0, rs) + (rest[rs] === "?" ? "?***" : "") : rest);
132
+ }
133
+ }
134
+ if (stop >= 0)
135
+ s = s.slice(0, stop) + (s[stop] === "?" ? "?***" : "");
136
+ const after = shapeOf(s);
137
+ const hasScheme = after.scheme;
138
+ const start = after.start;
139
+ const from = after.from;
140
+ // Without a scheme and two slashes there is normally no authority, and an @ is part of a
141
+ // path ("path@2x.png" stays unmasked below). But when an @ still appears before the first
142
+ // /, the text ahead of it reads as userinfo even when the parser here does not recognise it
143
+ // as a scheme (an underscore, a leading digit or space, a stray control character), so that
144
+ // shape is masked too instead of let through (VN1, round 3 Tek-542). With no slash at all
145
+ // the same holds when a ":" comes before the last @: "user_name:secret@example.com" is
146
+ // user:password and is masked, while "path@2x.png" has no ":" ahead of its @ and stays as
147
+ // given (outside review V13, D5-1: the slashless shape used to return early and print the
148
+ // password).
149
+ if (!hasScheme && from - start < 2) {
150
+ const firstSlash = s.indexOf("/");
151
+ const firstAt = s.indexOf("@");
152
+ if (firstAt < 0)
153
+ return s;
154
+ if (firstSlash < 0) {
155
+ if (!s.slice(0, s.lastIndexOf("@")).includes(":"))
156
+ return s;
157
+ }
158
+ else if (firstAt > firstSlash) {
159
+ return s;
160
+ }
161
+ }
162
+ // Nothing tells which @ of a refused target ends the user information, so everything up to the
163
+ // last one is shown as ***. The mask is visible on purpose: three review rounds on 2026-09-22
164
+ // measured every rule that guessed, and each one either returned a password that holds a slash
165
+ // or made the host vanish without a trace.
166
+ const at = s.lastIndexOf("@");
167
+ if (at < from)
168
+ return s;
169
+ masked = true;
170
+ return s.slice(0, from) + "***@" + s.slice(at + 1);
171
+ };
172
+ // A text with no scheme-like start and no authority start is a relative reference to a URL parser, and against a base
173
+ // it resolves into a path: "user_name:pw@host" became "https://<base host>/user_name:pw@host", and a redirect refused
174
+ // as one hop too many passes the request URL as that base (outside fuzz run 2026-11-22, the base form of V4-1). A
175
+ // person reads such a text as user information and a host, so when the reading from the text hides user
176
+ // information that answer stands with or without a base. A ? or # before the last @ with a colon between them hides
177
+ // user information that the parser reads as a query name or a fragment ("user?x:pw@host" against a base showed
178
+ // "x:pw@host" as the query name), so the cut form from the text is shown then too. A relative reference with no colon
179
+ // before its last @, such as "path@2x.png", "@scope/pkg" or "p?mail=a@b.com", is still resolved against the base
180
+ // below, as before.
181
+ const lastAtText = text.lastIndexOf("@");
182
+ if (!shape.scheme && shape.from - shape.start < 2 && lastAtText > 0 && text.slice(0, lastAtText).includes(":")) {
183
+ const shown = fromText();
184
+ const cut = text.search(/[?#]/);
185
+ const cutBeforeAt = cut >= 0 && cut < lastAtText;
186
+ // With a base the URL reading puts the text after a ? or # into a query or a fragment and masks it, while the text
187
+ // reading shows the text after the last @ as a host, so only *** is shown and neither reading shows the other's part
188
+ // (differential fuzz against 3.260.6).
189
+ if (masked)
190
+ return base !== undefined && cutBeforeAt ? "***" : shown;
191
+ if (cutBeforeAt && text.slice(cut, lastAtText).includes(":"))
192
+ return shown;
193
+ }
99
194
  let u = null;
100
195
  if (!shape.invalid) {
196
+ // The parser reads the same text as the reading above. Given href, it kept a leading U+00A0 or U+2003 and resolved
197
+ // "<U+00A0>https://user:pw@host/p" against a base as a relative path with the password in it (fifth check).
101
198
  try {
102
- u = new URL(href, base);
199
+ u = new URL(text, base);
103
200
  }
104
201
  catch {
105
202
  u = null;
@@ -127,54 +224,17 @@ export function maskLocation(href, base, written) {
127
224
  u.hash = "";
128
225
  return u.href;
129
226
  }
130
- let s = text;
131
- const stop = s.search(/[?#]/);
132
- // A ? or # before the last @ can still belong to the user information of a text that has no scheme-like start
133
- // ("user_name:pa?ss@host"). When a colon and no slash stands before that ?, everything up to the last @ is shown as ***,
134
- // and the cut at the ? or # applies to what follows it. A scheme or an authority with a ? before the @ is ambiguous and
135
- // has returned above.
136
- if (stop >= 0 && stop >= shape.from) {
137
- const lastAt = s.lastIndexOf("@");
138
- if (lastAt > stop && shape.from === shape.start && s.slice(0, stop).includes(":") && !/[\/\\]/.test(s.slice(shape.from, stop))) {
139
- const rest = s.slice(lastAt + 1);
140
- const rs = rest.search(/[?#]/);
141
- return s.slice(0, shape.from) + "***@" + (rs >= 0 ? rest.slice(0, rs) + (rest[rs] === "?" ? "?***" : "") : rest);
142
- }
143
- }
144
- if (stop >= 0)
145
- s = s.slice(0, stop) + (s[stop] === "?" ? "?***" : "");
146
- const after = shapeOf(s);
147
- const hasScheme = after.scheme;
148
- const start = after.start;
149
- const from = after.from;
150
- // Without a scheme and two slashes there is normally no authority, and an @ is part of a
151
- // path ("path@2x.png" stays unmasked below). But when an @ still appears before the first
152
- // /, the text ahead of it reads as userinfo even when the parser here does not recognise it
153
- // as a scheme (an underscore, a leading digit or space, a stray control character), so that
154
- // shape is masked too instead of let through (VN1, round 3 Tek-542). With no slash at all
155
- // the same holds when a ":" comes before the last @: "user_name:secret@example.com" is
156
- // user:password and is masked, while "path@2x.png" has no ":" ahead of its @ and stays as
157
- // given (outside review V13, D5-1: the slashless shape used to return early and print the
158
- // password).
159
- if (!hasScheme && from - start < 2) {
160
- const firstSlash = s.indexOf("/");
161
- const firstAt = s.indexOf("@");
162
- if (firstAt < 0)
163
- return s;
164
- if (firstSlash < 0) {
165
- if (!s.slice(0, s.lastIndexOf("@")).includes(":"))
166
- return s;
167
- }
168
- else if (firstAt > firstSlash) {
169
- return s;
170
- }
227
+ // A scheme and an authority start that the URL parser refuses, as with the port "pa" in https://user:pa/ss?pw@host,
228
+ // and a ? or # before the last @: no parse tells where the user information ends, and the cut at the ? showed part
229
+ // of the password, so only the scheme is shown (fourth independent check). A refused target with no ? or # before
230
+ // its last @ keeps the reading below, everything up to the last @ shown as ***.
231
+ const qAt = text.slice(shape.from).search(/[?#]/);
232
+ if (!shape.invalid && shape.from - shape.start >= 2 && qAt >= 0 && text.lastIndexOf("@") > shape.from + qAt) {
233
+ const sc = /^[a-z][a-z0-9+.-]*:/i.exec(text);
234
+ if (sc)
235
+ return sc[0] + "//***";
171
236
  }
172
- // Nothing tells which @ of a refused target ends the user information, so everything up to the
173
- // last one is shown as ***. The mask is visible on purpose: three review rounds on 2026-09-22
174
- // measured every rule that guessed, and each one either returned a password that holds a slash
175
- // or made the host vanish without a trace.
176
- const at = s.lastIndexOf("@");
177
- return at < from ? s : s.slice(0, from) + "***@" + s.slice(at + 1);
237
+ return fromText();
178
238
  }
179
239
  // Unicode bidi controls (U+202A to U+202E, U+2066 to U+2069) have no place in a check's
180
240
  // detail: text quoted from the fetched file could otherwise read in a different order here
@@ -1670,7 +1730,10 @@ export function validateLlmsTxt(f) {
1670
1730
  // CR-only and CRLF line endings become LF here (Tek-560): a file written with bare CR was one
1671
1731
  // line for the old split and read as a title with the whole document in it.
1672
1732
  const text = (f.text.charCodeAt(0) === 0xFEFF ? f.text.slice(1) : f.text).replace(/\r\n?/g, "\n");
1673
- const ct = (f.contentType || "").toLowerCase();
1733
+ // ASCII lower case and HTTP white space only (CT-1, outside fuzz run 2026-11-22). toLowerCase() turned the Kelvin sign
1734
+ // U+212A in "text/mar<U+212A>down" into a k, and trim() removed a leading no-break space, which HTTP carries as an
1735
+ // obs-text byte, so a media type that a MIME type parser refuses passed as text/plain or text/markdown.
1736
+ const ct = (f.contentType || "").replace(/[A-Z]+/g, (c) => c.toLowerCase());
1674
1737
  const looksHtml = /^\s*(<!doctype|<html|<head|<body)/i.test(text);
1675
1738
  if (looksHtml) {
1676
1739
  add("content-type", "fail", "Response is plain text", "the body looks like an HTML page, not an llms.txt file");
@@ -1678,7 +1741,7 @@ export function validateLlmsTxt(f) {
1678
1741
  }
1679
1742
  // The media type is compared whole, without its parameters. A substring test passed
1680
1743
  // application/x-text/plain and text/markdownish until 2026-09-27 (Tek-496).
1681
- const mediaType = ct.split(";")[0].trim();
1744
+ const mediaType = ct.split(";")[0].replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
1682
1745
  if (mediaType === "text/plain" || mediaType === "text/markdown") {
1683
1746
  add("content-type", "pass", "Response is plain text", mediaType);
1684
1747
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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",