Ensure Gateway ID validation consistency in ProcessWebhook
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start with payment/service.go, focusing on ProcessWebhook and its transaction block around lines 278–323; compare its gateway checks with the ValidateReference flow. Run the relevant payment tests and add coverage for a webhook whose gateway ID differs from the stored transaction. Done when mismatched gateways cannot change transaction state and the tests pass.
Written by the indexing model from the issue text.
Description
Issue: Missing Gateway Validation in Webhook Processing
Description
In the payment package, incoming webhook requests are processed via the ProcessWebhook method in payment/service.go. Currently, this method retrieves a transaction using only the parsed reference number from the webhook payload. However, it does not verify that the transaction's stored GatewayID matches the gatewayID parameter provided in the URL route (/api/v1/payments/:gatewayID/webhook).
This omission allows one payment gateway (or any client spoofing that gateway's route) to potentially alter or settle transaction records belonging to another gateway, creating a data integrity risk and security vulnerability.
Similar validation is correctly performed in the ValidateReference flow (used for real-time reference checking).
Impact
- Cross-Gateway Mutation: A webhook routed to
/api/v1/payments/gateway-a/webhookcould succeed in marking a transaction as successful even if that transaction was initialized undergateway-b. - Security & Auditing: Weakens the separation of duties and trust boundaries between different payment providers.
Code References
- Target File: service.go
- Location: Inside the repository transaction block in
ProcessWebhook: service.go#L278-L323
Proposed Solution
Add a validation check inside the RunInTransaction block in ProcessWebhook to ensure the gateway identifiers match before modifying the transaction state.
// Inside ProcessWebhook in service.go
err = s.repo.RunInTransaction(ctx, func(repo PaymentRepository) error {
tx, err := repo.GetByReferenceNumberForUpdate(ctx, gwPayload.ReferenceNumber)
if err != nil {
return fmt.Errorf("failed to retrieve transaction by reference: %w", err)
}
if tx == nil {
return fmt.Errorf("reference %s: %w", gwPayload.ReferenceNumber, ErrTransactionNotFound)
}
// NEW VALIDATION: Ensure the webhook matches the gateway configured for this transaction
if tx.GatewayID != gatewayID {
return fmt.Errorf("gateway mismatch for transaction %s: expected %s, got %s: %w",
tx.ReferenceNumber, tx.GatewayID, gatewayID, ErrTransactionNotFound)
}
// ... existing status and amount checks ...
})
By returning ErrTransactionNotFound (or a similar error), the HTTP handler will return a 404 Not Found (or 422 Unprocessable Entity), signaling to the gateway to stop retrying the mismatched payload.
- Dominant language
- Go
- Stars
- 6
- Forks
- 8
- Avg merge
- 21h 36m
- Merged PRs (30d)
- 42
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OpenNSW/core
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
payment: test fixtures hardcode real gateway names (govpay/lankapay) instead of generic placeholdersOpen
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
nsw-sl cleanup Type/Improvement
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
remote: let the host inject a logger, and log with one consistent policyPossibly taken @mushrafmim claimed this 5 days ago. OpenType/Improvement
Difficulty 4/5 3-5 days Newbie friendliness 22/100
Maintainers usually reply within 1 day
-
taskflow: run extensions through one dispatcher and tell them which phase they run inPossibly taken @mushrafmim claimed this 11 days ago. OpenType/Improvement
Difficulty 4/5 3-5 days Newbie friendliness 22/100
Maintainers usually reply within 1 day
Similar issues
-
☢️ Bug v3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
area/import-export area/projects concern/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
go-vikunja/vikunja#4455 · 1 comment ·
Maintainers usually reply within 2 days
-
Dependabot PRs no longer merge automaticallyPossibly taken @dwisiswant0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/urlfinder#160 ·
Maintainers usually reply within 1 day
-
database
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
chnm/legal-modernism#450 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day