fix: require shared secret for withdraw endpoint (#29) - #30
Open
erhnysr wants to merge 1 commit into
Open
Conversation
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.
Problem
POST /api/gateway/withdrawhas no authentication. It moves the seller's Gateway balance usingSELLER_PRIVATE_KEYand accepts an arbitrarydestinationAddress, so anyone who can reach the endpoint can drain the seller's funds to their own wallet:Fix
Adds an optional shared-secret guard in
app/api/gateway/withdraw/route.ts, right after theSELLER_PRIVATE_KEYcheck. WhenWITHDRAW_SECRETis set, every request must present a matchingx-withdraw-secretheader or it is rejected with401 Unauthorized:The guard is opt-in so it does not break the existing demo flow when the secret is unset — but the default is now documented as unsafe for production, giving operators a clear, secure path.
Why not wire the secret through the frontend?
The only caller is
components/dashboard/withdraw-dialog.tsx, a client component running in the browser. Injecting the secret there would requireNEXT_PUBLIC_, which ships it in the client bundle and defeats the purpose. This guard is therefore intended for server-to-server or env-gated use; the README recommends calling the endpoint from a trusted server-side context for hosted deployments. There is no existing session/auth middleware in the repo to reuse.Changes
app/api/gateway/withdraw/route.ts— optionalx-withdraw-secretguard.env.example—WITHDRAW_SECRET=with a warning that leaving it unset exposes the endpointREADME.md— "Protecting the withdraw endpoint" note under Security & Usage ModelTesting
npm run buildpasses (route compiles and builds; the endpoint is server-rendered on demand).Closes #29