Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3310.fixed.md
Original file line number Diff line number Diff line change
@@ -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)).
25 changes: 16 additions & 9 deletions core/src/host/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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|(?<![a-z0-9])(?:sig|pass)(?![a-z0-9]))["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
// A header-shaped name is a hyphenated field name whose last segment is a credential word, so
// `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`,
// `X-Amz-Signature`, `X-Key` and `X-Signature` are masked the way `capabilities.js` masks a
// stored capability body. The whole last segment has to be the credential word, so `X-Patch-Id`,
// `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name` keep their text. A bare
// `Signature:` stays readable on purpose: masking every name holding `signature`, `auth`,
// `session` or `token` would eat `auth: failed to connect` and `session: expired at noon`,
// which is the widening #3291 refused.
[/(["']?(?:[a-z0-9]+-)+(?:key|token|auth|cookie|session|credential|signature|pat|sig|pass)["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
// A header-shaped name is a hyphenated or underscored field name whose last segment is a
// credential word, so `X-Pat`, `X-Github-Pat`, `X_Token`, `X-Token[]`, `X-Auth`, `X-Cookie`,
// `X-Session`, `X-Credential`, `X-OAuth`, `X-Amz-Signature`, `X-Key` and `X-Signature` are masked
// the way `capabilities.js` masks a stored capability body. The whole last segment has to be the
// credential word, so `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name`
// keep their text. A bare `Signature:` stays readable on purpose: masking every name holding
// `signature`, `auth`, `session` or `token` would eat `auth: failed to connect` and
// `session: expired at noon`, which is the widening #3291 refused.
// #3310: the repeated segment group retried the whole name from every position, so on a
// hyphenated body the scan was quadratic (4/8/16/40/80 KB took 23/85/343/2132/8782 ms). The name
// now starts after a character that is not part of one and carries at most six segments of at
// most 64 characters, so a start costs a bounded amount and the scan is linear. The value is read
// as one piece up to the end of the field (a quote, comma, brace or newline ends it) and the
// six-character floor is on the whole value, so a first token under six characters is masked too.
// The value has no length cap: a cap left the tail of a long value readable in a report.
[/(?<![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]'],
]

// A path under a home can be deeper than the bound is long (#2964): `~/.local/share/deepseek-harness/
Expand Down
53 changes: 53 additions & 0 deletions core/test/diagnostics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,59 @@ test('cleanText keeps ordinary hyphenated names and a bare Signature', () => {
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 = []
Expand Down
2 changes: 1 addition & 1 deletion docs/subsystems/core-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
27 changes: 17 additions & 10 deletions patches/ds-bot/0001-core-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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]'],
Expand All @@ -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|(?<![a-z0-9])(?:sig|pass)(?![a-z0-9]))["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
+ // A header-shaped name is a hyphenated field name whose last segment is a credential word, so
+ // `X-Pat`, `X-Github-Pat`, `X-Token`, `X-Auth`, `X-Cookie`, `X-Session`, `X-Credential`,
+ // `X-Amz-Signature`, `X-Key` and `X-Signature` are masked the way `capabilities.js` masks a
+ // stored capability body. The whole last segment has to be the credential word, so `X-Patch-Id`,
+ // `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name` keep their text. A bare
+ // `Signature:` stays readable on purpose: masking every name holding `signature`, `auth`,
+ // `session` or `token` would eat `auth: failed to connect` and `session: expired at noon`,
+ // which is the widening #3291 refused.
+ [/(["']?(?:[a-z0-9]+-)+(?:key|token|auth|cookie|session|credential|signature|pat|sig|pass)["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, '$1[hidden]'],
+ // A header-shaped name is a hyphenated or underscored field name whose last segment is a
+ // credential word, so `X-Pat`, `X-Github-Pat`, `X_Token`, `X-Token[]`, `X-Auth`, `X-Cookie`,
+ // `X-Session`, `X-Credential`, `X-OAuth`, `X-Amz-Signature`, `X-Key` and `X-Signature` are masked
+ // the way `capabilities.js` masks a stored capability body. The whole last segment has to be the
+ // credential word, so `X-Patch-Id`, `X-Path-Id`, `X-Request-Id`, `session-count` and `key-name`
+ // keep their text. A bare `Signature:` stays readable on purpose: masking every name holding
+ // `signature`, `auth`, `session` or `token` would eat `auth: failed to connect` and
+ // `session: expired at noon`, which is the widening #3291 refused.
+ // #3310: the repeated segment group retried the whole name from every position, so on a
+ // hyphenated body the scan was quadratic (4/8/16/40/80 KB took 23/85/343/2132/8782 ms). The name
+ // now starts after a character that is not part of one and carries at most six segments of at
+ // most 64 characters, so a start costs a bounded amount and the scan is linear. The value is read
+ // as one piece up to the end of the field (a quote, comma, brace or newline ends it) and the
+ // six-character floor is on the whole value, so a first token under six characters is masked too.
+ // The value has no length cap: a cap left the tail of a long value readable in a report.
+ [/(?<![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]'],
]

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