[SEC-14] Security audit: x402 anti-replay never uses PostgreSQL (useDatabase always false) (#245)#299
Open
GEEKYFOCUS wants to merge 1 commit into
Open
Conversation
Confirm useDatabase is never enabled; replay protection stays in-memory only, allowing XDR reuse after restarts and across API replicas. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@GEEKYFOCUS Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Security audit report for issue #245 ([SEC-14] Anti-replay de x402 nunca usa la DB).
Finding: CONFIRMED (Medium severity)
The x402 anti-replay mechanism in
apps/api/src/middleware/x402.tshas two code paths — PostgreSQL (isPaymentUsed/markPaymentUsed) and an in-memorySet(usedTxHashes) — selected by auseDatabaseflag. Static analysis confirms:useDatabaseis declaredfalseat line 18 and never reassigned anywhere in the repository.ensureX402Initialized()successfully callsinitX402Tables()but does not setuseDatabase = true.DATABASE_URLindocker-compose.yml) andx402_paymentstables exist.This report is audit-only — no application or backend code changes, per issue requirements.
Report location
docs/security-reports/SEC-14-x402-replay-sin-db.mdKey answers (from issue template)
Setis lost on restartuseDatabaseever activated?SetReproducible on testnet
Yes — documented reproduction steps include same-process replay block, post-restart replay acceptance, and multi-instance bypass. Impact is amplified when combined with SEC-13 (XDR accepted without on-chain settlement).
Suggested fix (documented only, not implemented)
Set
useDatabase = trueafter successfulinitX402Tables(), add production fail-closed behavior, env flag for explicit store selection, and regression tests for DB-backed replay.Test plan
apps/api/src/middleware/x402.tsandapps/api/src/db/x402.tsgrepconfirmsuseDatabasehas a single assignment (false) and no reassignmentsdocker-compose.ymlprovidesDATABASE_URLbut middleware ignores DB pathx402.test.ts— no replay or DB persistence coveragedocker compose upto confirm post-restart replayCloses #245 (report delivery)