diff --git a/changelog.d/3291.fixed.md b/changelog.d/3291.fixed.md new file mode 100644 index 000000000..48078cc63 --- /dev/null +++ b/changelog.d/3291.fixed.md @@ -0,0 +1 @@ +`X-Sig`, `X-Hmac` and `X-Pass` values in a diagnostics log line or report row are masked now: the name list `cleanText` uses for the report and the downloaded log (`CREDENTIALS` in `core/src/host/diagnostics.js`) had none of the three, so a warning or log line that echoed one of those headers kept the value verbatim while `capabilities.js` already masked it in a stored capability body. `sig` and `pass` count as a whole segment, the way `pat` does there, so `assign`, `compass` and `bypass` keep their text; `hmac` is not part of any ordinary word. The value is masked from six characters, with a quote allowed on either side, so a JSON body is covered too, and a five-character value is left alone rather than eating the words around it ([#3291](https://github.com/ThinkFlowLab/FlyBot/issues/3291)). diff --git a/core/src/host/diagnostics.js b/core/src/host/diagnostics.js index 55cd3f08f..2f4fa5c23 100644 --- a/core/src/host/diagnostics.js +++ b/core/src/host/diagnostics.js @@ -52,6 +52,12 @@ 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]'], + // #3291: `sig`, `hmac` and `pass` name credentials too. This list is the one the report and the + // downloaded log are cleaned with, and it was narrower than the list `capabilities.js` masks a + // capability body with, so a log line echoing `X-Sig: …`, `X-Hmac: …` or `X-Pass: …` kept the value. + // `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|(? { assert.equal(out, '[hidden] [hidden] [hidden] [hidden] [hidden] [hidden]') }) +// #3291: the diagnostics mask had a second, narrower name list than `capabilities.js`: `sig`, +// `hmac` and `pass` were masked where a capability body is stored, but a log line or report that +// echoed `X-Sig: …`, `X-Hmac: …` or `X-Pass: …` kept the value verbatim. One test per name, so a +// list entry that misses one of the three cannot pass behind the other two. +test('cleanText hides the value of a sig header', () => { + assert.equal(cleanText('X-Sig: abcdef123456', { home: '' }), 'X-Sig: [hidden]') + assert.equal(cleanText('{"sig":"abcdef123456"}', { home: '' }), '{"sig":"[hidden]"}') +}) + +test('cleanText hides the value of an hmac header', () => { + assert.equal(cleanText('X-Hmac: abcdef123456', { home: '' }), 'X-Hmac: [hidden]') + assert.equal(cleanText('{"hmac":"abcdef123456"}', { home: '' }), '{"hmac":"[hidden]"}') +}) + +test('cleanText hides the value of a pass header', () => { + assert.equal(cleanText('X-Pass: abcdef123456', { home: '' }), 'X-Pass: [hidden]') + assert.equal(cleanText('{"pass":"abcdef123456"}', { home: '' }), '{"pass":"[hidden]"}') +}) + +// The same three names stay bounded as a whole segment, the way `pat` is in `capabilities.js`: +// `assign`, `compass` and `bypass` are ordinary names. The name the list already had keeps working, +// a JSON body is masked through its quotes, and a value under six characters is left alone. +test('cleanText keeps assign, compass and bypass and leaves a five-character value', () => { + assert.equal( + cleanText('assign: abcdef123456 compass: abcdef123456 bypass: abcdef123456', { home: '' }), + 'assign: abcdef123456 compass: abcdef123456 bypass: abcdef123456', + ) + assert.equal(cleanText('x-api-key: abcdef123456', { home: '' }), 'x-api-key: [hidden]') + assert.equal(cleanText('X-Sig: abc12', { home: '' }), 'X-Sig: abc12') +}) + function host(home, extra = {}) { const warnings = [] const disposers = [] diff --git a/docs/subsystems/core-host.md b/docs/subsystems/core-host.md index f9981ae29..a165a6512 100644 --- a/docs/subsystems/core-host.md +++ b/docs/subsystems/core-host.md @@ -487,6 +487,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. - 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 6a867feb8..b142e35b5 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -6403,8 +6403,16 @@ 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 = [ -@@ -36,27 +36,67 @@ const CREDENTIALS = [ +@@ -34,29 +34,75 @@ 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]'], ++ // #3291: `sig`, `hmac` and `pass` name credentials too. This list is the one the report and the ++ // downloaded log are cleaned with, and it was narrower than the list `capabilities.js` masks a ++ // capability body with, so a log line echoing `X-Sig: …`, `X-Hmac: …` or `X-Pass: …` kept the value. ++ // `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|(? value, home = homedir() } = {}) { diff --git a/patches/ds-bot/0007-version-and-tooling.patch b/patches/ds-bot/0007-version-and-tooling.patch index d8708375a..da5299e7a 100644 --- a/patches/ds-bot/0007-version-and-tooling.patch +++ b/patches/ds-bot/0007-version-and-tooling.patch @@ -854,8 +854,41 @@ diff --git a/test/diagnostics.test.js b/test/diagnostics.test.js assert.ok(cleanText('x'.repeat(5000)).length < 2100) }) -@@ -35,15 +35,25 @@ test('cleanText hides standalone credentials it was never given', () => { +@@ -33,17 +33,58 @@ test('cleanText hides standalone credentials it was never given', () => { + assert.equal(out, '[hidden] [hidden] [hidden] [hidden] [hidden] [hidden]') + }) ++// #3291: the diagnostics mask had a second, narrower name list than `capabilities.js`: `sig`, ++// `hmac` and `pass` were masked where a capability body is stored, but a log line or report that ++// echoed `X-Sig: …`, `X-Hmac: …` or `X-Pass: …` kept the value verbatim. One test per name, so a ++// list entry that misses one of the three cannot pass behind the other two. ++test('cleanText hides the value of a sig header', () => { ++ assert.equal(cleanText('X-Sig: abcdef123456', { home: '' }), 'X-Sig: [hidden]') ++ assert.equal(cleanText('{"sig":"abcdef123456"}', { home: '' }), '{"sig":"[hidden]"}') ++}) ++ ++test('cleanText hides the value of an hmac header', () => { ++ assert.equal(cleanText('X-Hmac: abcdef123456', { home: '' }), 'X-Hmac: [hidden]') ++ assert.equal(cleanText('{"hmac":"abcdef123456"}', { home: '' }), '{"hmac":"[hidden]"}') ++}) ++ ++test('cleanText hides the value of a pass header', () => { ++ assert.equal(cleanText('X-Pass: abcdef123456', { home: '' }), 'X-Pass: [hidden]') ++ assert.equal(cleanText('{"pass":"abcdef123456"}', { home: '' }), '{"pass":"[hidden]"}') ++}) ++ ++// The same three names stay bounded as a whole segment, the way `pat` is in `capabilities.js`: ++// `assign`, `compass` and `bypass` are ordinary names. The name the list already had keeps working, ++// a JSON body is masked through its quotes, and a value under six characters is left alone. ++test('cleanText keeps assign, compass and bypass and leaves a five-character value', () => { ++ assert.equal( ++ cleanText('assign: abcdef123456 compass: abcdef123456 bypass: abcdef123456', { home: '' }), ++ 'assign: abcdef123456 compass: abcdef123456 bypass: abcdef123456', ++ ) ++ assert.equal(cleanText('x-api-key: abcdef123456', { home: '' }), 'x-api-key: [hidden]') ++ assert.equal(cleanText('X-Sig: abc12', { home: '' }), 'X-Sig: abc12') ++}) ++ function host(home, extra = {}) { const warnings = [] + const disposers = []