refactor: guard callback routes with reusable middleware that checks the payment processor#597
Conversation
🦋 Changeset detectedLatest commit: 29bfef5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a6da7c6 to
ca9454e
Compare
ca9454e to
4a932d4
Compare
| const requireProcessor = (name: string) => | ||
| (_req: Request, res: Response, next: NextFunction) => { | ||
| const settings = createSettings() | ||
| if (settings.payments?.processor !== name) { |
There was a problem hiding this comment.
should we also check here if payments are enabled, not just which processor is configured?
There was a problem hiding this comment.
should we also check here if payments are enabled, not just which processor is configured?
Hi @cameri , this PR #616 addresses your comment .requireProcessor now checks payments.enabled before the processor name. Also fixed the OpenNode integration test setup (it was missing callbackBaseURL, so all 4 scenarios were silently returning 500).
|
PR title does not quite match the change: callbacks are always registered, but guarded by a reusable middleware that checks the payment processor is configured before allowing the request. |
Description
The
/callbacks/opennode,/callbacks/lnbits, and/callbacks/zebedeeroutes were always registered regardless of which payment processor was active. Each controller then had to checksettings.payments.processorand return 403 if it didn't match.This PR moves that check to the route layer so each route is now only registered when its processor is the configured one, the same way
/callbacks/nodelessworks after #584.Related Issue
Follows up on #584 (as approved by @cameri).
Motivation and Context
The in-controller processor check was redundant , if a route isn't registered, it can't be hit. Keeping dead routes open is unnecessary exposure, and the scattered
paymentProcessor !== 'x'checks were noise that could easily be missed when reading the controller logic.How Has This Been Tested?
test/unit/routes/callbacks.spec.tsto stubcreateSettingsso the OpenNode route registers correctly during the testScreenshots (if appropriate):
N/A
Types of changes
Checklist: