Isolate wallet secrets, add withdrawal idempotency, validate CORS origins - #1007
Open
victorisiguzoruzoma874 wants to merge 1 commit into
Conversation
…gins Closes kellymusk#981, kellymusk#982, kellymusk#983. - kellymusk#981: Split the wallet row shape in two. Wallet (Serialize, API-facing) documents that secret_key_encrypted must never be added to it. A new WalletSecretRow (no Serialize derive — the compiler rejects Json(..) on it outright) carries the encrypted seed for the one sanctioned accessor, services::wallets::wallet_secret_by_id, intended for the blockchain module only. Every existing wallet-returning query already named columns explicitly (no SELECT *); this closes the gap for future code that needs the secret. - kellymusk#982: POST /withdraw accepts an optional Idempotency-Key header (new migration: withdrawals.idempotency_key, unique per merchant). A resubmission with the same key returns the original withdrawal instead of creating a second one and debiting the balance twice. A check-then-insert race (two concurrent requests with a fresh key) is closed by catching the UNIQUE_VIOLATION on insert and re-reading instead of erroring. Documented in API.md and openapi.yaml. - kellymusk#983: CORS_ALLOWED_ORIGINS is now validated at startup — each origin must parse as a URL with an http/https scheme and a host, no path/query, and `*` is rejected outright (this API sends credentials). A bad value now fails AppConfig::from_env() with a clear message instead of surfacing later as a confusing HeaderValue parse panic in main.rs. Also fixes the same pre-existing extractor.rs compile break described in earlier PRs on this repo (ApiError gained a `field` member; two call sites weren't updated), needed for this branch to build.
|
@victorisiguzoruzoma874 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
Closes #981
closes #982
closes #983
walletstablesecret_key_encryptedcolumn is never exposed via API but is in the DB row #981 — Split the wallet row shape in two.Wallet(Serialize, API-facing) documents thatsecret_key_encryptedmust never be added to it. A newWalletSecretRow(noSerializederive — the compiler rejectsJson(..)on it outright) carries the encrypted seed for the one sanctioned accessor,services::wallets::wallet_secret_by_id, intended for the blockchain module only. Every existing wallet-returning query already named columns explicitly (noSELECT *); this closes the gap for future code that needs the secret.POST /withdrawto prevent double-submit withdrawals #982 —POST /withdrawaccepts an optionalIdempotency-Keyheader (new migration:withdrawals.idempotency_key, unique per merchant). A resubmission with the same key returns the original withdrawal instead of creating a second one and debiting the balance twice. A check-then-insert race (two concurrent requests with a fresh key) is closed by catching theUNIQUE_VIOLATIONon insert and re-reading instead of erroring. Documented inAPI.mdandopenapi.yaml.CORS_ALLOWED_ORIGINSparsing trims whitespace but does not validate that each value is a valid origin #983 —CORS_ALLOWED_ORIGINSis now validated at startup — each origin must parse as a URL with an http/https scheme and a host, no path/query, and*is rejected outright (this API sends credentials). A bad value now failsAppConfig::from_env()with a clear message instead of surfacing later as a confusingHeaderValueparse panic inmain.rs.Also fixes the same pre-existing
extractor.rscompile break described in earlier PRs on this repo (ApiErrorgained afieldmember; two call sites weren't updated), needed for this branch to build.Test plan
cargo checkpasses clean (only pre-existing warnings).