Repository navigation
Commit 907dbdc
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
- core
- src/host
- test
- docs/subsystems
- patches/ds-bot
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
70 | 77 | | |
71 | 78 | | |
72 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
119 | 172 | | |
120 | 173 | | |
121 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
| 491 | + | |
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6418 | 6418 | | |
6419 | 6419 | | |
6420 | 6420 | | |
6421 | | - | |
| 6421 | + | |
6422 | 6422 | | |
6423 | 6423 | | |
6424 | 6424 | | |
| |||
6428 | 6428 | | |
6429 | 6429 | | |
6430 | 6430 | | |
6431 | | - | |
6432 | | - | |
6433 | | - | |
6434 | | - | |
6435 | | - | |
6436 | | - | |
6437 | | - | |
6438 | | - | |
6439 | | - | |
| 6431 | + | |
| 6432 | + | |
| 6433 | + | |
| 6434 | + | |
| 6435 | + | |
| 6436 | + | |
| 6437 | + | |
| 6438 | + | |
| 6439 | + | |
| 6440 | + | |
| 6441 | + | |
| 6442 | + | |
| 6443 | + | |
| 6444 | + | |
| 6445 | + | |
| 6446 | + | |
6440 | 6447 | | |
6441 | 6448 | | |
6442 | 6449 | | |
| |||
0 commit comments