76 KiB
phase, reviewed, depth, files_reviewed, files_reviewed_list, findings, resolved, partly_resolved, status, parts, note, first_reviewed, rereview_note
| phase | reviewed | depth | files_reviewed | files_reviewed_list | findings | resolved | partly_resolved | status | parts | note | first_reviewed | rereview_note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 18-payment-gateway | 2026-10-13T22:33:10Z | standard | 110 |
|
|
1 | 1 | issues_found |
|
Reviewed after push and tag v0.1.25 (advisory). Paths are relative to summercms.go; ../ marks sibling repos. Part B finding paths are relative to sm-paymentgateway-plugin. | 2026-10-13T16:00:36Z | Incremental re-review after gap-closure plan 18-08 (../sm-pgstripe-plugin d488834..0313820, seven files). The findings counts are the findings still open or partly open. resolved (A-CR-01) is not in them. partly_resolved (A-CR-02) is counted in critical. Findings on files outside the seven are carried over unchanged and were not re-judged. The Docker-backed TestHostStripeFlow was read, not run. |
Phase 18 code review
Two parallel standard-depth reviews over 106 source files. Part A: framework (cabana, pact, admin SPA), sm-pgstripe-plugin and vue-paymentgateway-layer. Part B: sm-paymentgateway-plugin.
| Part | Critical | Warning | Info | Resolved |
|---|---|---|---|---|
| A | 2 | 11 | 15 | 1 |
| B | 4 | 10 | 13 | 0 |
The table counts the findings that are open or partly open after the 18-08 re-review. The first review counted A 3 / 10 / 8 and B 4 / 10 / 13 (48 findings).
Re-review after 18-08
Re-reviewed: 2026-10-13T22:33:10Z
Scope: gap-closure plan 18-08, git -C ../sm-pgstripe-plugin diff d488834..0313820 (commits 0c4fde7, f5c10e8, be75108, 0313820), seven files
Depth: standard
This is an incremental update of the full-phase review below, not a new review of the phase.
Re-read in full at 0313820, together with the diff: ../sm-pgstripe-plugin/webhook.go, operator.go, browser_return.go, host_test.go, operator_test.go, webhook_test.go and README.md. The three test files and the README are new in files_reviewed_list (106 to 110 files).
Read for tracing only, not reviewed: ../sm-pgstripe-plugin/client.go, stripefake_test.go, plugin.go:60-70 and lang/*/lang.yaml:30; in ../sm-paymentgateway-plugin (at f55320a, clean tree) payments/notification.go, payments/service.go:95-456, payments/machine.go, fsm/fsm.go:63-88, models/payment.go, api/actions.go:340-388, console/pg_cancel_sent_payments.go, schedule.go and the timeout rule in models/settings.go; in the framework modules/sunscreen/sunscreen.go and internal/build/build.go:105-112.
Not re-read: everything else. All Part B findings, and the Part A findings on the framework, the admin SPA, the Nuxt layer and the other pgstripe files (A-CR-03, A-WR-06 to A-WR-10, A-IN-03, A-IN-05, A-IN-07, A-IN-08), are carried over exactly as written and were not re-judged.
Commands run in ../sm-pgstripe-plugin at 0313820: go vet ./... (exit 0) and go test -count=1 -short ./... (ok). The three new Docker-free subtests pass: TestStripeOperator/a_declined_attempt_is_logged_and_never_rejected, TestStripeOperator/expired_sessions_and_canceled_intents_change_nothing and TestStripeWebhook/last_payment_error_decodes_its_codes. TestHostStripeFlow needs Docker and was not run, as instructed, so every statement about host_test.go comes from reading it together with the Stripe fake.
Existing findings on the seven files
| Finding | Status after 18-08 | Commit | Checked by |
|---|---|---|---|
| A-CR-01 | resolved | 0c4fde7 |
reading, unit subtest run |
| A-CR-02 | partly resolved (still counted as critical) | f5c10e8 |
reading |
| A-WR-01 | unchanged | reading | |
| A-WR-02 | unchanged | reading | |
| A-WR-03 | unchanged | reading | |
| A-WR-04 | unchanged | reading | |
| A-WR-05 | unchanged | reading | |
| A-IN-01 | unchanged | reading | |
| A-IN-02 | unchanged, by plan decision 3 | reading | |
| A-IN-04 | unchanged | reading | |
| A-IN-06 | unchanged (operator.go part; models/settings.go not re-read) |
reading |
Each of these findings carries a Re-review (18-08) paragraph with the details.
New findings (found in the 18-08 re-review)
No new critical finding. One warning and seven info items, all in Part A:
- A-WR-11: a payment whose asynchronous Checkout payment is still processing is canceled by the sweep, and the later success is refused.
- A-IN-09: the decline Warn line says the payment stays open whatever its state.
- A-IN-10: the refused-accept Error line is written per signal, and the success URL can repeat it.
- A-IN-11: the decline text is still logged on the purchase-time decline path.
- A-IN-12:
PaymentError.Typeis decoded and exported but nothing reads it. - A-IN-13: the
completedEventfixture names the first payment's session and intent, andpaid_after_final_stateuses it for the third purchase. - A-IN-14: test-quality notes (state assertions that cannot fail on their own, a mislabelled scenario, an untested branch).
- A-IN-15: the README and the settings page list different webhook events.
What held up
- Log content. The new Warn and Error lines carry ids, the payment state and Stripe's
codeanddecline_code.PaymentErrorhas no field for the message text, the body never reaches the logger, and no e-mail or key material is in reach ofattemptFailedorrefusedAccept. Two things to know: the payment uuid is new in log lines, and it is all a caller needs for the unauthenticated browser return (which changes state only after re-checking at Stripe);decline_codevalues such asinsufficient_fundsare tied to a payment and through it to a user, so the log's retention should allow for that. - Redaction. None of the new attribute keys (
payment,uuid,state,event,intent,session,code,decline_code) is on sunscreen's redaction list, so the ids needed to find the charge reach the production log. - Logger capture. The generated
maincallssunscreen.InstallDefaultbeforeparty.Activate, so theslog.Default()the operator takes at activation is the application's handler. - Row lock.
attemptFailedandrefusedAcceptrun inside the route's transaction on the payment row lockedFOR UPDATE, read the state of that locked row and add no query, write or Stripe call. Lock hold time and lock order are as before (A-WR-05 and B-WR-05 stand as written). - Proof method of the decline unit test. Its control case (
operator_test.go:442-447) shows that a rejecting event fails without a payment service, so the nil error of the decline does prove that no transition was attempted.
Part A
Phase 18: Code Review Report (part A)
Reviewed: 2026-10-13T12:00:00Z Depth: standard Files Reviewed: 47 Status: issues_found
Re-review (18-08): 51 files after the re-review added host_test.go, operator_test.go, webhook_test.go and README.md of sm-pgstripe-plugin. The second paragraph of the summary below describes the code before 18-08; see the re-review paragraphs of A-CR-01 and A-CR-02 for the current state.
Paths without ../ are relative to summercms.go/. Paths with ../ are the sibling repos sm-pgstripe-plugin and vue-paymentgateway-layer.
Summary
The review covered three areas: the cabana money field, write-only settings secrets and method-backed dropdowns; the Stripe operator (webhook signatures, idempotency, browser return, refunds, amount conversion); and the Nuxt layer's auth token and redirect handling. Signature verification itself is sound: webhook.ValidatePayload runs on the raw bytes before any lookup, the browser return never accepts from request input, and secrets never reach JSON (json:"-", withoutSecrets, redacting MarshalJSON). The auth token goes only into an Authorization: Bearer header and never into a query or cookie.
The serious problems are in the payment state handling around Stripe. A payment_intent.payment_failed event moves the payment to a final Rejected state even though Stripe lets the customer retry the same PaymentIntent or Checkout Session. If the customer then pays, Stripe takes the money and the local payment stays rejected. accept also drops any "paid" signal for a Rejected or Canceled payment without a log line, so these cases cannot even be found afterwards. The admin money input reads a comma as the decimal separator in every locale, so an English-locale admin who types 1,234 saves 1.234. Smaller issues: key selection depends on the active mode, amounts are rounded for non-two-decimal currencies, the refund has no idempotency key, and Stripe is called while the row lock is held.
Tracing note: the Stripe operator runs inside sm-paymentgateway-plugin/payments/notification.go. That file was read for context (lock, ErrNotificationIgnored → 200, Enabled gate) but is outside this part's scope.
Critical Issues
A-CR-01: payment_intent.payment_failed rejects a payment the customer can still complete, so a paid order stays Rejected
File: ../sm-pgstripe-plugin/webhook.go:161-162 (also webhook.go:136, doc comment)
Issue: handleEvent maps payment_intent.payment_failed to o.reject. In Stripe this event fires on every failed attempt, for example a card decline inside Checkout or a failed confirmCardPayment in PaymentIntent mode. The PaymentIntent returns to requires_payment_method, and the customer can retry on the same Checkout page or with the same client secret. Reject is final (payments/machine.go: Rejected is in PaymentFinalStates, and Accept is allowed only from Created or Sent). So the sequence is: decline, webhook, payment Rejected (order mail and events fire), customer retries, payment succeeds, checkout.session.completed or payment_intent.succeeded arrives, Can(Accept) returns false, and the event is a silent no-op. Stripe has captured the money while the order is Rejected. The PHP operator (Golem15\PGStripe\Operators\Stripe) never rejected on a failure event. This behavior is new in the port. Both PaymentIntent metadata (PaymentIntentData.Metadata at operator.go:181-183) and paymentMetadata carry payment_uuid, so the failure event always resolves to the payment.
Fix: Do not treat payment_intent.payment_failed as terminal. Log it and leave the payment Sent. Reject only on terminal signals: checkout.session.async_payment_failed, checkout.session.expired, and payment_intent.canceled.
case EventPaymentIntentPaymentFailed:
// Not terminal: the intent returns to requires_payment_method and the
// customer may retry on the same Checkout page or card form.
o.logger.Warn("golem15.pgstripe: payment attempt failed", "event", ev.ID, "payment", pc.Payment.ID)
return nil
Re-review (18-08): resolved by 0c4fde7 (sm-pgstripe-plugin). handleEvent gives payment_intent.payment_failed its own case, which calls attemptFailed and returns nil (webhook.go:189-191); attemptFailed only logs (webhook.go:200-216). o.reject( has one call site left, checkout.session.async_payment_failed (webhook.go:185-186). Checked by reading the code and by running TestStripeOperator/a_declined_attempt_is_logged_and_never_rejected, which passes. TestHostStripeFlow/decline_then_succeed, /decline_then_succeed_payment_intent and /event_table assert the end-to-end outcome (payment Sent after the decline, order Paid after the retry); they were read, not run. The second half of the fix above (reject on checkout.session.expired and payment_intent.canceled) was not taken, by plan decision 3; that part is tracked under A-IN-02. Related new findings: A-WR-11 and A-IN-09.
A-CR-02: A "paid" signal for a Rejected or Canceled payment is dropped silently (no log, no refund, Checkout Session left open after a cancel)
File: ../sm-pgstripe-plugin/operator.go:439-442, ../sm-pgstripe-plugin/browser_return.go:60-69
Issue: accept returns nil when Can(Accept) is false. That is correct for a replay of an already Accepted payment. It also covers a payment that Stripe reports as paid while the local state is Rejected (A-CR-01) or Canceled. The customer API allows cancel on an AwaitingPayment order (api/order_json.go:162, api/actions.go:366-384), and that cancels the Sent payment. The Stripe Checkout Session the customer has open stays payable for up to 24 h, because nothing expires it. If the customer pays it, the webhook and the browser return both reach accept, see Can=false, and return 200 with no log line. The money is captured, the order is Canceled, and nothing records it.
Fix: In accept, tell a replay (pc.Payment.State == Accepted) apart from a paid-at-Stripe payment in any other final state. For the second case, log at Error level with the payment id, event id and PaymentIntent id, and fire an event or admin notice (or refund automatically). Also expire the stored Checkout Session (client.V1CheckoutSessions.Expire) when a Stripe payment is canceled, through a PaymentCanceled listener in the plugin.
ok, err := svc.Can(ctx, pc.Tx, pc.Payment, pgmodels.PaymentTransitionAccept)
if err != nil { return err }
if !ok {
if pc.Payment.State != pgmodels.PaymentStateAccepted {
o.logger.Error("golem15.pgstripe: Stripe reports the payment paid but its state refuses Accept; manual refund needed",
"payment", pc.Payment.ID, "state", pc.Payment.State, "intent", extra[DataPaymentIntentID])
// optionally: record the data and fire a dedicated event
}
return nil
}
Re-review (18-08): partly resolved by f5c10e8 (sm-pgstripe-plugin). Checked by reading; TestHostStripeFlow/paid_after_final_state was read, not run.
Resolved: accept now calls refusedAccept when Can(Accept) is false (operator.go:447-454). For every state except Accepted and Refunded, refusedAccept writes an Error record with the payment id, uuid, state, the event id or browser_return, the PaymentIntent id and the stored session id (operator.go:484-501). The browser return passes its own trigger (browser_return.go:71). A paid signal for a Rejected or Canceled Stripe payment is no longer dropped without a trace.
What remains:
- Nothing prevents the charge. No code expires the Checkout Session or cancels the PaymentIntent when a payment is canceled: there is no
V1CheckoutSessions.Expirecall and noPaymentCanceledlistener in the plugin. A Checkout Session expires at Stripe 24 h after creation (the code sets noexpires_at). A PaymentIntent inrequires_payment_methodhas, as far as I know, no expiry of its own, so in PaymentIntent mode a payment canceled by the sweep stays payable with its client secret; confirm this against Stripe's documentation. - The log line is the only signal. No event, admin notice, stored marker or refund follows (plan decision 5). The line is written per signal, not per payment (A-IN-10).
- The customer-cancel scenario described above does not reach the new line.
api/actions.go:361-365of sm-paymentgateway-plugin (read for tracing) skips payments whose operator mode is not cash or manual, soPOST /orders/{hash}/cancelcancels the order and leaves the Stripe payment Sent. A later paid signal passesCan(Accept), the payment becomes Accepted and the outcome is the one of B-WR-06 and B-CR-02 (gateway, not re-read). The sentence "that cancels the Sent payment" in the issue text holds for cash and manual payments only. The payments that do reachrefusedAcceptare those canceled bypg:cancel-sent-paymentsor by an administrator, and those rejected bycheckout.session.async_payment_failed. - A replay is inferred from the state alone. Accepted and Refunded are silent without a comparison of the signal's PaymentIntent id with the stored
payment_intent_id(operator.go:485-488). A paid signal for a different PaymentIntent carrying the same payment uuid would be treated as a replay. I found no path in the code I read that gives one payment two payable Stripe objects; closing this is the id check A-WR-02 asks for.
The silent drop that made this finding critical is fixed, and the remainder is of the same kind as B-WR-06. It stays counted in the critical tier because this re-review does not re-grade existing findings.
A-CR-03: The admin money input reads a comma as the decimal separator in every locale, so 1,234 in en is saved as 1.234
File: admin/src/app/money.ts:39-51 (used by admin/src/components/form/fields/MoneyField.vue:169-185)
Issue: parseMoneyInput treats a single , or . as the decimal separator whatever the locale. In en, , is the grouping separator, so an administrator who types 1,234 (one thousand two hundred thirty-four) gets the canonical value "1.234". The default scale is 4, so the result is not too_precise. It is sent, accepted by the server, and saved as an amount 1000 times too small, with no error. Grouping is documented as invalid, but a single group separator is never detected. The field then shows the typed text, not the parsed value, until the page reloads.
Fix: Make the parser locale-aware. Accept the locale's decimal separator (decimalSeparator(locale)) and .. Refuse the locale's grouping separator, or refuse any d,ddd pattern with exactly three fraction digits when , is not the locale's decimal separator, as invalid.
export function parseMoneyInput(text: string, scale: number, decimal = '.'): MoneyParseResult {
// ...
const allowed = decimal === ',' ? /[.,]/g : /[.]/g
if (decimal !== ',' && body.includes(',')) return { value: null, error: 'invalid' }
// ...
}
Warnings
A-WR-01: Webhook verification, refunds and Stripe lookups always use the currently active mode's keys; the payment does not record its own mode
File: ../sm-pgstripe-plugin/client.go:51-65, ../sm-pgstripe-plugin/operator.go:286, 342, ../sm-pgstripe-plugin/browser_return.go:87
Issue: ModeKeys chooses the live or test triple from the test_mode setting at call time. After test_mode is toggled, webhooks for payments created under the other mode fail verification with a 403, so Stripe retries for 3 days and then gives up and the payments are never accepted. Refunds and browser-return lookups for those payments use the wrong secret key and fail with "No such payment_intent". Nothing in payments.data records the mode used at Purchase.
Fix: In Purchase, store the mode (stripe_mode: live|test, or Stripe's livemode) in payments.data. In Refund and paidAtStripe, choose the keys from that stored mode. In VerifyNotification, try both configured signing secrets (or decode livemode first and pick the matching secret), so a mode switch does not lose in-flight events.
Re-review (18-08): unchanged. ModeKeys is still called with the settings of the moment in Refund (operator.go:286), VerifyNotification (operator.go:342) and paidAtStripe (browser_return.go:92, formerly :87), and nothing stores the mode at Purchase. client.go is not part of the 18-08 diff. TestHostStripeFlow/wrong_secret asserts the behaviour (host_test.go:819-823: the live secret does not verify while test mode is on).
A-WR-02: Accepting an event does not check the event's amount, currency or session/intent id against the payment
File: ../sm-pgstripe-plugin/webhook.go:149-160
Issue: checkout.session.completed and payment_intent.succeeded accept the payment based only on metadata.payment_uuid or client_reference_id. amount_total / amount_received, currency, and whether data.object.id equals the stored stripe_checkout_session_id / payment_intent_id are never compared. If a second session exists for the same payment, or the order total changed after Purchase, a lower payment still accepts the order. Any other integration on the same Stripe account that reuses the payment_uuid metadata key could do the same.
Fix: Decode amount_total, amount_received and currency in EventObject. Accept only when the amount equals stripeAmount(paymentTotal(pc)), the currency matches, and the object id matches the stored id (when one is stored). Otherwise log at Error level and leave the payment unchanged.
Re-review (18-08): unchanged. The accepting cases are now at webhook.go:178-188. EventObject (webhook.go:63-73) still decodes no amount or currency, and no case compares data.object.id with the stored session or intent id. 18-08 names this missing check as its reason for not acting on checkout.session.expired (webhook.go:157-163). The new test TestHostStripeFlow/paid_after_final_state shows the effect in its part 4 (A-IN-13), and the replay classification added by 18-08 relies on the state alone (A-CR-02, remaining item 4).
A-WR-03: stripeAmount silently rounds amounts for non-two-decimal currencies
File: ../sm-pgstripe-plugin/operator.go:562-588
Issue: Zero-decimal currencies use (cents + 50) / 100, so a JPY total of 1000.50 is charged as 1001 with no error. Three-decimal currencies use Minor()*10, which rounds a scale-4 1.2345 KWD to two decimals first (charged 1.230 or 1.240). Stripe's currency docs also list UGX as a special case that must be sent as a two-decimal value (×100), but the code puts UGX in zeroDecimal, which would charge 1/100 of the amount. Please check this against Stripe's current currency table before relying on it.
Fix: Refuse an amount that the currency cannot represent exactly instead of rounding it (return an error when cents%100 != 0 for zero-decimal currencies). Compute three-decimal amounts from the scale-4 units, and refuse when the last digit is not zero. Confirm the UGX, ISK, HUF and TWD rules against Stripe's current table, and add tests for each.
Re-review (18-08): unchanged. stripeAmount is now at operator.go:620-633 with the currency tables at operator.go:607-614; UGX is still in zeroDecimal (operator.go:609). operator_test.go:304-306 asserts the rounding (500.50 JPY becomes 501).
A-WR-04: The refund has no idempotency key; a Stripe success followed by a rollback leaves the payment stuck
File: ../sm-pgstripe-plugin/operator.go:302-314
Issue: V1Refunds.Create is called inside the payment service's transaction (payments/service.go Refund). If Stripe refunds and then SaveData, the Refund transition or an event listener fails, the transaction rolls back and the payment stays Accepted. The admin's next attempt sends a new refund request, which Stripe refuses with charge_already_refunded. The payment can then never reach Refunded through the UI, even though the money has been returned. Purchase has the same weakness: a session created before a rollback is orphaned.
Fix: Set a deterministic idempotency key, for example params.SetIdempotencyKey("pgstripe-refund-" + pc.Payment.UUID). Also treat the Stripe error code charge_already_refunded as success (operators.Complete()).
Re-review (18-08): unchanged. operator.go:302-314 builds RefundCreateParams without an idempotency key and does not treat charge_already_refunded as success.
A-WR-05: An unauthenticated GET makes outbound Stripe calls while the payment row lock is held
File: ../sm-pgstripe-plugin/browser_return.go:60-69, 82-121; ../sm-pgstripe-plugin/client.go:28-33
Issue: browserReturn runs inside the route's lagoon.Transaction, after SELECT ... FOR UPDATE on the payment (and order). It calls V1CheckoutSessions.Retrieve / V1PaymentIntents.Retrieve, each with a 30 s timeout and up to 2 retries. Anyone holding the success URL (it travels in browser history and Referer) can repeat the GET to hold the lock and a database connection for tens of seconds at a time. That blocks the real webhook and every order action for that payment and uses up the connection pool.
Fix: Retrieve the Stripe object before taking the lock, or use a short dedicated timeout (for example 5 s, no retries) for the browser-return lookup. Then lock and apply only the state change. Also skip the Stripe call when the payment is already in a final state.
Re-review (18-08): unchanged. The lines are now browser_return.go:65-75 and 87-127; client.go:28-33 is not part of the 18-08 diff. One thing changed around this finding: the Stripe lookup is what produces the new Error line when the browser return finds a Canceled or Rejected payment paid (TestHostStripeFlow/paid_after_final_state, part 3). The "skip the Stripe call when the payment is already in a final state" part of the fix should therefore skip only Accepted and Refunded. Each such GET also writes one Error record (A-IN-10).
A-WR-06: Write-only secrets are stored untrimmed, and a whitespace-only value hides the env fallback
File: modules/cabana/settings_secret.go:121-138
Issue: liftSecretValues drops only "". A pasted key with a leading or trailing space, or a string of only spaces, is encrypted and stored as given. The state then reads stored, and ModeKeys (fallback, client.go:68-76) prefers it over the SUMMER_GOLEM15__PGSTRIPE__* value. Every Stripe call then fails authentication, and every webhook fails its signature check (403), with no hint in the UI.
Fix: Trim the value in liftSecretValues and treat a blank result as "keep" (delete the key), or refuse it as a 422. The import already trims (import_winter.go:261), so the form would then match it.
case string:
if strings.TrimSpace(v) == "" { delete(body, name); continue }
body[name] = strings.TrimSpace(v)
A-WR-07: moneyColumnType accepts any Scanner/Valuer struct, including sql.NullFloat64 and sql.NullString
File: modules/cabana/field_money.go:235-247
Issue: The boot gate is meant to ensure the "never parsed into a float" guarantee, but it only checks for *T implements sql.Scanner and T implements driver.Valuer. sql.NullFloat64 passes, so the decimal string is converted to float64 on Fill and on save. That breaks the exactness the field promises. sql.NullString also passes, but it marshals as {"String":..,"Valid":..}. MoneyField shows it as empty, and an unedited save sends the object back, which validateMoneyValue rejects as money.invalid (422), so the record cannot be saved without retyping the amount.
Fix: Require that the type also round-trips as a JSON string (implements json.Marshaler/encoding.TextMarshaler producing a string), or keep an explicit allowlist (string, *string, and types implementing a cabana.MoneyValue marker interface). Refuse sql.Null* and any float-backed type at boot.
A-WR-08: A money field without max has no upper bound, so overflow is an opaque 500 instead of a 422
File: modules/cabana/field_money.go:93-107, 180-185
Issue: max is optional, and without it validateMoneyValue accepts any number of integer digits. On a numeric(10,4) column behind a string field, Postgres raises numeric field overflow inside the save transaction, and the admin gets the generic server error instead of money.too_large on the field. T-18-10 names the column ceiling as a mitigation, but nothing enforces declaring it.
Fix: Either require max on every money field, or derive a default from the scale and a conservative precision (for example 999999.9999 for scale 4). Alternatively, map a numeric field overflow (SQLSTATE 22003) to a 422 on the field.
A-WR-09: The layer navigates to any redirect_url without checking the scheme
File: ../vue-paymentgateway-layer/app/utils/checkout.ts:134-138 (wired to window.location.assign in Pg/Checkout.vue:51)
Issue: isRedirect checks only that redirect_url is a non-empty string, and deps.assign hands it to location.assign. A javascript: or data: URL from any operator, whether misconfigured, written by a third party, or the result of a compromised upstream response, would run in the shop's origin, where the JWT cookie the auth hook reads is available.
Fix: Accept only http:/https: absolute URLs (or same-origin relative paths), and show pg.error.process otherwise.
export function isRedirect(r: PgProcessResult | null | undefined): r is { redirect_url: string } {
const u = (r as { redirect_url?: unknown } | null)?.redirect_url
if (typeof u !== 'string' || u === '') return false
try { return ['https:', 'http:'].includes(new URL(u, 'https://x.invalid').protocol) } catch { return false }
}
A-WR-10: The layer's formatMoney throws on an unknown currency code and breaks the whole render
File: ../vue-paymentgateway-layer/app/utils/money.ts:48-55
Issue: new Intl.NumberFormat(locale, {style:'currency', currency}) throws RangeError for a malformed code (legacy rows with zł, an empty-padded "PLN ", and so on). The admin version (admin/src/app/money.ts:89-96) catches this, but the layer does not. One bad row makes the SSR render of the order page or order list fail with a 500.
Fix: Wrap the formatter as the admin does: in the catch, format as style: 'decimal' and append the code.
A-WR-11: A payment whose asynchronous Checkout payment is still processing is canceled by the sweep, and the later async_payment_succeeded is refused
Found in: 18-08 re-review. The behaviour predates 18-08; 18-08 documents the sweep as what closes a payment left Sent, and it made the outcome visible as an Error line.
File: ../sm-pgstripe-plugin/webhook.go:178-184 (with webhook.go:157-163, ../sm-pgstripe-plugin/operator.go:166-184, ../sm-pgstripe-plugin/README.md:36)
Issue: checkout.session.completed with payment_status unpaid returns nil and writes nothing (webhook.go:179-181). The payment stays Sent, its updated_at stays at purchase time, and nothing records that the customer finished Checkout and an asynchronous payment is running. The gateway's daily pg:cancel-sent-payments cancels every Sent payment whose updated_at is older than payment_sent_to_canceled_timeout days (settings rule 1 to 30, default 7; console/pg_cancel_sent_payments.go:56-66 of sm-paymentgateway-plugin, read for tracing). purchaseCheckout sets no payment_method_types, so the session offers the methods enabled on the Stripe account, including delayed-notification ones. When such a payment settles after the timeout, checkout.session.async_payment_succeeded reaches accept, Can(Accept) is false for the Canceled payment, and the result is the refuses Accept Error line: the customer is charged, the bridge has already canceled the order, and someone has to refund or settle by hand. With the timeout at 1 day this concerns every delayed method. With the default of 7 days it needs a settlement slower than a week; Stripe documents up to 14 business days for SEPA Direct Debit (from memory; confirm against the methods enabled on the account).
Fix: Mark the payment when its session completes unpaid, and tell operators how the timeout relates to delayed methods. Storing a marker with SaveData also moves updated_at, which restarts the sweep's clock from the day the customer finished Checkout:
case EventCheckoutSessionCompleted:
if obj.PaymentStatus != PaymentStatusPaid {
// An asynchronous method is running: record it once, no transition.
return o.asyncPending(ctx, pc, string(obj.PaymentIntent))
}
where asyncPending sets stripe_async_pending (and the PaymentIntent id) only when the payment is Sent and the marker is absent. Add a README sentence that payment_sent_to_canceled_timeout must be longer than the settlement time of the delayed methods enabled on the account, or set PaymentMethodTypes to immediate methods until the sweep can skip pending payments.
Info
A-IN-01: An authentic event for a payment that is not yet visible is answered 200 "ignored", so Stripe never retries it
File: ../sm-pgstripe-plugin/operator.go:373-381
Issue: knownPayment reads outside the purchase transaction. If an event arrives before the transaction that created the payment commits (for example a PaymentIntent confirmed in Purchase that settles quickly), the event is answered 200 and Stripe never sends it again.
Fix: Answer a retryable status (for example 404 or 409) for a uuid that matches the uuid shape but is not found, and keep the 200 "ignored" for events without a uuid.
Re-review (18-08): unchanged. ExtractUUID still answers ErrNotificationIgnored for a uuid that knownPayment does not find outside the purchase transaction (operator.go:373-381, 385-393).
A-IN-02: checkout.session.expired is not handled
File: ../sm-pgstripe-plugin/webhook.go:149-164
Issue: An abandoned Checkout Session leaves the payment Sent and the order AwaitingPayment until someone acts on it by hand. The layer then polls 20 times and shows "slow".
Fix: Handle checkout.session.expired (when its id matches the stored session) with Cancel or Reject.
Re-review (18-08): unchanged, by plan decision 3. checkout.session.expired and payment_intent.canceled stay 200 no-ops. This is now documented (webhook.go:157-163, README.md:36) and asserted (TestHostStripeFlow/event_table, TestStripeOperator/expired_sessions_and_canceled_intents_change_nothing). One correction to the issue text: the payment is not left Sent until someone acts by hand. The gateway's daily pg:cancel-sent-payments cancels a Sent payment whose updated_at is older than payment_sent_to_canceled_timeout days (1 to 30, default 7; console/pg_cancel_sent_payments.go and schedule.go, read for tracing). So the payment is closed after that many days, not when the session expires. The early cancel on an expired event whose id matches the stored session is still open. See A-WR-11 for a case where the sweep closes a payment too early.
A-IN-03: Method-backed dropdowns dispatch on the field name and ignore the declared method; submitted values are not checked against the options
File: ../sm-pgstripe-plugin/models/settings.go:90-95; modules/cabana/form_schema.go:434-447
Issue: options: getCheckoutModeOptions is only checked to be an identifier. DropdownOptions(field) receives the field name, so a typo in the method name is never caught. The settings Put does not check the value against the served options, so only the model's in: rule protects checkout_mode.
Fix: Pass the method name to the provider (or check at boot that the provider answers a non-empty list for the field), and validate submitted dropdown values against the options.
A-IN-04: The browser return answers an opaque 500 instead of redirecting when accept fails
File: ../sm-pgstripe-plugin/browser_return.go:66-68
Issue: The customer returning from Stripe lands on a JSON 500 page.
Fix: Log the error and still redirect to target. The webhook will settle the payment.
Re-review (18-08): unchanged. browserReturn still returns the error of accept (browser_return.go:71-73, formerly :66-68), which the route answers with a 500.
A-IN-05: Money values may be negative, and fields cannot declare a minimum
File: modules/cabana/field_money.go:128-138; admin/src/app/money.ts:35-38
Issue: Both parsers accept a leading minus, and max limits only the magnitude. A price or shipping-cost field cannot refuse negatives.
Fix: Add a min key (or unsigned: true) and check it on both sides.
A-IN-06: Enabling the operator without a secret key turns every checkout into a 500
File: ../sm-pgstripe-plugin/operator.go:127-131; ../sm-pgstripe-plugin/models/settings.go:69-73
Issue: ErrNoSecretKey is returned as a Go error, not as StatusError, and the settings save does not check that enabled has a key (column or env) for the active mode.
Fix: Return operators.Failed("Stripe is not configured"), and/or add a settings rule refusing enabled without a key.
Re-review (18-08): unchanged for operator.go:127-131; models/settings.go was not re-read. TestHostStripeFlow/no_secret_key asserts that ErrNoSecretKey comes back as a Go error (host_test.go:1221-1241).
A-IN-07: readWinterFields reports every read error as "File not found"
File: ../sm-pgstripe-plugin/console/import_winter.go:338-341
Issue: A permission error or a directory path is misreported.
Fix: return nil, fmt.Errorf("%s: %w", file, err).
A-IN-08: isZeroMoney treats "", "-" and "." as zero
File: ../vue-paymentgateway-layer/app/utils/money.ts:58-60
Issue: The regex ^-?0*(\.0*)?$ matches strings that are not amounts, so a malformed value is shown as "free".
Fix: /^-?0+(\.0+)?$/.
A-IN-09: The decline Warn line says "the payment stays open for a retry" whatever the payment's state
Found in: 18-08 re-review
File: ../sm-pgstripe-plugin/webhook.go:200-216
Issue: attemptFailed runs for every payment_intent.payment_failed of an owned payment and never reads pc.Payment.State; the record has no state attribute. A decline delivered after the payment was accepted (the late delivery that TestHostStripeFlow/decline_then_succeed sends at host_test.go:650-658), or for a Rejected, Canceled or Refunded payment, is logged as "the payment stays open for a retry". Someone reading the log for a Canceled payment is told the opposite of its state.
Fix: Add "state", pc.Payment.State to the attributes and use a neutral message when pc.Payment.IsFinal() (for example "payment attempt failed; the payment is already final").
A-IN-10: The refused-accept Error line is written per signal, and the success URL can repeat it
Found in: 18-08 re-review
File: ../sm-pgstripe-plugin/operator.go:484-501, ../sm-pgstripe-plugin/browser_return.go:70-73, ../sm-pgstripe-plugin/README.md:39
Issue: The README says a paid signal for such a payment "writes one Error log line". That is one line per signal. In Checkout mode one charge produces both checkout.session.completed and payment_intent.succeeded, and both resolve to the payment because the uuid is in the session's and the PaymentIntent's metadata (operator.go:180-183). Each load of the success URL adds another line: it is an unauthenticated GET, limited only by the route's throttle:paymentgateway-notify bucket (part 3 of TestHostStripeFlow/paid_after_final_state expects the second record). Plan decision 5 makes this line the alert, so an alert rule that counts records overcounts, and anyone holding the success URL can raise the alert again. Nothing is stored on this path, by decision, so the operator cannot deduplicate.
Fix: Say "one Error line per signal" in the README and advise keying alerts on the payment attribute. If a single alert per payment is wanted, store a marker in payments.data on the first refusal and log at Info level afterwards.
A-IN-11: The decline text is still logged on the purchase-time decline path
Found in: 18-08 re-review
File: ../sm-pgstripe-plugin/operator.go:255-260 and operator.go:533-540 (logged at payments/service.go:285 of sm-paymentgateway-plugin, read for tracing); ../sm-pgstripe-plugin/README.md:161
Issue: 18-08 keeps the decline text out of the webhook log lines by not decoding it, and its threat T-18-51 and plan prohibition state that logs never carry the decline message. For a decline confirmed at Purchase, purchaseIntent puts pi.LastPaymentError.Msg into operators.Failed(msg), and the payment service logs that response at Error level as message. failure does the same with se.Msg, although its own log line leaves the message out on purpose (operator.go:536). The guarantee therefore holds for webhook events only. Stripe's message texts are not personal data on their own; the point is that the stated rule and the behaviour differ.
Fix: Keep the customer-facing message in the response (the D-17 contract) and have the gateway log Stripe's code instead of resp.Message (this goes with B-IN-07), or narrow the wording in the README and the threat model to the webhook path.
A-IN-12: PaymentError.Type is decoded and exported but nothing reads it
Found in: 18-08 re-review
File: ../sm-pgstripe-plugin/webhook.go:75-83
Issue: The doc comment says the operator reads the error type, but attemptFailed logs code and decline_code only (webhook.go:207-214). The only reader is the decode test (webhook_test.go:114). The field is new exported API of a shared plugin, where removing it later is a breaking change.
Fix: Log it as type (it separates a card decline from an api_error on Stripe's side), or drop the field before the plugin's first tag.
A-IN-13: completedEvent names the first payment's session and intent, and paid_after_final_state uses it for the third purchase
Found in: 18-08 re-review (from reading; the test needs Docker and was not run)
File: ../sm-pgstripe-plugin/host_test.go:1190-1213, host_test.go:1245-1252
Issue: completedEvent always builds an event for cs_test_1 with pi_test_1. In part 4 the payment is the third purchase on that host, so the fake gave it cs_test_3 and pi_test_3 (stripefake_test.go:111-121) and purchaseCheckout stored both (operator.go:192-195). The event evt_ok_3 therefore names another payment's session and intent with p3's uuid. The operator accepts it, and accept overwrites the stored payment_intent_id with pi_test_1 (operator.go:455-459). The refund that follows in the same part is then sent for pi_test_1, the first payment's intent, and the fake refunds any id (stripefake_test.go:218-228). The part passes only because A-WR-02 is open, it will fail once the object id is matched against the stored id, and it would not notice a refund sent for the wrong intent. decline_then_succeed guards the same fixture by asserting cs_test_1 first (host_test.go:610-613).
Fix: Give completedEvent the session and intent ids as parameters and take them from the stored payment data. In part 4, assert that the refund form's payment_intent equals the id stored at purchase.
A-IN-14: Test-quality notes on the 18-08 tests
Found in: 18-08 re-review
File: ../sm-pgstripe-plugin/operator_test.go:455-457, operator_test.go:526-528, ../sm-pgstripe-plugin/host_test.go:1094-1104, ../sm-pgstripe-plugin/operator.go:479-483
Issue:
- State assertions that cannot fail on their own. The operator in these two subtests has no payment service, so every path that could change
pc.Payment.Statereturns an error first. OncehandleEventhas returned nil, the state is necessarily still Sent. The real proof is the error check together with the control case (operator_test.go:442-447); the state checks read like a second, independent proof and are not one. - A mislabelled scenario. The comment on part 1 of
paid_after_final_statesays "The customer cancels the order", but the test cancels the payment withenv.payments.Cancel. The customer API does not cancel a Stripe payment (A-CR-02, remaining item 3), so the path the comment names ends with an Accepted payment on a Canceled order and is not covered by this test. - An untested branch. The Error line for "Created or Sent with the operator's guard refusing" has no test. Through the notification route it is also shadowed:
ProcessNotificationanswers 404 for a disabled operator before it calls the operator (payments/notification.go:71-80), so the branch needs the switch to change between that check andCan.
Fix: Drop the two state checks or replace them with an assertion that can fail (for example a published payment service whose calls are counted). Reword the part 1 comment to "the sweep or an administrator cancels the payment". Add a unit case for the guard-refusing branch with a payment service whose operator is disabled.
A-IN-15: The README and the settings page list different webhook events
Found in: 18-08 re-review
File: ../sm-pgstripe-plugin/README.md:68 (against lang/en/lang.yaml:30 and lang/pl/lang.yaml:30 of sm-pgstripe-plugin, outside this scope, read for cross-reference)
Issue: Step 2 of the README's Dashboard section now lists four events to subscribe to and marks payment_intent.payment_failed optional. The comment shown under both signing-secret fields of the settings page (webhook_comment, models/settings/fields.yaml:48,68) lists three: checkout.session.completed, checkout.session.async_payment_succeeded and payment_intent.succeeded. It leaves out checkout.session.async_payment_failed, the only event that still rejects after 18-08. An administrator who follows the in-app text never receives the terminal failure, and the payment stays Sent until the sweep. The 18-08 plan lists this text as a known follow-up.
Fix: Add checkout.session.async_payment_failed to webhook_comment in both language files.
Reviewed: 2026-10-13T12:00:00Z Reviewer: Claude (msd-code-reviewer) Depth: standard Re-reviewed (18-08 scope, seven sm-pgstripe-plugin files): 2026-10-13T22:33:10Z
Part B
Phase 18: Code Review Report (part B: sm-paymentgateway-plugin)
Reviewed: 2026-10-13T15:58:16Z
Depth: standard
Files Reviewed: 59 (all in /media/nvme/dev/golem15/summercms.io/summercms/sm-paymentgateway-plugin; paths below are relative to that repo)
Status: issues_found
Summary
I reviewed the money package, the order and payment machines with their services and bridge, the notification route, the customer API (authorization, state guards, projection), the legacy cart reader, the currency providers, paymentgateway:import-winter, and the admin controllers. To check behaviour I also read the helpers these files call: money/parse.go, cart/item.go, cart/cart.go, cart/details.go, support/hashids.go, support/guest_token.go, support/redactor.go and the cabana file/upload handlers. For parity questions I compared against the PHP plugin in examples/golem15-wintercms-starter/plugins/golem15/paymentgateway.
Several parts hold up:
- The notification route verifies the request before it looks up a payment, caps the body at 1 MiB and redacts its logs.
- The payment row is locked
FOR UPDATEbeforeCan. - API mutations re-check their state guard on the locked order row.
- The order JSON projection is a real allowlist.
- Unknown and forbidden orders both answer 404.
- The legacy reader fails loudly on unknown types.
The main problems:
- Guest codes can be forged.
guest_codeis derived deterministically from the order id, and legacy rows used a salt that is public in the PHP source. - The bridge diverges from PHP and corrupts
successful_payment_id. - The default currency can be changed after setup, which silently re-bases every stored exchange ratio.
- The Fixer access key leaks into logs.
Below the blockers there are integer-overflow and panic paths in money arithmetic, external operator calls made before the state guards and inside DB transactions, and the customer API ignoring orders_enabled.
Critical Issues
B-CR-01: Guest access to an order is forgeable. guest_code is a deterministic hashids of the order id, and legacy rows used the public salt KEIOS.PAYMENTGATEWAY
File: api/auth.go:106-110, models/hashids.go:61-69 (encoder in support/hashids.go:96-98,181-184)
Issue: canActOnOrder gives full order access (read, cancel, change the payment method, remove items, request a refund) to anyone who presents ?guest_code= equal to the stored guest_code. That code is not random: it is hashids(salt, id × 118, 32) (GuestCodeFactor).
- Legacy orders. The PHP plugin hard-coded the salt
KEIOS.PAYMENTGATEWAYinsupport/HashIdsHelper.php, and the Go port keeps it asLegacySalt. So for every order PHP created, bothhash_idandguest_codecan be computed by anyone. For each id 1..N, computehash = hashids(LegacySalt, 8).encode(id)andcode = hashids(LegacySalt, 8|32).encode(id*118). PHP's static cache reused the length-8 encoder, so try both lengths. Then callGET /_paymentgateway/api/v1/orders/{hash}?guest_code={code}. This enumerates every legacy guest order, andPOST .../cancel/.../refund-requestact on them. - New orders. The secret is the hashids salt, which is also what protects the public
hash_id. Hashids is an obfuscation scheme, not a MAC. The salt-derived alphabet shuffle can be recovered from enough known (id, hash) pairs, and a customer can collect pairs for consecutive ids by placing orders. Once the shuffle is known, every guest code follows.
T-18-37 says the guest code is an authorization factor. As implemented it is only as strong as hashids. The PHP original had the same weakness, but the port re-exposes it on a new, headless, enumerable API.
Fix: Make guest_code a random bearer secret and stop deriving it from the id:
// models/hashids.go AfterCreate, for a guest order
b := make([]byte, 24)
if _, err := rand.Read(b); err != nil { return err }
code := base64.RawURLEncoding.EncodeToString(b) // 32 chars
updates["guest_code"] = code
For legacy rows, add a migration or console step that rotates every non-null guest_code to a random value. Alternatively, refuse a presented code that equals hashids(LegacySalt, id*118) at either length, and require the HMAC guest_token for those orders. Document the rotation in the import notes. Store a hash of the code (SHA-256) instead of the code itself if the column is ever exposed to admins.
B-CR-02: The PaymentAccepted bridge writes successful_payment_id before checking Can(Pay), overwriting the real successful payment on Paid, Canceled or Finished orders (PHP did not persist it)
File: orders/bridge.go:98-110
Issue: onPaymentAccepted runs UPDATE ... SET successful_payment_id = <this payment> unconditionally and only then checks Can(Pay). When Pay is not allowed, it logs and returns nil, so the write commits. In PHP (OrderPaymentEventSubscriber::onPaymentAccepted) $order->successful_payment = ... is only an in-memory assignment, persisted by performTransition(Pay) through saveWithState. When can(pay) is false, nothing is saved.
Consequences:
- Duplicate payment on a Paid order. A second accepted payment (a double Stripe session, or an admin accepting a stale cash payment) re-points the order at payment B.
PerformTransition(GrantRefund/DirectRefund/RefundAfterReturn)then refunds B only. Payment A stays Accepted, is no longer referenced, and is never refunded through the order flow. - Late payment on a Canceled order. A Stripe payment confirmed after the API or cron canceled the order is recorded as the order's successful payment. The customer is charged, the order stays Canceled, and only an error log line records it. The admin "create payment" buttons are hidden because
SuccessfulPaymentID != nil.
Fix: Persist only together with the transition, as PHP does, and handle the not-payable case explicitly:
ok, err := b.orders.Can(ctx, e.Tx, order, models.OrderTransitionPay)
if err != nil { return err }
if !ok {
b.logger.Error("paymentgateway: order cannot accept the payment", ...)
return nil // optionally fire an event / flag for manual refund
}
id := e.Payment.ID
if err := e.Tx.WithContext(ctx).Model(order).Update("successful_payment_id", id).Error; err != nil { return err }
order.SuccessfulPaymentID = &id
return b.orders.PerformTransition(ctx, e.Tx, order, models.OrderTransitionPay)
Consider treating an Accepted payment on a Canceled order like the Rejected branch (refund, or at least an admin notification).
B-CR-03: default_currency can be changed at any time, which silently re-bases every stored exchange ratio and native amount
File: models/settings/fields.yaml:10-18, models/settings.go:209-232,244-276, currency/converter.go:175-206,267-283, console/import_winter.go:141-160
Issue: golem15_paymentgateway_currencies.ratio stores "units of the default currency per unit of ISO" relative to the default currency at the time each row was fetched. PHP made defaultCurrency a disabled field: it was set once by the SetUp wizard and then locked. The Go settings form makes it a required, freely editable dropdown with no guard, and import-winter --force overwrites it too.
After a change from PLN to EUR:
ConvertToNativemultiplies a USD amount by the old USD-to-PLN ratio (≈3.7) and labels the result EUR.- The PLN rows of existing orders have no ratio row, so a new one is fetched against EUR.
Every new native_amount_stored is then wrong by the PLN/EUR factor. The payments and orders "sales this month" scoreboards sum native_amount_stored WHERE native_currency = <new code>, which mixes in the wrong amounts and drops the earlier ones. Nothing warns the administrator.
Fix: Make the field write-once:
- In
Settings.BeforeValidate, load the stored row and reject a change of a non-emptydefault_currency(422settings.default_currency_locked), or allow it only when no orders or payments exist. - Add
attributes: { disabled: true }(or adependsOn/readOnly preset) after setup infields.yaml. - Make
import-winter --forcerefuse a different code when orders exist. - If a change must ever be supported, truncate and refetch
golem15_paymentgateway_currenciesin the same transaction.
B-CR-04: The Fixer access key is written to the application log on any transport error
File: currency/fixer.go:50,66-69
Issue: The access key goes into the query string (q.Set("access_key", f.AccessKey), then root+"/latest?"+q.Encode()). When client.Do fails (timeout, DNS, TLS, connection refused), Go returns a *url.Error whose Error() is Get "https://…/latest?access_key=<KEY>&base=…": <cause>. net/http strips only userinfo passwords, not query values. Rates then logs that error at Warn level (slog.Default().Warn("paymentgateway: fixer rate", ..., "err", err)), and the scheduled pg:update-currencies runs every ten minutes, so an outage writes the key into the logs repeatedly. Also, when fixer_url is unset the key is sent to the default https://exchange.viamage.com, a third-party proxy, rather than fixer.io.
Fix: Do not log the raw *url.Error, and strip the query:
resp, err := client.Do(req)
if err != nil {
var ue *url.Error
if errors.As(err, &ue) {
return "", fmt.Errorf("%w: fixer request failed: %v", ErrNoRate, ue.Err)
}
return "", fmt.Errorf("%w: fixer request failed", ErrNoRate)
}
Also refuse to send AccessKey unless FixerBaseURL is explicitly configured (or default the URL to https://data.fixer.io/api when a key is set).
Warnings
B-WR-01: Money arithmetic wraps int64 silently (Add, Sub, Neg, FromMinor, Amount4.Scan(int64)), and Fits(MinInt64) returns true
File: money/money.go:83-85,138-154, money/amount.go:48-49,62-70,79-84
Issue: Mul, Div and Allocate were hardened to panic on overflow, but:
AddandSubdom.units + o.unitsandm.units - o.unitswith no check.FromMinordoescents * 100.Amount4.Scandoesv * scaleUnitsfor an int64 source.NegandAbsofMinInt64returnMinInt64.Amount4.Fitscomputes-a, which forMinInt64stays negative, soFitsreturns true.Amount4.StringofMinInt64prints garbage (%04dof a negative remainder).
cart.totalGross sums item totals with Add. Two lines that each fit int64 can sum to a wrapped value that lands inside ±MaxNumeric12 and passes the Fits ceiling check in orders.Make, orders.Save and payments.Create. The stored total then has nothing to do with the lines.
Fix: Check overflow in Add and Sub and return ErrOverflow (their signatures already return an error):
s := m.units + o.units
if (o.units > 0 && s < m.units) || (o.units < 0 && s > m.units) {
return Money{}, ErrOverflow
}
Guard FromMinor, Scan(int64) and Neg the same way (return an error, or panic consistently with Mul). Make Fits reject math.MinInt64 explicitly.
B-WR-02: The quote cart accepts an unbounded count, and Mul then panics with ErrOverflow in orders.Service.Save (500, a panic used as control flow)
File: controllers/quotes_cart.go:229-234 (with cart/item.go TotalNetPrice/TotalGrossPrice, money/money.go:209-212)
Issue: change_item with field: "count" only checks n >= 1. With a unit price of 999999.9999 (the allowed maximum), any count above about 9.2×10⁸ makes Mul(count, 1) exceed int64 after the scale-5 step. fromScale5 then panics. Nothing recovers it before svc.Save → TotalGross, so the request dies with a panic instead of the money.too_large 403 the code intends to return just below. Smaller counts that fit individually can still wrap the cart sum (B-WR-01).
Fix: Bound the count before applying it, and have Save turn arithmetic overflow into ErrAmountTooLarge:
const maxCount = 1_000_000
if !ok || n < 1 || n > maxCount { return c.refuse(ctx, "quote.count_min") }
// and in orders.Service.Save / Make: compute totals via a helper that recovers money.ErrOverflow
Prefer making Item.TotalNetPrice and TotalGrossPrice return (Money, error) over panicking.
B-WR-03: The customer API ignores orders_enabled. With orders off the bridge is a no-op, so process can be repeated and items edited after a payment exists
File: api/actions.go:62-115, api/items.go:51-75, orders/bridge.go:60-62
Issue: The doc comment says a second process answers 409 because "the bridge moves the order to AwaitingPayment". bridge.order() returns nil when settings.OrdersEnabled is false, so the order stays Placed after a successful process. A second process then passes requireState(Placed) and creates and sends a second payment (another Stripe Checkout session). AddPiece, RemoveItem and SelectShipping also keep working on an order that already has a Sent payment for the old total. resolveOrder and every handler skip the switch, while the admin side does check it (ordersAdminController.ordersOn).
Fix: In resolveOrder (or a middleware on the API group), answer 404 or 409 when !settings.OrdersEnabled. Also refuse process when the order already has a payment in Created or Sent:
if !settings.OrdersEnabled { writeNotFound(w); return nil, false }
B-WR-04: The RecordExternal contract cannot be met for a disabled operator. The doc says "need not be enabled", but Send and Accept are guarded by enabled
File: payments/service.go:458-470 (guard in payments/machine.go NewMachine, enabledGuard at payments/service.go:117-129)
Issue: RecordExternal accepts any registered operator, enabled or not, "the record is a fact, then calls Send and Accept". Both Send and Accept carry Guard: enabled, which returns false for a disabled operator. A consumer following the documented D-04 b path therefore gets ErrTransition and a payment stuck in Created, and with the default cron it is canceled after payment_created_to_canceled_timeout days.
Fix: Either require GetEnabled in RecordExternal (and update the doc), or add an explicit AcceptExternal that bypasses the enabled guard only for externally recorded payments (for example a Subject.External flag checked in enabledGuard).
B-WR-05: Operator side effects run before the state guard and inside the DB transaction, with no idempotency; lock order is inverted between the order and notification paths
File: payments/service.go:260-291,325-353, orders/service.go:323-337, orders/bridge.go:63,96
Issue:
Purchasecallsop.Purchase(an outbound Stripe request) before it checks thatSendis allowed. A payment that is notCreated, or whose operator is registered but disabled (s.Operatordoes not check enabled), still triggers the external call, and only then fails onapply(Send).Refundcallsop.Refundinside the caller's transaction. If anything later in the transaction fails (an event listener, the bridge, a serialization or deadlock error), the money has been refunded at the operator while the row rolls back toAccepted. An admin retry then issues a second refund request. No idempotency key derived from the payment UUID is passed.- The admin order refund (
PerformTransition→payments.Lock) takes the order lock and then the payment lock. The notification path (ProcessNotification→Lock(payment)→ bridgeorders.Lock) takes them in the opposite order. A concurrent refund webhook and admin refund on the same order can deadlock. Postgres aborts one side, possibly the admin side after the operator refund was already issued (point 2).
Fix:
- Check
Can(Send)(with the guard) beforeop.Purchase. - Pass an idempotency key (the payment UUID plus the transition) to operator calls.
- Lock order before payment everywhere: in
ProcessNotification, whenp.OrderID != nil, lock the order row before the payment row.
B-WR-06: POST /cancel on an AwaitingPayment order with an in-flight online payment cancels the order and leaves the payment Sent; a later Accept charges the customer for a canceled order
File: api/actions.go:345-388 (with orders/bridge.go:103-110)
Issue: Cancel cancels only cash and manual payments, then applies Cancel to the order directly, even when a Stripe payment is still Sent (the customer may be on the Checkout page). When the webhook later accepts that payment, onPaymentAccepted finds the order Canceled, cannot Pay, logs an error and (B-CR-02) records it as the successful payment. Nothing refunds it. The comment's claim that "the sweep handles" this is not backed by anything in the reviewed code.
Fix:
- Refuse
cancel(409) while an API-mode payment of the order isSent, or cancel that payment at the operator first (expire the Checkout session or cancel the intent). - In the bridge, refund an Accepted payment on a Canceled order the same way the Rejected branch does.
B-WR-07: Payment rows are canceled from unlocked reads, and transitions are blind UPDATEs without a state predicate
File: api/actions.go:356-376, orders/service.go:338-359, payments/service.go:362-372
Issue: ForOrderRows reads the order's payments without FOR UPDATE, then Can and Cancel act on that snapshot. apply writes UPDATE ... SET state = next WHERE id = ? with no AND state = <from>. Correctness depends on every concurrent writer also locking the order row first. The bridge does this only when orders_enabled is on, and payments.Accept from the admin payments screen locks only the payment. Interleaving: the admin accepts a manual payment while the API cancel holds the order, with orders off. Both commit, and the last write wins: an Accepted payment is flipped to Canceled.
Fix: Lock each payment row before deciding (s.payments.Lock(ctx, tx, p.ID) inside the loop). In apply, use an optimistic predicate:
res := tx.WithContext(ctx).Model(&models.Payment{}).Where("id = ? AND state = ?", p.ID, p.State).Update("state", next)
if res.RowsAffected != 1 { return fmt.Errorf("%w: payment %d changed concurrently", ErrTransition, p.ID) }
Apply the same to orders.Service.apply.
B-WR-08: The native amount is never checked against numeric(12,4) in Make and Save, nor against numeric(10,4) in RecordExternal
File: orders/service.go:106-111,211-216, payments/service.go:472-474
Issue: Make and Save check total against MaxNumeric12 but not native. A EUR order of 50,000,000 converts to about 213,000,000 PLN, which overflows native_amount_stored numeric(12,4). Postgres raises numeric field overflow, which surfaces as an opaque 500 in the API (and as a 500 from the quote cart) instead of the 422 or 403 too_large that the same code returns for the gross total. RecordExternal checks order.AmountStored but copies NativeAmountStored into a numeric(10,4) payment column unchecked. payments.Create does both checks correctly.
Fix: After ConvertToNative, add if !native.Amount4().Fits(money.MaxNumeric12) { return ErrAmountTooLarge } in Make and Save, and if !order.NativeAmountStored.Fits(money.MaxNumeric10) in RecordExternal.
B-WR-09: import-winter stores mailer_from_email and admin_email without the e-mail validation the settings form enforces
File: console/import_winter.go:349-377,431-434
Issue: mailer.credentials.email is copied verbatim (only trimmed). mailgroup is accepted as an e-mail whenever it contains @. The values then become the mail ReplyTo and the staff To address (events/mailers.go:133-135, events/recipients.go:85-86). An exported value such as "a@b.c, other@x" or one containing CR/LF bypasses the "e-mail rules validate mailer_from_email and admin_email" mitigation of T-18-24. postcard's header checks will probably refuse such a value at send time, which then breaks every mail silently: the error is only logged.
Fix: Validate with net/mail.ParseAddress and require that the parsed address equals the trimmed input (single address, no display name). Report invalid values as ignored lines, as the timeouts already do.
B-WR-10: Negative costs are not refused for shipping methods and quote items, and add_quoteable bypasses the quote cart's non-negative rule
File: models/shipping.go:58-64, models/quoteable.go:39-45, controllers/quotes_cart.go:198
Issue: The money admin field compares magnitude against max and accepts a leading minus, and neither model's Rules() refuses a negative cost_stored. A negative shipping cost lowers every order that selects it (SelectShipping). A negative quoteable is turned into a negative cart line by addQuoteable (q.CostStored.Money(currency)), while change_item refuses the same value with quote.price_negative. payments.Create uses Fits (absolute value), so a negative total passes and becomes a negative cash or manual payment.
Fix: Refuse cost_stored < 0 in shippingsAdminController.beforeSave and quoteablesAdminController.beforeSave (or add a min: "0" to the money field if cabana supports it). Check q.CostStored < 0 in addQuoteable. Refuse a non-positive total in payments.Create (ErrAmountTooLarge's sibling ErrAmountInvalid).
Info
B-IN-01: The route comment is wrong; the API paths have three segments and also match the notification pattern
File: routes.go:59-60 (patterns at routes.go:15-19)
Issue: /_paymentgateway/api/v1/orders, /payment-methods and /shippings have three segments after /_paymentgateway, so they also match /_paymentgateway/{op}/{mode}/{result}. GET works only because the literal pattern is more specific. POST /_paymentgateway/api/v1/orders is routed to notify and answers 404 "Operator not found".
Fix: Correct the comment, or reserve the api segment (register explicit 405 handlers for the three API paths).
B-IN-02: Per-user API throttling never applies
File: plugin.go:119-128
Issue: The paymentgateway-api bucket keys on bouncer.User, but the throttle is group middleware that runs before the handler-level api.OptionalJWT/RequireJWT, which are the only places the principal is set. The key is therefore always the client IP, contrary to the "per user or IP" claim in T-18-41.
Fix: Run the optional JWT guard as group middleware ahead of the throttle, or document IP-only keying.
B-IN-03: Allocate accepts negative ratios and can hand out more than the amount
File: money/money.go:252-303
Issue: With ratios [-1,-1,4] on 0.01, truncation toward zero gives shares [0,0,0.02]. The remainder is then negative and the remainder > 0 loop never corrects it. Allocate is not used in production code yet.
Fix: Refuse negative ratios (return nil or panic), as MoneyRight expects positive ratios.
B-IN-04: Four-place ratios lose most of their precision for low-value currencies
File: currency/converter.go:117-133
Issue: numeric(8,4) means IDR→EUR (≈0.0000568) is stored as 0.0001, a 76 % error. A ratio below 0.00005 rounds to 0 and is refused (ErrBadRatio), which makes the currency unusable. This matches PHP, but it matters for money exactness.
Fix: Document the limitation, or widen currencies.ratio (for example numeric(18,10)) in a later phase.
B-IN-05: The golem15-paymentgateway-label element never re-renders when value changes
File: assets/js/quote-cart.js:23-28
Issue: The element reads value only in connectedCallback and has no observedAttributes or attributeChangedCallback. If Vue patches the attribute on a reused row element, the list keeps showing the old state or operator label.
Fix: Add static get observedAttributes() { return ['value'] } and an attributeChangedCallback that updates textContent.
B-IN-06: IsGuestEmail matches any address that contains guest@
File: events/recipients.go:38-40
Issue: An address such as myguest@example.com or theguest@firm.pl is treated as the guest marker, so the user's own address is skipped. This matches PHP str_contains.
Fix: Match the actual guest-user domain or prefix the user plugin uses.
B-IN-07: process returns the operator's raw message to an anonymous caller and turns every failure into a 422
File: api/actions.go:103-114
Issue:
resp.Message(for example a Stripe error text) is returned to whoever holds the guest code.- Database errors and deadlocks returned by
orders.Purchasealso become 422 "payment could not be started" instead of a logged 500.
Fix: Return the generic msgPaymentFailed and log resp.Message. Map only domain errors (ErrUnsupportedCurrency, MissingFieldError, ErrAmountTooLarge, operator errors) to 422.
B-IN-08: readWinterFields reports every read error as "File not found"
File: console/import_winter.go:309-313
Issue: Permission denied, a directory path or an I/O error are all reported as a missing file.
Fix: Use fmt.Errorf("%s: %w", file, err).
B-IN-09: The stats sum is cast to numeric(14,4)
File: controllers/orders_partials.go:155-158
Issue: A monthly sum above 9,999,999,999.9999 makes Postgres fail the stats partial with numeric field overflow.
Fix: Cast to unconstrained numeric and parse the text. ParseAmount4 already reports overflow.
B-IN-10: The guest token cache keeps a nil verifier forever and is never evicted
File: api/auth.go:155-177
Issue: If app.key is unavailable on the first call, nil is cached for that app permanently. The map keyed by *backpack.App also grows in tests that build many apps.
Fix: Do not cache nil. Hold the verifier on the plugin instance, or publish it on the app at boot.
B-IN-11: The notification route depends on net/http/httptest in production and replays the handler after commit
File: payments/notification.go:12,158-167
Issue:
- A production package imports
net/http/httptest, and responses are fully buffered. r.Bodyhas already been consumed when the operator's handler runs, so a handler that re-reads it sees EOF.op.Enabled(a settings DB read) runs beforeVerifyNotification, and its 404-versus-403 answer reveals which operators are enabled.
Fix:
- Use a small custom
ResponseWriterrecorder. - Rewind
r.Body(bytes.NewReader(body)) beforehandler.ServeHTTP. - Optionally answer 403 for a disabled operator.
B-IN-12: The quotes controller has no FormExtendQuery
File: controllers/quotes.go:60-63 (and controllers/admin_registry.go:273-287)
Issue: Only the list is scoped to state = 'Quote'. The quotes preview, update form, process_quote and the quote_cart action all load any order id under the quotes controller. Saves are refused by FormBeforeUpdate, but the screens and the read-only cart of non-quote orders are served there.
Fix: Add FormExtendQuery with the same state = 'Quote' scope, as ordersAdminController does for the inverse.
B-IN-13: A huge page overflows the offset in GET /orders
File: api/orders.go:33-46
Issue: (page-1)*OrdersPerPage overflows for a page near MaxInt, and the negative offset is ignored, so the first page is served.
Fix: Clamp page to something like total/OrdersPerPage + 1 before computing the offset.
Reviewed: 2026-10-13T15:58:16Z Reviewer: Claude (msd-code-reviewer) Depth: standard