Skip to content

Commit 907dbdc

Browse files
authored
host: the header-name credential scan is quadratic on long text and three more shapes stay unmasked (X_Token:, X-Token[], X-OAuth:) (#3313)
Fixes #3310 Owner: Dev-1 Reviewer: Birfy ## Review round `Verdict: INC` at `2d99db912259bba00c5ab561bf5a229e2cc8e797` (comment `7088893096`) — fixed in `0a124c6c0f62d6b0fb2304dc40054b9b8c9d4536`, both points: - **The value tail was capped.** `[^\s"',}][^"',}\n]{5,199}` stopped masking after 200 characters, so a 704-character value came back as `X-Token: [hidden]` plus 504 readable characters, while the base entry masked the whole value. The cap is gone: the value is read to the end of the field. A committed case pins a 704-character value to exactly `[hidden]`; red on `2d99db91` (`actual` `'X-Token: [hidden]A1A1…'` with 504 visible, `expected` `'X-Token: [hidden]'`), green after the fix. The floor stays `{5,}` — after the first character that is six — so the `X-Token: abc12` control (five characters, readable) is unchanged and still green; `{4,}` would have masked it. - **The comment said four segments.** The cost-test comment above the name pattern said "at most four segments" while the pattern and `core-host.md` say six; it says six now. `patches/ds-bot/0001` and `0007` are what `node scripts/ds-bot-patches.mjs generate` wrote, not hand-edited. ## Red first Both halves were measured and committed on live `main` (`9a48f5aa4bd49c8cae0d80fb4da3a74d02af0f99`) before the fix. **Cost**, `cleanText` over `'a-'.repeat(bytes / 2)`, standalone probe on that base: ``` 4096 B -> 23.4 ms 8192 B -> 85.3 ms 16384 B -> 342.5 ms 40960 B -> 2132.5 ms 81920 B -> 8782.2 ms ``` The committed case is a timing assertion, not a golden string: it measures every row and requires each under a second, so its own red run stopped at the first failing row — `40960 bytes took 2145 ms` — and the 80 KB row above is the probe's. `# tests 89 / # pass 85 / # fail 4` in that run. **Shapes.** These four are coverage gaps, not a regression: every one of them also leaks on the base, so the red run is the base proving it, and the fix adds cover rather than restoring it. ``` "X_Token: abcdef123456" -> "X_Token: abcdef123456" "X-Token[]: abcdef123456" -> "X-Token[]: abcdef123456" "X-OAuth: abcdef123456" -> "X-OAuth: abcdef123456" "X-Token: abc def" -> "X-Token: abc def" ``` The three committed shape tests failed on exactly those pairs (actual `'X_Token: abcdef123456'` against expected `'X_Token: [hidden]'`, and so on). ## What changed One entry in `CREDENTIALS` (`core/src/host/diagnostics.js`), three changes to it: - **The scan is bounded.** The name starts after a character that is not part of one (`(?<![a-z0-9])`, so a hyphen or underscore may precede it and `foo-X-Token:` still masks), and it carries at most six hyphen/underscore segments of at most 64 characters before the credential word. The old shape retried its whole name from every position; with the left anchor and the two caps a start costs a bounded amount and the scan is linear. The same 80 KB body now takes about 6 ms, and the committed case pins the bound by printing the five rows and requiring each under a second. - **Three shapes join the list.** A header name may be joined by an underscore (`X_Token:`) and may be an array key (`X-Token[]:`), and `oauth` is a credential word (`X-OAuth:`). A JSON key, a tab after the colon, `X-Auth: Bearer …` and `?X-Token=…` keep masking. - **The floor is on the value, not its first token.** The value is read as one piece up to the end of the field (a quote, comma, brace or newline ends it), so `X-Token: abc def` is masked whole while `X-Token: abc12` — five characters — stays readable. Nothing loosens. A standalone probe re-run on the fixed tree prints `MATRIX OK`: every header name masks — `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`, `X-Amz-Signature`, `X-Key`, `X-Signature`, `X-Sig`, `X-Hmac` and `X-Pass`, plus `passwd` — while `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count`, `key-name`, `assign`, `compass`, `bypass`, `status`, `author`, `Signature:` and `?limit=50` all come back unchanged. A bare `Signature:` stays readable on purpose — the documented accepted limit — and this PR does not change it. The comment above the entry, the `diagnostics` bullet in `docs/subsystems/core-host.md` and `changelog.d/3310.fixed.md` state the rule and the bound. `patches/ds-bot/0001` and `0007` are what `node scripts/ds-bot-patches.mjs generate` writes, not hand-edited; `client.js` is untouched (no client source changed). No UI face: this is the stored-text cleaner behind the report, the downloaded log and the system prompt. ## Verification at the tip Tip: `0a124c6c0f62d6b0fb2304dc40054b9b8c9d4536`, tree `21cfbba0785adc2454168d69bce739a12d505c8e`, base and merge-base `9a48f5aa4bd49c8cae0d80fb4da3a74d02af0f99`. Every reading below is at this tree; the local commit it was measured on is `0adef74df7e9736f435584c9fba2de03a4bd6357`, and the push path rebuilt the head from the same tree, so only the parent differs. Ran: - `cd core && node --import ./test/harness-resolve.mjs --test --test-timeout=120000 test/diagnostics.test.js` → 90/90, including `cleanText masks a long header value whole` (the 704-character case) and the `X-Token: abc12` control; the cost case prints `4096 B: 0.4 ms`, `8192 B: 0.6 ms`, `16384 B: 1.1 ms`, `40960 B: 2.9 ms`, `81920 B: 5.8 ms` - `TZ=UTC npm run verify` → exit 0: core 3441/3441 (its `npm test`; one more than the previous tip, the new case), plane 25/25, social 758/758, tree 157/157, timeline 175/175, workflow 544/544, project 151/151, `.github/scripts`+policy 735/735, interop 37/37, live-e2e 34/34; every suite `# fail 0` - oxlint in that run: core `Found 91 warnings and 0 errors` (the same count as `main`; this file adds none), plugin suites 0 errors - `node scripts/ds-bot-patches.mjs check` / `canonical` → `10 patches apply cleanly in order`, `core/ equals ds-bot/ + patches/ds-bot/`, `patches/ds-bot/ is what generate writes (generate is a no-op)` - `build-client.mjs --check` inside `verify` → green - `ARCH_DOCS_BASE=9a48f5aa4bd49c8cae0d80fb4da3a74d02af0f99 npm run arch-docs` (in `core/`) → `arch-docs: OK (6 changed file(s))` - `node .github/scripts/changelog.mjs check` → `1 fragment(s) in changelog.d/ are well formed` - `node .github/scripts/check-mojibake.mjs` → `ok — 0 occurrences of U+FFFD in 1785 text file(s)` Not run: - the smoke test (`src/host/` change: the diff is one regex entry in a pure text helper, no startup path, endpoint or state shape moved); say the word and I run `dev/bench.sh smoke` on a free port - the CI `package` job's pack check, typecheck and actionlint, which `npm run verify` does not run ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 3313, "claim": "Dev-1", "issue": 3310, "summary": "The diagnostics cleaner's header-name credential entry is bounded: the name starts after a non-name character and carries at most six segments of at most 64 characters, so the quadratic retry is gone and an 80 KB hyphenated body takes about 6 ms instead of 8.8 s. An underscore join, an array key and an oauth segment are masked too, and the six-character floor now sits on the whole value, so X-Token: abc def is masked whole while a five-character value stays readable. The ordinary names and a bare Signature: keep their text. Red-first tests pin the bound and all three shapes.", "files": ["core/src/host/diagnostics.js", "core/test/diagnostics.test.js", "docs/subsystems/core-host.md", "changelog.d/3310.fixed.md", "patches/ds-bot/0001-core-fixes.patch", "patches/ds-bot/0007-version-and-tooling.patch"], "checks": { "ran": "TZ=UTC npm run verify", "result": "green", "at": "0a124c6c0f62d6b0fb2304dc40054b9b8c9d4536" }, "next": "INC at 2d99db9 fixed in 0a124c6; ready for a new review at this tip" } ``` <!-- /flybot:checkpoint -->
1 parent 9a48f5a commit 907dbdc

6 files changed

Lines changed: 142 additions & 21 deletions

File tree

‎changelog.d/3310.fixed.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The diagnostics report and the downloaded log bound their credential scan again: the header-shaped entry added for `X-Pat`-style names retried its whole name from every position, so a hyphenated body cost the square of its length (8.8 s at 80 KB) and one long error body in a warning or a note could block the host. The name now starts after a character that is not part of it and carries at most six segments, so an 80 KB body takes under 2 ms. Three shapes that stayed readable are masked too — an underscore join (`X_Token:`), an array key (`X-Token[]:`) and an `oauth` segment (`X-OAuth:`) — and the six-character floor now applies to the whole value, so `X-Token: abc def` is masked as one piece while `X-Token: abc12` and the ordinary names (`X-Patch-Id`, `session-count`, `key-name`) keep their text ([#3310](https://github.com/ThinkFlowLab/FlyBot/issues/3310)).

‎core/src/host/diagnostics.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,22 @@ const CREDENTIALS = [
5858
// `sig` and `pass` count as a whole segment the way `pat` does there, so `assign`, `compass` and
5959
// `bypass` are ordinary names; `hmac` is not part of any ordinary word.
6060
[/(["']?(?:hmac|passwd|(?<![a-z0-9])(?:sig|pass)(?![a-z0-9]))["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
61-
// A header-shaped name is a hyphenated field name whose last segment is a credential word, so
62-
// `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`,
63-
// `X-Amz-Signature`, `X-Key` and `X-Signature` are masked the way `capabilities.js` masks a
64-
// stored capability body. The whole last segment has to be the credential word, so `X-Patch-Id`,
65-
// `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name` keep their text. A bare
66-
// `Signature:` stays readable on purpose: masking every name holding `signature`, `auth`,
67-
// `session` or `token` would eat `auth: failed to connect` and `session: expired at noon`,
68-
// which is the widening #3291 refused.
69-
[/(["']?(?:[a-z0-9]+-)+(?:key|token|auth|cookie|session|credential|signature|pat|sig|pass)["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
61+
// A header-shaped name is a hyphenated or underscored field name whose last segment is a
62+
// credential word, so `X-Pat`, `X-Github-Pat`, `X_Token`, `X-Token[]`, `X-Auth`, `X-Cookie`,
63+
// `X-Session`, `X-Credential`, `X-OAuth`, `X-Amz-Signature`, `X-Key` and `X-Signature` are masked
64+
// the way `capabilities.js` masks a stored capability body. The whole last segment has to be the
65+
// credential word, so `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name`
66+
// keep their text. A bare `Signature:` stays readable on purpose: masking every name holding
67+
// `signature`, `auth`, `session` or `token` would eat `auth: failed to connect` and
68+
// `session: expired at noon`, which is the widening #3291 refused.
69+
// #3310: the repeated segment group retried the whole name from every position, so on a
70+
// hyphenated body the scan was quadratic (4/8/16/40/80 KB took 23/85/343/2132/8782 ms). The name
71+
// now starts after a character that is not part of one and carries at most six segments of at
72+
// most 64 characters, so a start costs a bounded amount and the scan is linear. The value is read
73+
// as one piece up to the end of the field (a quote, comma, brace or newline ends it) and the
74+
// six-character floor is on the whole value, so a first token under six characters is masked too.
75+
// The value has no length cap: a cap left the tail of a long value readable in a report.
76+
[/(?<![a-z0-9])(["']?(?:[a-z0-9]{1,64}[-_]){1,6}(?:key|token|auth|cookie|session|credential|signature|pat|sig|pass|oauth)(?:\[\])?["']?\s*[:=]\s*["']?)[^\s"',}][^"',}\n]{5,}/gi, '$1[hidden]'],
7077
]
7178

7279
// A path under a home can be deeper than the bound is long (#2964): `~/.local/share/deepseek-harness/

‎core/test/diagnostics.test.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,59 @@ test('cleanText keeps ordinary hyphenated names and a bare Signature', () => {
116116
assert.equal(cleanText('X-Token: abc12', { home: '' }), 'X-Token: abc12')
117117
})
118118

119+
// #3310: the header-name entry started a name with a repeated segment group, so on a hyphenated
120+
// body it retried the whole name from every position and one `cleanText` call grew with the square
121+
// of the text: 4/8/16/40/80 KB took 23/85/343/2132/8782 ms on `9a48f5aa`, and the call sites take
122+
// whatever an error body carries. The name is anchored at a word boundary and carries at most six
123+
// segments, so the scan is linear; this case pins the bound and prints the table it measured.
124+
test('cleanText stays fast on a long hyphenated body', (t) => {
125+
for (const bytes of [4096, 8192, 16384, 40960, 81920]) {
126+
const text = 'a-'.repeat(bytes / 2)
127+
const started = performance.now()
128+
cleanText(text, { home: '' })
129+
const ms = performance.now() - started
130+
t.diagnostic(`${bytes} bytes: ${ms.toFixed(1)} ms`)
131+
assert.ok(ms < 1000, `${bytes} bytes took ${ms.toFixed(0)} ms`)
132+
}
133+
})
134+
135+
// #3310: an underscore joins a header name too, and an array key is still the same shape. The value
136+
// side does not change: a JSON key, a tab, a bearer value and a `?X-Token=` parameter keep masking.
137+
test('cleanText hides an underscore or array header name', () => {
138+
assert.equal(cleanText('X_Token: abcdef123456', { home: '' }), 'X_Token: [hidden]')
139+
assert.equal(cleanText('X-Token[]: abcdef123456', { home: '' }), 'X-Token[]: [hidden]')
140+
assert.equal(cleanText('{"X_Token":"abcdef123456"}', { home: '' }), '{"X_Token":"[hidden]"}')
141+
assert.equal(cleanText('X-Token[]:\tabcdef123456', { home: '' }), 'X-Token[]:\t[hidden]')
142+
assert.equal(cleanText('X-Auth: Bearer abcdef123456', { home: '' }), 'X-Auth: [hidden]')
143+
assert.equal(cleanText('?X-Token=abcdef123456', { home: '' }), '?X-Token=[hidden]')
144+
})
145+
146+
// #3310: `oauth` names a credential too, and a name segment like `X-OAuth` is the header shape.
147+
test('cleanText hides an oauth header', () => {
148+
assert.equal(cleanText('X-OAuth: abcdef123456', { home: '' }), 'X-OAuth: [hidden]')
149+
assert.equal(cleanText('{"X-OAuth":"abcdef123456"}', { home: '' }), '{"X-OAuth":"[hidden]"}')
150+
})
151+
152+
// #3310: the six-character floor was applied to the first whitespace-delimited token, so a value
153+
// whose first word was short escaped whole. The floor is on the value, which is masked as one piece.
154+
test('cleanText masks the whole header value when its first token is short', () => {
155+
assert.equal(cleanText('X-Token: abc def', { home: '' }), 'X-Token: [hidden]')
156+
assert.equal(cleanText('X-Token: abc def ghi', { home: '' }), 'X-Token: [hidden]')
157+
// Five characters in total stay readable, and an ordinary hyphenated name stays readable.
158+
assert.equal(cleanText('X-Token: abc12', { home: '' }), 'X-Token: abc12')
159+
assert.equal(cleanText('X-Patch-Id: abc def', { home: '' }), 'X-Patch-Id: abc def')
160+
})
161+
162+
// #3310 review: the value tail was capped at 199 characters after its first, so a long value kept
163+
// its head masked and left the rest readable — 704 characters came back as 200 masked and 504
164+
// visible. Base masked the whole value, so a cap here would widen what a log line prints. The value
165+
// is read to the end of the field with no length bound.
166+
test('cleanText masks a long header value whole', () => {
167+
const value = 'A1'.repeat(352)
168+
assert.equal(value.length, 704)
169+
assert.equal(cleanText(`X-Token: ${value}`, { home: '' }), 'X-Token: [hidden]')
170+
})
171+
119172
function host(home, extra = {}) {
120173
const warnings = []
121174
const disposers = []

‎docs/subsystems/core-host.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ has lines (#2790, `core/test/room-read-floor-clamp.test.js`).
488488
### Diagnostics
489489

490490
- The report bounds a sentence after it abbreviates it ([#2936](https://github.com/ThinkFlowLab/FlyBot/issues/2936)): `cleanText` turns every home folder into `~` first — the process's and this host's own, which can sit outside it (#2944) — and applies its `max` only then — the Read-only row's 200, a browser log line's 500 and its code's 40 — and a bound that fires backs off to the last whole word and closes with one `…`, so a long home can no longer leave a row that stops mid-word with no mark and the mark cannot double.
491-
- The report and the downloaded log mask credentials by name, before the bound ([#3291](https://github.com/ThinkFlowLab/FlyBot/issues/3291)): `cleanText`'s `CREDENTIALS` list redacts the value written after `X-Sig`, `X-Hmac`, `X-Pass`, `x-api-key`, `Authorization`, `api_key`, `password` or `secret`, so a log line or report row that echoes one of them shows `[hidden]` instead of the value — the three names `sig`, `hmac` and `pass` were in `capabilities.js`'s mask of a stored capability body and missing from this list. `sig` and `pass` count as a whole segment the way `pat` does there, so `assign`, `compass` and `bypass` are ordinary names that keep their text, and `hmac` is not part of any ordinary word. A quote may stand on either side of the name and of the value, so a JSON body (`{"sig":"…"}`) is masked the same way, and a value under six characters is left alone rather than eating the words around it. A header-shaped name — a hyphenated field name whose last segment is the credential word — is masked too, so a log line or report row echoing `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`, `X-Amz-Signature`, `X-Key` or `X-Signature` shows `[hidden]`, and `passwd` joins the bare names; `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name` keep their text, because the whole last segment has to be the credential word. A bare `Signature:` stays readable, and that is the known limit of this list: masking every name that carries `signature`, `auth`, `session` or `token` would also eat prose such as `auth: failed to connect` and `session: expired at noon`, which is the widening [#3291](https://github.com/ThinkFlowLab/FlyBot/issues/3291) refused.
491+
- The report and the downloaded log mask credentials by name, before the bound ([#3291](https://github.com/ThinkFlowLab/FlyBot/issues/3291)): `cleanText`'s `CREDENTIALS` list redacts the value written after `X-Sig`, `X-Hmac`, `X-Pass`, `x-api-key`, `Authorization`, `api_key`, `password` or `secret`, so a log line or report row that echoes one of them shows `[hidden]` instead of the value — the three names `sig`, `hmac` and `pass` were in `capabilities.js`'s mask of a stored capability body and missing from this list. `sig` and `pass` count as a whole segment the way `pat` does there, so `assign`, `compass` and `bypass` are ordinary names that keep their text, and `hmac` is not part of any ordinary word. A quote may stand on either side of the name and of the value, so a JSON body (`{"sig":"…"}`) is masked the same way, and a value under six characters is left alone rather than eating the words around it. A header-shaped name — a hyphenated field name whose last segment is the credential word — is masked too, so a log line or report row echoing `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`, `X-Amz-Signature`, `X-Key` or `X-Signature` shows `[hidden]`, and `passwd` joins the bare names; `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name` keep their text, because the whole last segment has to be the credential word. A bare `Signature:` stays readable, and that is the known limit of this list: masking every name that carries `signature`, `auth`, `session` or `token` would also eat prose such as `auth: failed to connect` and `session: expired at noon`, which is the widening [#3291](https://github.com/ThinkFlowLab/FlyBot/issues/3291) refused. Since [#3310](https://github.com/ThinkFlowLab/FlyBot/issues/3310) an underscore joins a header name too (`X_Token`), an array key (`X-Token[]`) and an `oauth` segment (`X-OAuth`) count, and the six-character floor is on the whole value rather than its first token, so `X-Token: abc def` is masked as one piece; the name starts after a character that is not part of one and carries at most six segments of at most 64 characters, so the scan is linear rather than quadratic — a hyphenated body that took 8.8 s at 80 KB takes under 2 ms, and a case pins the bound.
492492
- The report abbreviates **every** home it prints, not only the process's ([#2947](https://github.com/ThinkFlowLab/FlyBot/issues/2947)): `install` keeps `reportHomes = [homedir(), home]` and `show` hands that pair to `cleanText`, whose `homeFolders` drops duplicates and replaces the longest folder first, so a path under this host's own home reads `~` whether that home sits inside or outside the OS home, and the `Read-only` row, the entry lines the report prints, `state file:` / `journal file:`, the journal and log-state sentences and the browser fields all go through `show`. The line the host writes to `logs/diagnostics.jsonl` and to stderr still goes through `clean`, which knows the process's home alone; the report re-renders an entry through `show` when it prints it. The abbreviation still happens before `cut`, so the row's 200 measures the shortened text. A nested home is not collapsed into the outer one ([#2956](https://github.com/ThinkFlowLab/FlyBot/issues/2956)): `homeFolders` drops a folder that sits inside another listed folder, so the outer home takes the `~` and `/home/me/.dsh/bot/state.json` prints `~/.dsh/bot/state.json`, which keeps it apart from `/home/me/state.json` (`~/state.json`) — one string never names two files. A home deep enough that its own tail would fill the bound gives up its middle before the bound is applied ([#2964](https://github.com/ThinkFlowLab/FlyBot/issues/2964)): the scope stays and the last level stays (`~/.local/share/deepseek-harness/teams/flybot-dev` → `~/.local/…/flybot-dev`), so both reload sentences keep their tail — `… fix or move the file and reload.` and `… close the other one and reload.` — and the shortening fires only on text over its own bound, so a short home still prints byte for byte as it did.
493493
- The report also says which feature plugin the owner switched off ([#2940](https://github.com/ThinkFlowLab/FlyBot/issues/2940)): a `Plugins` row after `Read-only` names every id whose switch is off, in `FEATURE_PLUGINS` order and joined by `, `, ending ` off` (`project off`, `timeline, project off`), and appends ` (restart pending)` while one of those switches no longer answers the value this start read (`pluginSwitches` / `pluginSwitchesPending(rt.state, pluginSwitchesAtStart(statePath))`, the pair Settings → Plugins answers `pendingRestart` with). The row carries switch values only — never `loaded` or `installed`, which are other facts ([#2868](https://github.com/ThinkFlowLab/FlyBot/issues/2868)) — and a host whose switches are all on, or whose state has no `flybot.plugins` at all, draws no row: that report is byte for byte the one before this change.
494494
- Host diagnostics never depend on `ctx.logger`: DSH may export no logger, and a test or plugin-local host may carry one without `warn`. `rt.warn` still writes stderr and the diagnostics log in that case (`src/host/diagnostics.js`). Plugins reach the same log through `flybot.warn` (#68); see [plugin-runtime](plugin-runtime.md).

‎patches/ds-bot/0001-core-fixes.patch‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6418,7 +6418,7 @@ diff --git a/src/host/diagnostics.js b/src/host/diagnostics.js
64186418
// Shapes of credentials that are not saved keys: provider keys, bearer tokens, and
64196419
// token or key parameters in addresses (the Web login address carries one).
64206420
const CREDENTIALS = [
6421-
@@ -34,29 +34,84 @@ const CREDENTIALS = [
6421+
@@ -34,29 +34,91 @@ const CREDENTIALS = [
64226422
[/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=*-]{8,}/gi, '$1 [hidden]'],
64236423
[/([?&#](?:token|access_token|api_key|apikey|key|secret|password)=)[^&\s"']+/gi, '$1[hidden]'],
64246424
[/(["']?(?:api[_-]?key|authorization|x-api-key|password|secret)["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
@@ -6428,15 +6428,22 @@ diff --git a/src/host/diagnostics.js b/src/host/diagnostics.js
64286428
+ // `sig` and `pass` count as a whole segment the way `pat` does there, so `assign`, `compass` and
64296429
+ // `bypass` are ordinary names; `hmac` is not part of any ordinary word.
64306430
+ [/(["']?(?:hmac|passwd|(?<![a-z0-9])(?:sig|pass)(?![a-z0-9]))["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
6431-
+ // A header-shaped name is a hyphenated field name whose last segment is a credential word, so
6432-
+ // `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`,
6433-
+ // `X-Amz-Signature`, `X-Key` and `X-Signature` are masked the way `capabilities.js` masks a
6434-
+ // stored capability body. The whole last segment has to be the credential word, so `X-Patch-Id`,
6435-
+ // `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name` keep their text. A bare
6436-
+ // `Signature:` stays readable on purpose: masking every name holding `signature`, `auth`,
6437-
+ // `session` or `token` would eat `auth: failed to connect` and `session: expired at noon`,
6438-
+ // which is the widening #3291 refused.
6439-
+ [/(["']?(?:[a-z0-9]+-)+(?:key|token|auth|cookie|session|credential|signature|pat|sig|pass)["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
6431+
+ // A header-shaped name is a hyphenated or underscored field name whose last segment is a
6432+
+ // credential word, so `X-Pat`, `X-Github-Pat`, `X_Token`, `X-Token[]`, `X-Auth`, `X-Cookie`,
6433+
+ // `X-Session`, `X-Credential`, `X-OAuth`, `X-Amz-Signature`, `X-Key` and `X-Signature` are masked
6434+
+ // the way `capabilities.js` masks a stored capability body. The whole last segment has to be the
6435+
+ // credential word, so `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name`
6436+
+ // keep their text. A bare `Signature:` stays readable on purpose: masking every name holding
6437+
+ // `signature`, `auth`, `session` or `token` would eat `auth: failed to connect` and
6438+
+ // `session: expired at noon`, which is the widening #3291 refused.
6439+
+ // #3310: the repeated segment group retried the whole name from every position, so on a
6440+
+ // hyphenated body the scan was quadratic (4/8/16/40/80 KB took 23/85/343/2132/8782 ms). The name
6441+
+ // now starts after a character that is not part of one and carries at most six segments of at
6442+
+ // most 64 characters, so a start costs a bounded amount and the scan is linear. The value is read
6443+
+ // as one piece up to the end of the field (a quote, comma, brace or newline ends it) and the
6444+
+ // six-character floor is on the whole value, so a first token under six characters is masked too.
6445+
+ // The value has no length cap: a cap left the tail of a long value readable in a report.
6446+
+ [/(?<![a-z0-9])(["']?(?:[a-z0-9]{1,64}[-_]){1,6}(?:key|token|auth|cookie|session|credential|signature|pat|sig|pass|oauth)(?:\[\])?["']?\s*[:=]\s*["']?)[^\s"',}][^"',}\n]{5,}/gi, '$1[hidden]'],
64406447
]
64416448

64426449
-export function cleanText(text, { redact = value => value, home = homedir() } = {}) {

0 commit comments

Comments
 (0)