fix(security): rework #2 — remove credential-to-disk leak; lock attestation-before-spend#14
Draft
shroominic wants to merge 7 commits into
Draft
fix(security): rework #2 — remove credential-to-disk leak; lock attestation-before-spend#14shroominic wants to merge 7 commits into
shroominic wants to merge 7 commits into
Conversation
Previously attestation happened AFTER _spendToken(), meaning if attestation failed the user lost their tokens with no refund. Now attestation runs first — if it throws, no tokens are spent. - Added _getAttestationAuth() helper that gets auth headers without the main spend (key lookup for apikeys, minimal spend for xcashu) - xcashu mode reuses the attestation spend token for the actual request to avoid a double spend - Both fetchAIResponse() and _prepareRoutedRequest() restructured to do E2EE attestation before _spendToken() - Updated VeniceImpl.md to document the new ordering guarantee
…e-spend Reworks PR #2 (Venice E2EE attest-before-spend). Two certain, provable fixes; deliberately leaves the double-spend payment-amount design to the author. Credential leak (FIXED): _storeRequest() dumped FULL request headers (live X-Cashu cashu tokens AND Authorization: Bearer api keys) to reqs/req-*.json on every request; reqs/ was not gitignored. Removed _storeRequest entirely, its call in _makeRequest, and the now-unused fs/path imports. Added reqs/ to .gitignore as defense in depth. Attestation-before-spend (LOCKED): the requiredSats main spend already runs only after prepareE2EERequest() (which fetches+verifies the Venice attestation). Added a regression test asserting the 50-sat request spend never precedes attestation verification. Test wiring: added vitest devDep + "test" script. Tests: - pr2_storeleak.test.ts: asserts NO reqs/*.json written and no live token on disk (reproduced the leak pre-fix; passes now). - pr2_spend_ordering.test.ts: (b) ordering invariant passes; (c) a clearly labeled CHARACTERIZATION test documenting the still-open double-spend (1-sat attestation spend, unconsumed, + 50-sat request spend). NOT fixed (left for author, not verifiable here): whether to reuse the attestation's 1-sat spend token for the request vs keep a separate paid attestation. Depends on Venice's attestation-endpoint payment model. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
wrong branch, do a PR to the feat/venice-integration branch instead. |
The sdk#14 rework removed the _storeRequest disk dump, but the red-team found additional ways a live X-Cashu spend token could leak to logs/disk. This closes them and adds a regression test. 1) RoutstrClient._makeRequest logged the FULL headers object (incl. the live X-Cashu token) and the whole Response at DEBUG. Now logs only Object.keys(headers) and response.status — never header VALUES. 2) scripts/routstr-daemon.ts: deleted the dead saveRequestBody() (which wrote full headers incl. Authorization/X-Cashu to reqs/*.json), plus the now-unused ensureRequestsDir/REQUESTS_DIR and writeFile/mkdir/join imports. One uncomment away from re-leaking. 3) routeRequests.ts: debugLevel was destructured but never applied (dead API; the daemon passes debugLevel:"DEBUG"). Wired it via client.setDebugLevel(debugLevel) — smaller correct change than ripping it out of the interface + caller. Also: the regression test surfaced a 4th vector — several _spendToken / _handleErrorResponse "token preview" logs printed the FULL token/api-key value. Added a _tokenPreview() redactor (prefix + length only) and routed every such site through it. Regression test pr2_headerlog_leak.test.ts runs a real xcashu request at DEBUG, spies on every console sink, and asserts the live token value never reaches console output. Existing pr2_storeleak / pr2_spend_ordering tests remain green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Update (
|
Contributor
|
AI slop PRs are not allowed on this repo, especially when the sloperator doesn't read maintainer left comments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reworks #2. Opened as a DRAFT — it deliberately leaves one money-path design decision to the author (below). It is branched from #2's head, so like #2 it needs rebasing onto current
mainbefore merge.Fixed (provable, with tests)
_storeRequest()wrote the full request headers — liveX-Cashucashu tokens andAuthorization: BearerAPI keys — toreqs/req-*.jsonviaJSON.stringifyon every request (all models/modes), andreqs/was not gitignored. Removed_storeRequest, its call in_makeRequest, and the now-unusedfs/pathimports; addedreqs/to.gitignoreas defense in depth. Regression test (pr2_storeleak.test.ts) asserts noreqs/*.jsonis written and no token reaches disk — it reproduced the leak against the pre-fix source, and passes after the fix.requiredSatsmain spend already runs only afterprepareE2EERequest()fetches and verifies the Venice attestation. Added a test (pr2_spend_ordering.test.ts) asserting the request-amount spend never precedes attestation verification.isE2EEModelgate and the vitest wiring (added the missingvitestdevDep +testscript so the suite actually runs).Deliberately NOT fixed — needs the author's decision (money path)
An e2ee xcashu request currently fires two spends: a 1-sat attestation spend in
_getAttestationAuthwhose returned token is never consumed, then the fullrequiredSatsspend. A clearly-labeled[characterization]test documents this so it stays visible. Resolution depends on Venice's attestation-endpoint payment model, which is not verifiable from this repo, so it was not guessed:attestAuth.spendResultthrough and skip the second_spendToken(requiredSats)(or spend only the remainder). Correct iff the attestation endpoint debits from / can be applied to the same balance as the completion call (matches thee2eeSpendResultternary sketched inVeniceImpl.md). Risk if wrong: underpayment / rejected completion./tee/attestationindependently. Risk if wrong: a silent 1-sat-per-request overcharge.Pick A or B based on Venice's billing, then update the characterization test (it's designed to fail once the double-spend is resolved).
Verification
vitest run(the 3 new tests) → 3 passed;pnpm run build(tsup) → success;typecheckclean inclient/(only pre-existingscripts/*errors). The 8 full-suite failures are the pre-existingbetter-sqlite3native-binding issue (Node v26), unrelated to this change.🤖 Generated with Claude Code