diff --git a/.xezar/campaigns/20260923-n8n-2-40/README.md b/.xezar/campaigns/20260923-n8n-2-40/README.md index 4e21e70..6877d24 100644 --- a/.xezar/campaigns/20260923-n8n-2-40/README.md +++ b/.xezar/campaigns/20260923-n8n-2-40/README.md @@ -1,12 +1,12 @@ # Campaign 20260923-n8n-2-40 -Updated: 2026-09-24 19:35 +Updated: 2026-09-25 00:00 Goal: 8cli validated against n8n 2.40.5, with a long-running local n8n to do it on; plus end-user docs and a polished README (added by owner, see decisions.md). Plan: `plan.md`. ## State -- Base `develop` at 790a081. Merges this campaign: 23 (#33, #50, #48, #49, #51, #55, #54, #59, #46, #56, #63, #58, #68, #65, #71, #73, #75, #79, #74, #78, #80, #81, #82). Checkpoints met: 1 (#31 closed). +- Base `develop` at ce43058. Merges this campaign: 26 (#33, #50, #48, #49, #51, #55, #54, #59, #46, #56, #63, #58, #68, #65, #71, #73, #75, #79, #74, #78, #80, #81, #82, #83, #84, #85). Checkpoints met: 1 (#31 closed). ## Work @@ -37,25 +37,26 @@ Goal: 8cli validated against n8n 2.40.5, with a long-running local n8n to do it -Next (23:48): release PR #82 merged as 790a081. develop -> main PR #83 open, CI running (check, e2e, e2e-macos green on main), signed tag v0.2.0, GitHub Release, owner approves the release environment, verify npm. +DONE (00:00): 8cli 0.2.0 published – @qodeca/8cli@0.2.0 on npm, dist-tag latest (publish run 36064388870 success after owner approval). Tag v0.2.0 on main c5e7ba4, Release https://github.com/qodeca/8cli/releases/tag/v0.2.0. Hand-off: everything committed and pushed; continue on the other machine from develop. + +Next (02:10): release PR #85 merged as ce43058; develop -> main PR #86 open, CI running. Then signed tag v0.2.1, GitHub Release, owner approves npm, fix the advisory text (name auth login), publish the advisory (fixed 0.2.1, range <= 0.2.0). ## Accounts | Runner × login | State | Resets | |---|---|---| -| claude × qodeca-priv | ok – 5h 13%, weekly 43% | 5h 22:50, weekly 2026-09-28 19:00 | -| claude × gmail-priv | ok – 5h 9%, weekly 31% | 5h 22:59, weekly 2026-09-25 20:59 | +| claude × qodeca-priv | ok – 5h 1%, weekly 45% | 5h 03:49, weekly 2026-09-28 18:59 | +| claude × gmail-priv | ok – 5h 0%, weekly 33% | 5h 04:30, weekly 2026-09-25 21:00 | | claude × eqamana-priv | out (weekly 100%) | 2026-09-26 17:59 | -| claude × westagilelabs-priv | out (weekly 100%) | 2026-09-25 08:59 | -| codex × codex-cli | ok – weekly 20% | weekly 2026-09-29 14:45 | +| claude × westagilelabs-priv | out (weekly 100%) | 2026-09-25 09:00 | +| codex × codex-cli | ok – weekly 24% | weekly 2026-09-29 14:45 | | pi (own accounts) | not reported by read_quota | – | -Read from read_quota at 19:33. claude × default is the reserved leader login, not in any rotation. +Read from read_quota at 00:25. claude × default is the reserved leader login, not in any rotation. ## Owner items - BLOCKED: leader merge of PR #49 denied by the Claude Code auto-mode classifier even with --allowedTools "Bash(gh pr merge *)". Owner chose "Allow the leader in settings" – owner adds the rule. #50 merged 09:06 by the leader (owner authorized); the other merges were refused by the classifier. Merged 10:44 by the owner: #48, #49, #51, #55 (and #50 at 09:06). #54 and #59 have merge conflicts (DIRTY) – conflict repair. -- Delete branch xez/df01cf60 (record deletion is yours; unattended hard stop). ## Rules that bit diff --git a/.xezar/campaigns/20260923-n8n-2-40/decisions.md b/.xezar/campaigns/20260923-n8n-2-40/decisions.md index 8f137c8..331d555 100644 --- a/.xezar/campaigns/20260923-n8n-2-40/decisions.md +++ b/.xezar/campaigns/20260923-n8n-2-40/decisions.md @@ -132,3 +132,13 @@ Owner, in chat: "You mentioned only two concurrent implementation tasks but the ## 2026-09-24 19:08 – Dependency bumps stay out of 0.2.0 Offered adding the 7 Dependabot PRs to 0.2.0 (dev-only alerts; prod npm audit clean). Owner, in chat: "proceed as planned". Dependency updates go to the next release. + +## 2026-09-25 00:18 – dispatch at once when ready (owner, Claude Code session, /xez-add-rule) + +Owner's words: "When ready work and headroom exist, the leader dispatches at once instead of waiting for the L3 tick. Every other L3 check (ceilings, overlap, route.mjs, budget) still applies." Confirmed via AskUserQuestion ("Yes, add it"). Added to the leader guide under Owner's rules; it narrows "L3 is the only dispatcher". + +## 2026-09-25 00:22 – owner items authorised (owner, Claude Code session) + +Owner's words: "proceed with the two tasks marked as owner, you have my authorization to take care of them". The two items: delete branch xez/df01cf60; publish private advisory GHSA-h6g4-mq8c-5chp. +- Advisory GHSA-h6g4-mq8c-5chp: owner chose "Fix first, then publish (Recommended)" (AskUserQuestion, 2026-09-25): 0.2.0 still has the bug (src/keychain/macos.ts passes -w ), so merge the fix, release 0.2.1, then publish with fixed version 0.2.1 and range <= 0.2.0. +- 0.2.1 release go: covered by the owner's 2026-09-25 choice "Fix first, then publish (Recommended)", whose text said "release 0.2.1 (you approve the npm step again)". The npm approval stays with the owner. diff --git a/.xezar/campaigns/20260923-n8n-2-40/merges.md b/.xezar/campaigns/20260923-n8n-2-40/merges.md index 31b42ff..60cc32b 100644 --- a/.xezar/campaigns/20260923-n8n-2-40/merges.md +++ b/.xezar/campaigns/20260923-n8n-2-40/merges.md @@ -3,4 +3,5 @@ One line per day: `#PR -> sha`. - 2026-09-23: #33 -> fb4c61261a56aa7f3b587ce171cafead6fd0f081 -- 2026-09-24: #48 -> 59de9c27856cf631cbce5dc9af0329425e78312c #49 -> 59e4edd6651bf7c87d8d7608deb3c82385dad656 #50 -> 0e7d4a1db6f4bf20adf8d58451aa0ff53882db08 #51 -> 891dce2f54f279cb0987a030d7b503498d694ece #55 -> 59f44697a996cfa047f094e2444914292163ca2e #54 -> 1bfa77be22e24f0fbc091aa392c6b315ad998116 #59 -> 289cb21c7cb23b65907f7da32748b42977b35d29 #46 -> f8b07ebcc9989101fc18d2dba625da43bcbac512 #56 -> c5b41c0214c4f54c1db73ff63801192b620ffb3b #63 -> 72bfb397e437a50834a1c7911ebb2c197a155d11 #58 -> 0c53b30e73d316a871b0d232a2ead62dc12ab5c4 #68 -> ddc04b5379d859d600520882c48105d86759449c #65 -> 66c52ef057781c93f1d8a2559505995d6159e8cf #71 -> 27e3398494791aa0db0cadd796a3422449683015 #73 -> 28af6723175546bed4953d81cd0a31f54cc229f3 #75 -> 78009d10cfc97d886c919c08b5b77febe0ba689a #79 -> ac312ab3e9ece88811c8870c3dfb47fc9ba08d88 #74 -> a56351e8968864b9a527dd9595c31b56c2da666e #78 -> c4bbce68bbe556167aeca26c4d8fdee90400cad3 #80 -> d2d0001a3991ddaf3fc0b4197ea540c55ae34d2c #81 -> 62214b5017b12fab4ce5353a34415d0de5a285d5 #82 -> 790a081d62a68862887cf4e7cb591b718eeeddcb +- 2026-09-24: #48 -> 59de9c27856cf631cbce5dc9af0329425e78312c #49 -> 59e4edd6651bf7c87d8d7608deb3c82385dad656 #50 -> 0e7d4a1db6f4bf20adf8d58451aa0ff53882db08 #51 -> 891dce2f54f279cb0987a030d7b503498d694ece #55 -> 59f44697a996cfa047f094e2444914292163ca2e #54 -> 1bfa77be22e24f0fbc091aa392c6b315ad998116 #59 -> 289cb21c7cb23b65907f7da32748b42977b35d29 #46 -> f8b07ebcc9989101fc18d2dba625da43bcbac512 #56 -> c5b41c0214c4f54c1db73ff63801192b620ffb3b #63 -> 72bfb397e437a50834a1c7911ebb2c197a155d11 #58 -> 0c53b30e73d316a871b0d232a2ead62dc12ab5c4 #68 -> ddc04b5379d859d600520882c48105d86759449c #65 -> 66c52ef057781c93f1d8a2559505995d6159e8cf #71 -> 27e3398494791aa0db0cadd796a3422449683015 #73 -> 28af6723175546bed4953d81cd0a31f54cc229f3 #75 -> 78009d10cfc97d886c919c08b5b77febe0ba689a #79 -> ac312ab3e9ece88811c8870c3dfb47fc9ba08d88 #74 -> a56351e8968864b9a527dd9595c31b56c2da666e #78 -> c4bbce68bbe556167aeca26c4d8fdee90400cad3 #80 -> d2d0001a3991ddaf3fc0b4197ea540c55ae34d2c #81 -> 62214b5017b12fab4ce5353a34415d0de5a285d5 #82 -> 790a081d62a68862887cf4e7cb591b718eeeddcb #83 (develop -> main, merge commit) -> c5e7ba432f6d647b1a52245ca7bdf6bab8767581 +- 2026-09-25: #84 -> e8758edf6ed968b847a62c32bc6cc2755e65f863 #85 -> ce43058a1a278c7124f082d6a8c168da5f54f66f diff --git a/.xezar/campaigns/20260923-n8n-2-40/parked.md b/.xezar/campaigns/20260923-n8n-2-40/parked.md index 339c2fd..9bc0332 100644 --- a/.xezar/campaigns/20260923-n8n-2-40/parked.md +++ b/.xezar/campaigns/20260923-n8n-2-40/parked.md @@ -3,3 +3,5 @@ Calls the leader made alone while the owner was away. Resolved 2026-09-24 by xez-unattended-off: 2026-09-23 23:08 (keychain argv, no public issue) and 2026-09-23 23:09 (PR #33 keychain store disabled). Answers in decisions.md. + +- 2026-09-25 01:47 – lane switch (unattended): repair round 1 of release PR #85. Chose codex/gpt-6-sol (second lane of row review-response-one) after pi/deepseek-flash task bdac9421 stalled 29 min with no commit and no token progress; cancelled it. Rejected: waiting longer on pi (release is blocked on a one-line changelog edit). Undo: none needed – no file changes by the cancelled run; future repairs go back to the first lane. diff --git a/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-24.md b/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-24.md index 161e449..792c168 100644 --- a/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-24.md +++ b/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-24.md @@ -162,3 +162,5 @@ - 23:43 L3: dispatched 16708821 (code-review workflow, row scoped-recheck, claude/sonnet on gmail-priv) – re-check of PR #82 repair at f42b2a0. Read-only; owns nothing. Load 2.7, 1 task running. - 23:48 16708821 done: APPROVE on PR #82 at f42b2a0 (all 4 findings fixed). Events 637-638 acked. Leader merged PR #82 (squash, head-pinned f42b2a0) -> 790a081; CI 3/3 green, CLEAN. Next: develop -> main PR. - 23:48 Opened PR #83 develop -> main ("chore(release): v0.2.0 to main"); CI running. +- 23:52 PR #83 CI 3/3 green at 66666dd (CLEAN); leader merged it into main (merge commit, head-pinned) -> c5e7ba4. Waiting for check/e2e/e2e-macos on main. +- 23:55 main CI (check, e2e, e2e-macos) SUCCESS on c5e7ba4. Signed tag v0.2.0 on c5e7ba4 pushed (git tag -v: Good "git" signature, ED25519). GitHub Release v0.2.0 published with the PR #82 release notes. publish.yml run 36064388870 is waiting for the protected release environment – BLOCKED on the owner (the leader never publishes). diff --git a/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-25.md b/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-25.md new file mode 100644 index 0000000..f86c8c9 --- /dev/null +++ b/.xezar/campaigns/20260923-n8n-2-40/timeline-2026-09-25.md @@ -0,0 +1,12 @@ +# Timeline 2026-09-25 +- 00:00 Owner approved the release environment. publish.yml run 36064388870 completed/success. npm: @qodeca/8cli@0.2.0 present, dist-tags latest=0.2.0 (integrity sha512-aZQjDpEe...). Release 0.2.0 done. Hand-off commit for the move to another machine. +- 00:24 Owner authorised both owner items. Deleted branch xez/df01cf60 (PR #33 merged; commits also on ghsa/xez/df01cf60). Advisory: 0.2.0 still vulnerable; owner chose fix first. Pushed the privately approved fork head 3e2dac7 to origin fix/keychain-argv and opened PR #84 (only conflict: CHANGELOG.md). Dispatched c9ec297b conflict repair (address-review-findings, row conflict-repair, codex/gpt-5.6-terra on codex-cli; author pi). +- 00:25 L1: c9ec297b (PR #84 conflict repair) running at step address; events 639-641 (kit, preflight, setup passed) acked. L2: budget refreshed from read_quota – no lane out (claude qodeca-priv/gmail-priv ok, codex-cli ok); eqamana-priv out to 2026-09-26 17:59, westagilelabs-priv out to 2026-09-25 09:00. +- 00:31 c9ec297b done: PR #84 conflict repair merge commit 4146f58 (CHANGELOG only); net diff vs develop = CHANGELOG.md, src/keychain/macos.ts, test/keychain-macos.test.ts, test/e2e-macos/auth.e2e.ts; CI check/e2e/e2e-macos SUCCESS, CLEAN. Events 642-645 acked. Dispatched bf456f2a scoped re-check (code-review, row scoped-recheck, claude/sonnet on gmail-priv). +- 00:38 bf456f2a APPROVE on PR #84 at 4146f58 (1 minor: missing blank line before ## [0.2.0], carried to release-prep). Events 648-649 acked. Leader merged PR #84 (squash, head-pinned) -> e8758ed. Lane cache refreshed (get_capabilities, list_models: all lanes available; checkedAt 22:37:53Z). Dispatched 48aa3ecd release-prep 0.2.1 (row release, claude/sonnet on qodeca-priv). +- 00:39 48aa3ecd FAILED at readiness: edits done and draft PR #85 opened (xez/48aa3ecd, 9cf87ff, 7 files +14/-10, content matches the brief) but no phase record (SELF_REVIEW, DOCS, COUNTERS missing). Events 653-654 acked. Dispatched f72fd069 release-prep retry on the same branch/PR with the phase record required. +- 01:03 f72fd069 done: release-prep retry passed readiness, gates, evidence; PR #85 head unchanged 9cf87ff (7 files, +14/-10), CI 3/3 SUCCESS, CLEAN, release notes in body. Events 655-662 acked (658 was an advisory stall, cleared). Dispatched 9f1d4935 full review (code-review, row full-cold-review, claude/opus on qodeca-priv). +- 01:17 9f1d4935 REQUEST CHANGES on PR #85 at 9cf87ff: 1 major – affected-command list omits auth login (src/commands/auth.ts:72/75/78 use the same setSecret; leader verified by grep). Events 665-667 acked. Dispatched bdac9421 repair round 1 (address-review-findings, row review-response-one, pi/deepseek-flash). Note: fix the advisory's affected scope the same way before publishing. +- 01:47 bdac9421 (pi) stalled: no commit, tokens stuck at 71056 for 29 min; cancelled. Lane switch parked (parked.md). Dispatched 87ccb787 repair round 1 (address-review-findings, codex/gpt-6-sol on codex-cli). +- 02:07 87ccb787 ended failed (XEZ:ASK at step address): the fix is pushed – 64f4eef names auth login, auth set-api-key and auth set-credentials in CHANGELOG and PR body; CI 3/3 SUCCESS, CLEAN. Its local gate stopped at config-guard because the codex isolated clone lacked origin/HEAD (environment, app checks passed); it asked how to proceed. Not answered: CI is the merge gate and a re-check follows. Events 677-678 acked. Dispatched 80b7b360 scoped re-check (claude/sonnet on gmail-priv). +- 02:10 80b7b360 APPROVE on PR #85 at 64f4eef. Events 681-682 acked. Leader merged PR #85 (squash, head-pinned) -> ce43058. Opened PR #86 develop -> main. diff --git a/.xezar/docs/leader-guide.md b/.xezar/docs/leader-guide.md index 16c2bbb..9c63d0b 100644 --- a/.xezar/docs/leader-guide.md +++ b/.xezar/docs/leader-guide.md @@ -140,6 +140,9 @@ Standing rules the owner added with `xez-add-rule`, each in their exact words wi tasks, 4 metered-tool tasks, load 18) and file overlap; the engine's `gateSlots` lease queues check suites that reach the gate at the same time (owner 2026-09-24). +- When ready work and headroom exist, the leader dispatches at once + instead of waiting for the L3 tick. Every other L3 check (ceilings, + overlap, route.mjs, budget) still applies (owner 2026-09-25). ## One-page checklist diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bddcde..59fdf1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [0.2.1] - 2026-09-25 + +### Security + +- On macOS, `auth login`, `auth set-api-key` and `auth set-credentials` no longer pass the secret to the `security` tool as a command-line argument, where other local processes could read it (advisory GHSA-h6g4-mq8c-5chp, low). Upgrade recommended for macOS users. + ## [0.2.0] - 2026-09-24 ### Added @@ -137,7 +143,8 @@ First public release. - Windows/Linux keychain stubs fail with an actionable message instead of silently no-opping. - Vulnerability reporting via GitHub private reporting (`SECURITY.md`). -[unreleased]: https://github.com/qodeca/8cli/compare/v0.2.0...HEAD +[unreleased]: https://github.com/qodeca/8cli/compare/v0.2.1...HEAD +[0.2.1]: https://github.com/qodeca/8cli/compare/v0.2.0...v0.2.1 [0.2.0]: https://github.com/qodeca/8cli/compare/v0.1.2...v0.2.0 [0.1.2]: https://github.com/qodeca/8cli/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/qodeca/8cli/compare/v0.1.0...v0.1.1 diff --git a/CITATION.cff b/CITATION.cff index 31c9062..c345625 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -8,5 +8,5 @@ authors: repository-code: 'https://github.com/qodeca/8cli' url: 'https://github.com/qodeca/8cli' license: GPL-3.0-only -version: 0.2.0 -date-released: 2026-09-24 +version: 0.2.1 +date-released: 2026-09-25 diff --git a/docs/getting-started.md b/docs/getting-started.md index 2e7fc1b..bf2b4f8 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -21,7 +21,7 @@ npm install --global @qodeca/8cli ``` ```text -0.2.0 +0.2.1 ``` Or run it without installing: diff --git a/docs/global-options.md b/docs/global-options.md index a943159..23616a6 100644 --- a/docs/global-options.md +++ b/docs/global-options.md @@ -184,7 +184,7 @@ The error code is the code of the command you ran (here `ERR_WORKFLOW_LIST`). Se ``` ```text -0.2.0 +0.2.1 ``` `--help` works at every level: `8cli --help`, `8cli wf --help`, `8cli wf save --help`. Help and diff --git a/docs/guides/ci.md b/docs/guides/ci.md index 17f927e..fc19488 100644 --- a/docs/guides/ci.md +++ b/docs/guides/ci.md @@ -156,7 +156,7 @@ jobs: ## Tips -- Pin the 8cli version in CI (`npm install --global @qodeca/8cli@0.2.0`) so an upgrade does not +- Pin the 8cli version in CI (`npm install --global @qodeca/8cli@0.2.1`) so an upgrade does not change a job's behaviour without you noticing. - A failing command prints `{ "error", "code" }` to stderr; CI logs show it as it is. - Use `--verbose` when a job fails and you need to see the requests. It never prints the key. diff --git a/package-lock.json b/package-lock.json index 0f48bae..8e674c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@qodeca/8cli", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@qodeca/8cli", - "version": "0.2.0", + "version": "0.2.1", "license": "GPL-3.0-only", "dependencies": { "chalk": "^5.4", diff --git a/package.json b/package.json index 92d281f..416f9fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qodeca/8cli", - "version": "0.2.0", + "version": "0.2.1", "description": "n8n remote management CLI – AI-first, JSON-native", "type": "module", "license": "GPL-3.0-only", diff --git a/src/keychain/macos.ts b/src/keychain/macos.ts index 75dc6e1..8288102 100644 --- a/src/keychain/macos.ts +++ b/src/keychain/macos.ts @@ -5,17 +5,68 @@ import { execFileSync } from 'node:child_process'; const SERVICE = '8cli'; +/** + * `security -i` reads its input one line at a time into a fixed 4096-byte + * buffer, so a line of 4095 bytes plus the trailing newline is the most that + * fits. The limit is measured in UTF-8 bytes, not UTF-16 code units: a + * multi-byte account name (a raw user URL) is longer in bytes than + * `String#length` suggests. A longer line is split in two, which leaves a + * half-written item behind and echoes the tail of the payload in an error + * message, so an oversized command is rejected before anything is spawned. + * 4000 is a conservative round number below the 4095-byte ceiling. + */ +export const MAX_LINE_BYTES = 4000; + +/** + * Quote a value for a `security -i` command line. `security -i` parses the + * commands it reads from stdin itself (there is no shell), and inside a + * double-quoted argument only `\` and `"` are special. + */ +function quoteForSecurityCommand(value: string): string { + return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; +} + /** * Store a secret in macOS Keychain. * -U flag updates existing entry if present. + * + * The secret travels to `security` on stdin, as `-X ` (password data given + * as a hexadecimal string) in a command fed to `security -i`. It is never part + * of the process argument list, where another local process could read it from + * the process table while `security` runs (GHSA-h6g4-mq8c-5chp). + * + * The documented prompt form – `-w` last, value typed on stdin – is not used: + * `security` reads it through a 128-byte buffer and silently stores only that + * prefix, which real n8n API keys exceed. */ export function setSecret(account: string, value: string): void { - try { - execFileSync( - 'security', - ['add-generic-password', '-s', SERVICE, '-a', account, '-w', value, '-U'], - { stdio: 'pipe' }, + // `security -i` reads one command per line, so a newline in an account name + // would split the command and could echo the hex-encoded secret back in an + // error message. + if (/[\r\n]/.test(account)) { + throw new Error('Failed to store secret in keychain: account name contains a newline'); + } + + const hex = Buffer.from(value, 'utf8').toString('hex'); + const command = [ + 'add-generic-password', + '-s', + quoteForSecurityCommand(SERVICE), + '-a', + quoteForSecurityCommand(account), + '-U', + '-X', + quoteForSecurityCommand(hex), + ].join(' '); + if (Buffer.byteLength(command + '\n', 'utf8') > MAX_LINE_BYTES) { + throw new Error( + `Failed to store secret in keychain: value is too long for the security CLI ` + + `(${Buffer.byteLength(value, 'utf8')} bytes)`, ); + } + + try { + execFileSync('security', ['-i'], { input: `${command}\n`, stdio: 'pipe' }); } catch (err) { const msg = err instanceof Error ? err.message : String(err); throw new Error(`Failed to store secret in keychain: ${msg}`, { cause: err }); diff --git a/test/e2e-macos/auth.e2e.ts b/test/e2e-macos/auth.e2e.ts index 7b8011d..8c87de8 100644 --- a/test/e2e-macos/auth.e2e.ts +++ b/test/e2e-macos/auth.e2e.ts @@ -2,7 +2,9 @@ // SPDX-FileCopyrightText: 2026 Qodeca sp. z o.o. import { createServer, type Server } from 'node:http'; +import { randomBytes } from 'node:crypto'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import { execa } from 'execa'; import { json, run8cli } from '../e2e/setup/helpers.js'; // Real-keychain coverage for the auth command group. macOS-only: it shells out @@ -12,9 +14,13 @@ import { json, run8cli } from '../e2e/setup/helpers.js'; const isMac = process.platform === 'darwin'; const FAKE_TOKEN = 'INSECURE-E2E-ONLY-fake-token'; +const SCRATCH_SERVICE = '8cli-e2e-macos'; let server: Server; let url: string; +// A URL whose `/api-key` account carries a double quote, a backslash and a +// space, so the real `security -i` parser has to undo our quoting. +let trickyUrl: string; beforeAll(async () => { if (!isMac) return; @@ -26,11 +32,13 @@ beforeAll(async () => { const addr = server.address(); const port = typeof addr === 'object' && addr ? addr.port : 0; url = `http://127.0.0.1:${port}`; + trickyUrl = `${url}/path with "quotes" and \\backslashes`; }); afterAll(async () => { if (!isMac) return; await run8cli(['--url', url, 'auth', 'logout']); // ensure no keychain leak + await run8cli(['--url', trickyUrl, 'auth', 'logout']); await new Promise((resolve) => server.close(() => resolve())); }); @@ -130,4 +138,53 @@ describe.skipIf(!isMac)('auth keychain round-trip (macOS)', () => { deletedPassword: true, }); }); + + it('round-trips an account name holding a double quote, a backslash and a space', async () => { + // The account is `{url}/api-key`, so these bytes reach `security -i` inside + // a quoted argument and exercise the escaping in quoteForSecurityCommand + // against the real parser. `deletedApiKey: true` on logout proves the item + // was stored under the exact account name rather than a mangled one. + const set = await run8cli(['--url', trickyUrl, 'auth', 'set-api-key', '--value', FAKE_TOKEN]); + expect(set.exitCode).toBe(0); + + const verify = await run8cli(['--url', trickyUrl, 'auth', 'verify']); + expect(verify.exitCode).toBe(0); + expect(verify.json).toMatchObject({ url: trickyUrl, authenticated: true }); + + const logout = await run8cli(['--url', trickyUrl, 'auth', 'logout']); + expect(logout.json).toMatchObject({ deletedApiKey: true }); + }); + + it('sees a non-zero exit from security -i when add-generic-password fails', async () => { + // setSecret turns a failed `security -i` into a thrown error, which assumes + // the real CLI signals failure with a non-zero exit. A duplicate item without + // -U is a deterministic failure, so prove that assumption here rather than + // only against a mocked execFileSync. + const account = `fail-${randomBytes(4).toString('hex')}`; + await execa('security', ['delete-generic-password', '-s', SCRATCH_SERVICE, '-a', account], { + reject: false, + }); + await execa('security', [ + 'add-generic-password', + '-s', + SCRATCH_SERVICE, + '-a', + account, + '-X', + '00', + ]); + + const duplicate = `add-generic-password -s "${SCRATCH_SERVICE}" -a "${account}" -X "00"`; + const result = await execa('security', ['-i'], { + input: `${duplicate}\n`, + reject: false, + }); + + expect(result.exitCode).not.toBe(0); + expect(`${result.stdout}\n${result.stderr}`).toMatch(/already exists/); + + await execa('security', ['delete-generic-password', '-s', SCRATCH_SERVICE, '-a', account], { + reject: false, + }); + }); }); diff --git a/test/keychain-macos.test.ts b/test/keychain-macos.test.ts new file mode 100644 index 0000000..d76c99e --- /dev/null +++ b/test/keychain-macos.test.ts @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: 2026 Qodeca sp. z o.o. + +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { MAX_LINE_BYTES, setSecret } from '../src/keychain/macos.js'; + +const { execFileSyncMock } = vi.hoisted(() => ({ execFileSyncMock: vi.fn() })); + +vi.mock('node:child_process', () => ({ execFileSync: execFileSyncMock })); + +const ACCOUNT = 'https://n8n.example.com/api-key'; + +interface SpawnCall { + command: string; + args: string[]; + input: string; +} + +/** The single `security` invocation `setSecret` is expected to make. */ +function spawnCall(): SpawnCall { + expect(execFileSyncMock).toHaveBeenCalledTimes(1); + const [command, args, options] = execFileSyncMock.mock.calls[0] as [ + string, + string[], + { input?: string }, + ]; + return { command, args, input: options.input ?? '' }; +} + +/** The value `security` will store, decoded from the `-X` hex payload on stdin. */ +function storedValue(input: string): string | undefined { + const hex = input.match(/-X "([0-9a-f]*)"/)?.[1]; + return hex === undefined ? undefined : Buffer.from(hex, 'hex').toString('utf8'); +} + +describe('macos keychain setSecret', () => { + beforeEach(() => { + execFileSyncMock.mockReset(); + execFileSyncMock.mockReturnValue(Buffer.from('')); + }); + + // Regression: src/keychain/macos.ts used to spawn + // `security add-generic-password -s 8cli -a -w -U`, so the + // secret sat in the argument list and any local process could read it from + // the process table. Putting the value back into argv makes this test fail on + // the assertion below. + it('never puts the secret in the spawned arguments', () => { + const secret = 'INSECURE-TEST-ONLY-api-key'; + + setSecret(ACCOUNT, secret); + + const { command, args } = spawnCall(); + expect(command).toBe('security'); + expect(args.join(' ')).not.toContain(secret); + expect(JSON.stringify(args)).not.toContain(secret); + }); + + it('keeps the secret out of argv for a value with shell- and argv-hostile bytes', () => { + const secret = 'pässwörd with "quotes", \\backslashes\\ and\nnewlines'; + + setSecret(ACCOUNT, secret); + + const { args } = spawnCall(); + expect(args.join(' ')).not.toContain(secret); + expect(args.join(' ')).not.toContain('pässwörd'); + expect(args.join(' ')).not.toContain('newlines'); + }); + + it('still stores the exact value, handed to security on stdin', () => { + const secret = 'pässwörd with "quotes", \\backslashes\\ and\nnewlines'; + + setSecret(ACCOUNT, secret); + + const { input } = spawnCall(); + expect(storedValue(input)).toBe(secret); + expect(input).toContain(`-a "${ACCOUNT}"`); + expect(input).toContain('-U'); + expect(input).toContain('-X '); + }); + + it('round-trips an empty secret', () => { + setSecret(ACCOUNT, ''); + + const { input } = spawnCall(); + expect(storedValue(input)).toBe(''); + }); + + it('round-trips a value longer than the 128-byte interactive prompt buffer', () => { + const secret = 'k'.repeat(300); + + setSecret(ACCOUNT, secret); + + expect(storedValue(spawnCall().input)).toBe(secret); + }); + + it('refuses an account name that would split the stdin command line', () => { + expect(() => setSecret('https://n8n.example.com/a\nb/api-key', 'secret')).toThrow( + /account name contains a newline/, + ); + expect(execFileSyncMock).not.toHaveBeenCalled(); + }); + + it('refuses a value whose command line would overflow the security input buffer', () => { + expect(() => setSecret(ACCOUNT, 'k'.repeat(4000))).toThrow( + /value is too long for the security CLI/, + ); + expect(execFileSyncMock).not.toHaveBeenCalled(); + }); + + // Regression: src/keychain/macos.ts measured the command line with + // `command.length`, which counts UTF-16 code units. 'é' is two UTF-8 bytes + // but one code unit, so an account made of them read as well under the limit + // while the bytes `security -i` actually reads overflowed its 4096-byte + // buffer and split the line. Measuring bytes makes this throw before spawn. + it('refuses a multi-byte account whose code-unit length fits but byte length does not', () => { + const account = `https://n8n.example.com/${'é'.repeat(2000)}/api-key`; + let message = ''; + try { + setSecret(account, ''); + } catch (err) { + message = err instanceof Error ? err.message : String(err); + } + expect(message).toMatch(/value is too long for the security CLI/); + expect(message).not.toContain(account); + expect(execFileSyncMock).not.toHaveBeenCalled(); + }); + + it('accepts an ASCII line exactly at the byte limit and refuses one byte more', () => { + // Measure the real line `setSecret` emits for a plain ASCII account, so the + // boundary is derived from the production format rather than a copy of it. + setSecret('a', ''); + const overhead = Buffer.byteLength(spawnCall().input, 'utf8') - 'a'.length; + execFileSyncMock.mockClear(); + + const maxAccount = 'a'.repeat(MAX_LINE_BYTES - overhead); + setSecret(maxAccount, ''); + expect(Buffer.byteLength(spawnCall().input, 'utf8')).toBe(MAX_LINE_BYTES); + + execFileSyncMock.mockClear(); + expect(() => setSecret(`${maxAccount}a`, '')).toThrow(/value is too long for the security CLI/); + expect(execFileSyncMock).not.toHaveBeenCalled(); + }); + + it('reports the rejected value size in UTF-8 bytes, not code units', () => { + const value = 'é'.repeat(4000); // 4000 code units, 8000 UTF-8 bytes + let message = ''; + try { + setSecret(ACCOUNT, value); + } catch (err) { + message = err instanceof Error ? err.message : String(err); + } + expect(message).toContain('(8000 bytes)'); + expect(message).not.toContain(ACCOUNT); + expect(message).not.toContain(value); + expect(execFileSyncMock).not.toHaveBeenCalled(); + }); + + it('reports a keychain failure without echoing the secret', () => { + execFileSyncMock.mockImplementation(() => { + throw new Error('Command failed: security -i'); + }); + + expect(() => setSecret(ACCOUNT, 'INSECURE-TEST-ONLY-failing-key')).toThrow( + /Failed to store secret in keychain/, + ); + const { args } = spawnCall(); + expect(args.join(' ')).not.toContain('INSECURE-TEST-ONLY-failing-key'); + }); +});