diff --git a/changelog.d/3310.fixed.md b/changelog.d/3310.fixed.md new file mode 100644 index 000000000..8fbdacb55 --- /dev/null +++ b/changelog.d/3310.fixed.md @@ -0,0 +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)). diff --git a/core/src/host/diagnostics.js b/core/src/host/diagnostics.js index c16905fb2..79a937344 100644 --- a/core/src/host/diagnostics.js +++ b/core/src/host/diagnostics.js @@ -58,15 +58,22 @@ const CREDENTIALS = [ // `sig` and `pass` count as a whole segment the way `pat` does there, so `assign`, `compass` and // `bypass` are ordinary names; `hmac` is not part of any ordinary word. [/(["']?(?:hmac|passwd|(? { assert.equal(cleanText('X-Token: abc12', { home: '' }), 'X-Token: abc12') }) +// #3310: the header-name entry started a name with a repeated segment group, so on a hyphenated +// body it retried the whole name from every position and one `cleanText` call grew with the square +// of the text: 4/8/16/40/80 KB took 23/85/343/2132/8782 ms on `9a48f5aa`, and the call sites take +// whatever an error body carries. The name is anchored at a word boundary and carries at most six +// segments, so the scan is linear; this case pins the bound and prints the table it measured. +test('cleanText stays fast on a long hyphenated body', (t) => { + for (const bytes of [4096, 8192, 16384, 40960, 81920]) { + const text = 'a-'.repeat(bytes / 2) + const started = performance.now() + cleanText(text, { home: '' }) + const ms = performance.now() - started + t.diagnostic(`${bytes} bytes: ${ms.toFixed(1)} ms`) + assert.ok(ms < 1000, `${bytes} bytes took ${ms.toFixed(0)} ms`) + } +}) + +// #3310: an underscore joins a header name too, and an array key is still the same shape. The value +// side does not change: a JSON key, a tab, a bearer value and a `?X-Token=` parameter keep masking. +test('cleanText hides an underscore or array header name', () => { + assert.equal(cleanText('X_Token: abcdef123456', { home: '' }), 'X_Token: [hidden]') + assert.equal(cleanText('X-Token[]: abcdef123456', { home: '' }), 'X-Token[]: [hidden]') + assert.equal(cleanText('{"X_Token":"abcdef123456"}', { home: '' }), '{"X_Token":"[hidden]"}') + assert.equal(cleanText('X-Token[]:\tabcdef123456', { home: '' }), 'X-Token[]:\t[hidden]') + assert.equal(cleanText('X-Auth: Bearer abcdef123456', { home: '' }), 'X-Auth: [hidden]') + assert.equal(cleanText('?X-Token=abcdef123456', { home: '' }), '?X-Token=[hidden]') +}) + +// #3310: `oauth` names a credential too, and a name segment like `X-OAuth` is the header shape. +test('cleanText hides an oauth header', () => { + assert.equal(cleanText('X-OAuth: abcdef123456', { home: '' }), 'X-OAuth: [hidden]') + assert.equal(cleanText('{"X-OAuth":"abcdef123456"}', { home: '' }), '{"X-OAuth":"[hidden]"}') +}) + +// #3310: the six-character floor was applied to the first whitespace-delimited token, so a value +// whose first word was short escaped whole. The floor is on the value, which is masked as one piece. +test('cleanText masks the whole header value when its first token is short', () => { + assert.equal(cleanText('X-Token: abc def', { home: '' }), 'X-Token: [hidden]') + assert.equal(cleanText('X-Token: abc def ghi', { home: '' }), 'X-Token: [hidden]') + // Five characters in total stay readable, and an ordinary hyphenated name stays readable. + assert.equal(cleanText('X-Token: abc12', { home: '' }), 'X-Token: abc12') + assert.equal(cleanText('X-Patch-Id: abc def', { home: '' }), 'X-Patch-Id: abc def') +}) + +// #3310 review: the value tail was capped at 199 characters after its first, so a long value kept +// its head masked and left the rest readable — 704 characters came back as 200 masked and 504 +// visible. Base masked the whole value, so a cap here would widen what a log line prints. The value +// is read to the end of the field with no length bound. +test('cleanText masks a long header value whole', () => { + const value = 'A1'.repeat(352) + assert.equal(value.length, 704) + assert.equal(cleanText(`X-Token: ${value}`, { home: '' }), 'X-Token: [hidden]') +}) + function host(home, extra = {}) { const warnings = [] const disposers = [] diff --git a/docs/subsystems/core-host.md b/docs/subsystems/core-host.md index 7c7a15ff0..1b50dbfae 100644 --- a/docs/subsystems/core-host.md +++ b/docs/subsystems/core-host.md @@ -488,7 +488,7 @@ has lines (#2790, `core/test/room-read-floor-clamp.test.js`). ### Diagnostics - 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. -- 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. +- 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. - 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. - 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. - 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). diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 6600bcbae..8ba55b65c 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -6418,7 +6418,7 @@ diff --git a/src/host/diagnostics.js b/src/host/diagnostics.js // Shapes of credentials that are not saved keys: provider keys, bearer tokens, and // token or key parameters in addresses (the Web login address carries one). const CREDENTIALS = [ -@@ -34,29 +34,84 @@ const CREDENTIALS = [ +@@ -34,29 +34,91 @@ const CREDENTIALS = [ [/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=*-]{8,}/gi, '$1 [hidden]'], [/([?&#](?:token|access_token|api_key|apikey|key|secret|password)=)[^&\s"']+/gi, '$1[hidden]'], [/(["']?(?: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 + // `sig` and `pass` count as a whole segment the way `pat` does there, so `assign`, `compass` and + // `bypass` are ordinary names; `hmac` is not part of any ordinary word. + [/(["']?(?:hmac|passwd|(? value, home = homedir() } = {}) { diff --git a/patches/ds-bot/0007-version-and-tooling.patch b/patches/ds-bot/0007-version-and-tooling.patch index f216dcc0c..c7f436f16 100644 --- a/patches/ds-bot/0007-version-and-tooling.patch +++ b/patches/ds-bot/0007-version-and-tooling.patch @@ -858,7 +858,7 @@ diff --git a/test/diagnostics.test.js b/test/diagnostics.test.js assert.ok(cleanText('x'.repeat(5000)).length < 2100) }) -@@ -33,17 +33,100 @@ test('cleanText hides standalone credentials it was never given', () => { +@@ -33,17 +33,153 @@ test('cleanText hides standalone credentials it was never given', () => { assert.equal(out, '[hidden] [hidden] [hidden] [hidden] [hidden] [hidden]') }) @@ -934,6 +934,59 @@ diff --git a/test/diagnostics.test.js b/test/diagnostics.test.js + assert.equal(cleanText('Signature: abcdef123456', { home: '' }), 'Signature: abcdef123456') + assert.equal(cleanText('X-Token: abc12', { home: '' }), 'X-Token: abc12') +}) ++ ++// #3310: the header-name entry started a name with a repeated segment group, so on a hyphenated ++// body it retried the whole name from every position and one `cleanText` call grew with the square ++// of the text: 4/8/16/40/80 KB took 23/85/343/2132/8782 ms on `9a48f5aa`, and the call sites take ++// whatever an error body carries. The name is anchored at a word boundary and carries at most six ++// segments, so the scan is linear; this case pins the bound and prints the table it measured. ++test('cleanText stays fast on a long hyphenated body', (t) => { ++ for (const bytes of [4096, 8192, 16384, 40960, 81920]) { ++ const text = 'a-'.repeat(bytes / 2) ++ const started = performance.now() ++ cleanText(text, { home: '' }) ++ const ms = performance.now() - started ++ t.diagnostic(`${bytes} bytes: ${ms.toFixed(1)} ms`) ++ assert.ok(ms < 1000, `${bytes} bytes took ${ms.toFixed(0)} ms`) ++ } ++}) ++ ++// #3310: an underscore joins a header name too, and an array key is still the same shape. The value ++// side does not change: a JSON key, a tab, a bearer value and a `?X-Token=` parameter keep masking. ++test('cleanText hides an underscore or array header name', () => { ++ assert.equal(cleanText('X_Token: abcdef123456', { home: '' }), 'X_Token: [hidden]') ++ assert.equal(cleanText('X-Token[]: abcdef123456', { home: '' }), 'X-Token[]: [hidden]') ++ assert.equal(cleanText('{"X_Token":"abcdef123456"}', { home: '' }), '{"X_Token":"[hidden]"}') ++ assert.equal(cleanText('X-Token[]:\tabcdef123456', { home: '' }), 'X-Token[]:\t[hidden]') ++ assert.equal(cleanText('X-Auth: Bearer abcdef123456', { home: '' }), 'X-Auth: [hidden]') ++ assert.equal(cleanText('?X-Token=abcdef123456', { home: '' }), '?X-Token=[hidden]') ++}) ++ ++// #3310: `oauth` names a credential too, and a name segment like `X-OAuth` is the header shape. ++test('cleanText hides an oauth header', () => { ++ assert.equal(cleanText('X-OAuth: abcdef123456', { home: '' }), 'X-OAuth: [hidden]') ++ assert.equal(cleanText('{"X-OAuth":"abcdef123456"}', { home: '' }), '{"X-OAuth":"[hidden]"}') ++}) ++ ++// #3310: the six-character floor was applied to the first whitespace-delimited token, so a value ++// whose first word was short escaped whole. The floor is on the value, which is masked as one piece. ++test('cleanText masks the whole header value when its first token is short', () => { ++ assert.equal(cleanText('X-Token: abc def', { home: '' }), 'X-Token: [hidden]') ++ assert.equal(cleanText('X-Token: abc def ghi', { home: '' }), 'X-Token: [hidden]') ++ // Five characters in total stay readable, and an ordinary hyphenated name stays readable. ++ assert.equal(cleanText('X-Token: abc12', { home: '' }), 'X-Token: abc12') ++ assert.equal(cleanText('X-Patch-Id: abc def', { home: '' }), 'X-Patch-Id: abc def') ++}) ++ ++// #3310 review: the value tail was capped at 199 characters after its first, so a long value kept ++// its head masked and left the rest readable — 704 characters came back as 200 masked and 504 ++// visible. Base masked the whole value, so a cap here would widen what a log line prints. The value ++// is read to the end of the field with no length bound. ++test('cleanText masks a long header value whole', () => { ++ const value = 'A1'.repeat(352) ++ assert.equal(value.length, 704) ++ assert.equal(cleanText(`X-Token: ${value}`, { home: '' }), 'X-Token: [hidden]') ++}) + function host(home, extra = {}) { const warnings = []