fix(payments): drop the notification sender-IP gate; re-check on its own cadence
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 21s
CI / ui (pull_request) Successful in 1m16s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m55s

A real test payment on the contour exposed both problems at once. YooKassa
delivered the notification five times; all five were rejected because the
backend saw the sender as 10.77.0.1 — the contour sits behind a tunnel and
cannot observe real client addresses, the same reason the IP bans in this
repository are prod-only. The chips were not lost (the reconcile sweep would
have credited them), but the primary path was dead and the customer was left
watching an unchanged balance.

The address check is removed rather than made conditional. It never was the
security boundary — the confirming GET /v3/payments/{id} is — and the one thing
it bought is already bought earlier and far more tightly: the order is resolved
from the notification's metadata *before* any provider call, so a notification
naming no known order costs a single indexed read and stops there. Guessing a
live order id means guessing a uuid. Against that, an address check adds nothing
and breaks every deployment that cannot see real client addresses, while turning
any future change to YooKassa's published ranges into a silent degradation.

The second problem was mine. The reconcile threshold was keyed off the order
lifetime, so a lost notification cost the customer the full 30-minute TTL before
the chips landed. Those are different questions: the lifetime governs how long a
customer may take to pay, the re-check governs how soon we notice a lost
callback. Split apart — `payments.ReconcileAfter`, one minute, swept on every
reaper tick. The bound D49 was chosen for survives: the calls one order can
cause are still its lifetime divided by the sweep interval, a handful, not an
open-ended poll. Worst case for a failed notification drops from ~30 minutes to
~5; an order the customer is still paying for is left alone.

Tests: the foreign-sender test is replaced by the two properties that now carry
the load — a notification naming an unknown order makes no provider call at all,
and a genuine notification is honoured whatever address it appears to come from.
Plus one pinning that a seconds-old order is not polled.

The shared bundle budget goes 31 -> 32 KB, with the reason recorded in the
script header: every user-visible string lands in that chunk and it had been
sitting 40 bytes under the cap.

Decisions D48 and D49 revised.
This commit is contained in:
Ilia Denisov
2026-07-28 12:00:03 +02:00
parent 12e616ceae
commit 4cac09c9f3
12 changed files with 174 additions and 155 deletions
+14 -5
View File
@@ -242,11 +242,20 @@ The native Android app is a Capacitor 8 wrapper of the `ui` SPA, scaffolded unde
- **Monetization** — «Фишка» currency, per-platform wallets, ads. Agreements in
`docs/PAYMENTS_DECISIONS_ru.md`; a phased plan (E0E9). go-jet money rule above applies.
- **YooKassa (the direct rail since v1.x) does NOT sign its webhooks.** Authenticity is the
confirming `GET /v3/payments/{id}` — never the notification body — plus the published sender-IP
allowlist. Two extra guards ride on the confirmed object: its `metadata.order_id` must name the
order, and its `test` flag must match the shop's `IsTest` (a test-shop payment must never credit
real chips). Answer 200 for anything durably decided, 5xx only to be redelivered (YooKassa retries
24h).
confirming `GET /v3/payments/{id}` — never the notification body. Two extra guards ride on the
confirmed object: its `metadata.order_id` must name the order, and its `test` flag must match the
shop's `IsTest` (a test-shop payment must never credit real chips). Answer 200 for anything
durably decided, 5xx only to be redelivered (YooKassa retries 24h).
- **Do NOT gate the notification on the sender IP** — tried, reverted. The contour sits behind a
tunnel and sees every caller as an internal address (`10.77.0.1`), so the allowlist rejected every
genuine notification and the credit fell back to the reconcile sweep. Same root cause as the
IP bans being prod-only. It bought nothing anyway: the order is resolved from the notification
metadata **before** any provider call, so a forged id costs one indexed read, and guessing a live
order id means guessing a uuid.
- **Never key a re-check interval off the order TTL.** The order lifetime answers "how long may a
customer take to pay"; the re-check answers "how soon do we notice a lost callback". Tying them
together made a failed notification cost the customer the full 30-minute TTL before the chips
landed. `payments.ReconcileAfter` is its own constant for that reason.
- **Subscribe to `refund.succeeded`, not just the payment events.** The YooKassa cabinet lets an
operator refund without touching our API, so without that event the money goes back while the
chips stay credited. The reversal engine is **full-refund-only** (it rejects any amount other than