turva-llms-txt-validator 0.8.2 → 0.8.3

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
@@ -82,16 +82,16 @@ The two discovery checks return `pass` or `info`. They never change the summary
82
82
  npx --yes turva-llms-txt-validator example.com --json --strict
83
83
  ```
84
84
 
85
- Completed validation returns `{ target, summary, checks }`, where `target` is `https://<host>/llms.txt`. Each check contains `{ id, status, label, detail }`. Read `id` and `status` in a script, because the wording of `detail` can change between versions. The `input-path` check, which reports a path given with the domain and then ignored, also carries `value`, that path cut to 120 characters.
85
+ Completed validation returns `{ target, summary, checks }`, where `target` is `https://<host>/llms.txt`. Each check contains `{ id, status, label, detail }`. Read `id` and `status` in a script, because the wording of `detail` can change between versions. The `input-path` check, which reports a path given with the domain and then ignored, also carries `value`, that path cut to 120 characters. When the address holds an `@` and its masked form does not show that path, the value is `/***`. That happens when a URL parser put user information into the path, as with the backslash in `https://corp.example\erik:secret@host.example`.
86
86
 
87
87
  The validator removes C0 and C1 control characters, bidirectional controls and invisible characters from the `detail` text, which can quote the checked site. The invisible characters are chosen by Unicode class, not from a list: every format character, which is General_Category Cf, every Default_Ignorable_Code_Point and the line and paragraph separators U+2028 and U+2029. That covers the zero-width characters, the left-to-right and right-to-left marks, the Arabic letter mark, the word joiner and the invisible math operators, the soft hyphen, the byte-order mark, the variation selectors, the combining grapheme joiner, the Hangul fillers and the tag characters U+E0000 to U+E007F. Spaces stay: the no-break space and U+2000 to U+200A. The zero-width non-joiner and joiner go too, so a quoted Persian, Malayalam or Devanagari word loses its joining marks and reads without them. The Arabic number signs U+0600 to U+0605 go as well. Until 0.8.0 only the bidi controls and the C0 and C1 controls were removed, and the invisible characters stayed in the text and in the JSON. An emoji sequence in quoted text loses its zero-width joiners and its variation selector: a family emoji reads as its members side by side, a heart written with U+FE0F shows in text style, a keycap sequence loses the selector, and a tag flag shows as its black flag. The emoji themselves, skin tone modifiers, regional indicators and combining marks stay.
88
88
 
89
- With `--json`, an invalid domain or a failed fetch returns `{ "error": "...", "target": "..." }` and exits with code `2`. A network error adds `code`, such as `EAI_AGAIN`. An unknown option, a second domain and a missing domain return `{ "error": "..." }` only, with no target, and also exit with code `2`.
89
+ With `--json`, an invalid domain or a failed fetch returns `{ "error": "...", "target": "..." }` and exits with code `2`. A network error adds `code`, such as `EAI_AGAIN`. An unknown option, a second domain and a missing domain return `{ "error": "..." }` only, with no target, and also exit with code `2`. An unknown option is named by its dashes and the letters, digits and dashes after them, and the rest of the argument is not shown, so a target typed with a leading dash, as in `-u:secret@example.com`, gives `unknown option "-u" (the rest of the argument is not shown)`.
90
90
 
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 `@` 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.
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. When the validator follows such a redirect, the address it reached is shown as its scheme, its host and `/***`, as in `https://example.com/***`, and so is an address reached after it while its `Location` keeps part of the earlier path or query. An address whose `Location` keeps none of it, such as an absolute address or a path from the root, is shown as usual. 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
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
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://***`.
@@ -230,7 +230,7 @@ The default validation requests two documents: `https://<host>/llms.txt` and `ht
230
230
  - Timeout: eight seconds per document, shared across its redirect chain.
231
231
  - Read limit: 256 KiB, which is 262,144 bytes, per response by default. A file cut there gets the size note "over 256 KiB, read truncated". A library caller can change the limit, see the options above.
232
232
  - Redirects: up to four hops, over HTTPS, to the same host or its `www`/apex equivalent. Off-site redirects, embedded credentials and unsupported ports are rejected. A redirect target is reported with its credentials and fragment removed and its query values masked, whether the redirect was followed or rejected.
233
- - Host checks: IP literals, bracketed IPv6 addresses, localhost and the internal-use TLDs `localdomain`, `local`, `internal`, `home`, `lan`, `corp`, `test`, `invalid`, `arpa` and `onion` are rejected before a request is sent. An address that holds `@`, `?` or `#` is not repeated in the error message, because it can carry a user name, a password or a query value. One trailing dot on the host you give, as in `example.com.`, is removed first. Redirect targets are checked too, and one trailing dot on a redirect target is removed the same way.
233
+ - Host checks: IP literals, bracketed IPv6 addresses, localhost and the internal-use TLDs `localdomain`, `local`, `internal`, `home`, `lan`, `corp`, `test`, `invalid`, `arpa` and `onion` are rejected before a request is sent. An address that holds `@`, `?` or `#` is not repeated in the error message, because it can carry a user name, a password or a query value. The message names the host that a URL parser reads from such an address only when that host is the text right after the last `@`, or when the address holds no `@`. So `//user?@example.com`, where the parser reads the user name as the host, names no host. One trailing dot on the host you give, as in `example.com.`, is removed first. Redirect targets are checked too, and one trailing dot on a redirect target is removed the same way.
234
234
 
235
235
  **DNS resolution is not checked for private addresses.** A syntactically public domain can resolve to a private IP, so if you expose this package through a service that accepts untrusted domains, enforce private-address restrictions at the network layer. Local and CI runs use their own network policy. The hosted validator runs on the Cloudflare edge.
236
236
 
@@ -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.2 --ignore-scripts && npm audit signatures
256
+ mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.8.3 --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.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.
261
+ Tag `v0.8.3` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.8.3 --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/bin/cli.js CHANGED
@@ -48,8 +48,13 @@ if (flags.includes("--version") || flags.includes("-V")) {
48
48
  process.exit(0);
49
49
  }
50
50
  const unknown = flags.find((f) => !KNOWN.has(f));
51
- if (unknown)
52
- fail("unknown option " + JSON.stringify(stripControls(unknown).slice(0, 40)));
51
+ // Only the name of an unknown option is repeated: the dashes and the letters, digits and dashes after them. A target
52
+ // typed with a leading dash, as in -u:password@example.com, is read as an option, and up to 0.8.2 its first 40
53
+ // characters, user information included, were repeated in the error (n9, independent rerun 2026-11-22).
54
+ if (unknown) {
55
+ const name = /^-+[A-Za-z0-9-]*/.exec(unknown)[0].slice(0, 40);
56
+ fail("unknown option " + JSON.stringify(name) + (name === unknown ? "" : " (the rest of the argument is not shown)"));
57
+ }
53
58
  if (targets.length === 0 || targets[0].trim() === "")
54
59
  fail("no domain or URL given");
55
60
  if (targets.length > 1)
@@ -28,6 +28,7 @@ export type FetchedLlmsTxt = {
28
28
  truncated: boolean;
29
29
  redirectedFrom: string | null;
30
30
  finalUrl: string;
31
+ shownFinalUrl?: string;
31
32
  };
32
33
  export type FetchRedirect = {
33
34
  redirect: true;
package/dist/src/index.js CHANGED
@@ -341,7 +341,22 @@ export function enteredPath(raw) {
341
341
  return "";
342
342
  }
343
343
  const path = u.pathname;
344
- return path === "/" || path === "" || path === "/llms.txt" ? "" : path;
344
+ if (path === "/" || path === "" || path === "/llms.txt")
345
+ return "";
346
+ // A typed address whose user information the parser moved into the path, as in
347
+ // https://corp.example\erik:password@host.example, read as host corp.example and path
348
+ // /erik:password@host.example, repeated the password in this value (n7, independent rerun
349
+ // 2026-11-22). The path is shown only when maskLocation shows it for the whole typed address.
350
+ return s.includes("@") && !maskLocation(s).includes(path) ? "/***" : path;
351
+ }
352
+ // The host a refused typed address is named by in an error. An address with an @, a ? or a # is named by the host the
353
+ // parser reads from it, and only when that host is the text right after the last @, or the text has no @: with a ? or #
354
+ // before the @ the parser reads the user name as the host, and //user?@example.com named "user" (n8, independent
355
+ // rerun 2026-11-22). Mirrors worker.ts validatorEcho().
356
+ function typedHostEcho(raw) {
357
+ const host = normalizeHostInput(raw) || "";
358
+ const at = raw.lastIndexOf("@");
359
+ return host && (at < 0 || raw.slice(at + 1).toLowerCase().startsWith(host)) ? host : "";
345
360
  }
346
361
  export function isValidPublicHost(host) {
347
362
  if (!host || host.length > 253)
@@ -421,6 +436,7 @@ export async function fetchLlmsTxt(host, opts = {}) {
421
436
  throw new Error("the request address does not keep the host that was checked");
422
437
  }
423
438
  let redirectedFrom = null;
439
+ let hidden = false;
424
440
  // One budget for the whole redirect chain, not one per hop. Mirrors the hosted validator
425
441
  // (turva.dev/llms-txt-validator), which is canonical: with five hops a per-hop signal made
426
442
  // the caller's timeout five times longer than the value it passed in.
@@ -444,14 +460,15 @@ export async function fetchLlmsTxt(host, opts = {}) {
444
460
  if (!loc)
445
461
  return { redirect: true, reason: "no-location", status: res.status, location: "" };
446
462
  if (hop >= 4)
447
- return { redirect: true, reason: "too-many", status: res.status, location: cut(maskLocation(loc, url), 120) };
463
+ return { redirect: true, reason: "too-many", status: res.status, location: cut(maskLocation(loc, hidden ? undefined : url), 120) };
448
464
  let next;
449
465
  try {
450
466
  next = new URL(loc, url);
451
467
  }
452
468
  catch {
453
- return { redirect: true, reason: "bad-location", status: res.status, location: cut(maskLocation(loc, url), 120) };
469
+ return { redirect: true, reason: "bad-location", status: res.status, location: cut(maskLocation(loc, hidden ? undefined : url), 120) };
454
470
  }
471
+ const parsedHref = next.href;
455
472
  // LV-22 (round S3, Tek-546): one trailing dot names the same host, as it does in the typed
456
473
  // address (normalizeHostInput), so a redirect to https://example.com./ is a same-site redirect.
457
474
  // A second dot still fails the host test below.
@@ -463,6 +480,24 @@ export async function fetchLlmsTxt(host, opts = {}) {
463
480
  return { redirect: true, reason: "unsafe-target", status: res.status, location: cut(maskLocation(next.href, undefined, loc), 120) };
464
481
  if (!twin)
465
482
  return { redirect: true, reason: "off-host", status: res.status, location: cut(maskLocation(next.href, undefined, loc), 120) };
483
+ // A followed Location that reads as user information, as user_name:password@example.com resolved into
484
+ // https://example.com/user_name:password@example.com, kept the password in the address the report showed (n1,
485
+ // independent rerun 2026-11-22). The Location is read as written, against the address it came from, as a refused
486
+ // one is. When that reading masks more than the parsed address shows, the chain is marked: every later address
487
+ // that keeps its path is resolved from this one, so the final address is shown as its scheme, its host and "/***", and a later
488
+ // refused Location is read without this address as its base.
489
+ // A later Location that keeps nothing of the marked address, such as an absolute address or a path from the root,
490
+ // clears the mark: it is resolved against the marked address and against the same origin with every path segment
491
+ // and the query replaced, at the same depth, and when both give the same address the path and the query of the
492
+ // marked address did not reach it. Bases one segment deep let ".." and "../x" clear the mark while the hidden
493
+ // segments stayed (F1 of the seventh check, 2026-11-22).
494
+ const inheritsBase = (() => { const u0 = new URL(url); let n = 0; const alt = u0.origin + u0.pathname.replace(/[^\/]+/g, () => "zz9q" + n++) + (u0.search ? "?zz9q" : ""); try {
495
+ return new URL(loc, url).href !== new URL(loc, alt).href;
496
+ }
497
+ catch {
498
+ return true;
499
+ } })();
500
+ hidden = maskLocation(loc, url) !== maskLocation(parsedHref) || maskLocation(next.href, undefined, loc) !== maskLocation(next.href) || (hidden && inheritsBase);
466
501
  if (!redirectedFrom)
467
502
  redirectedFrom = url;
468
503
  url = next.href;
@@ -501,7 +536,8 @@ export async function fetchLlmsTxt(host, opts = {}) {
501
536
  bytes,
502
537
  truncated,
503
538
  redirectedFrom,
504
- finalUrl: url
539
+ finalUrl: url,
540
+ ...(hidden ? { shownFinalUrl: "https://" + new URL(url).host + "/***" } : {})
505
541
  };
506
542
  }
507
543
  }
@@ -1746,7 +1782,9 @@ export function validateLlmsTxt(f) {
1746
1782
  // detail as sent. An input with redirectedFrom and no finalUrl, which fetchLlmsTxt never returns but a
1747
1783
  // caller of this function can pass, names the address it was redirected from alone instead of ending
1748
1784
  // in "to undefined" (Tek-668, NULL-2, mirrored from worker.ts).
1749
- add("http-status", "pass", "File exists at /llms.txt", f.redirectedFrom ? "HTTP 200, followed a redirect from " + maskLocation(f.redirectedFrom) + (f.finalUrl ? " to " + maskLocation(f.finalUrl) : "") : "HTTP 200");
1785
+ // shownFinalUrl, when fetchLlmsTxt set it, stands in for finalUrl (n1, independent rerun 2026-11-22).
1786
+ const shownFinal = f.shownFinalUrl !== undefined ? maskLocation(f.shownFinalUrl) : f.finalUrl ? maskLocation(f.finalUrl) : "";
1787
+ add("http-status", "pass", "File exists at /llms.txt", f.redirectedFrom ? "HTTP 200, followed a redirect from " + maskLocation(f.redirectedFrom) + (shownFinal ? " to " + shownFinal : "") : "HTTP 200");
1750
1788
  // A leading byte-order mark is stripped the same way the fetch path already strips it: the
1751
1789
  // TextDecoder used there removes a BOM by default, so the direct API took a different
1752
1790
  // document than the fetched one for the exact same bytes until this was measured (outside
@@ -3309,7 +3347,7 @@ export async function validateHost(input, opts = {}) {
3309
3347
  // its first 120 characters into stderr and the --json error (Tek-496). Such an entry is
3310
3348
  // named by the host the parser reads from it, or not at all, as the hosted form does.
3311
3349
  const raw = String(input ?? "");
3312
- const shown = /[@?#]/.test(raw) ? normalizeHostInput(raw) || "" : stripControls(cut(raw, 120));
3350
+ const shown = /[@?#]/.test(raw) ? typedHostEcho(raw) : stripControls(cut(raw, 120));
3313
3351
  throw new Error(shown ? "not a public domain name: " + shown : "not a public domain name");
3314
3352
  }
3315
3353
  // opts comes from the caller, and path and accept exist for this function's own
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
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",