Merge pull request 'Fix/starpost promo gate' (#6) from fix/starpost-promo-gate into main

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
takuya committed 2026-10-25 12:04:36 +03:00
commit f09895d65e
2 files changed
+20 -1

No files matched your search

+10 -1
View File
@@ -293,7 +293,10 @@ def invalidate_promo():
if not isinstance(code, str) or not 1 <= len(code) <= 100:
return error("invalid promo code")
with db() as conn, conn.cursor() as cur:
cur.execute("DELETE FROM promo_codes WHERE user_id=%s AND code=%s", (session["user_id"], code.strip()))
cur.execute(
"DELETE FROM promo_codes WHERE user_id=%s AND code=%s AND credited_at IS NOT NULL",
(session["user_id"], code.strip()),
)
if cur.rowcount == 0:
return error("promo code is unavailable", 409)
return jsonify(invalidated=True, code=code.strip())
@@ -509,6 +512,9 @@ def order_product(product_id):
return None, error("product not found", 404)
if row["seller_id"] == session["user_id"]:
return None, error("cannot buy your own product")
cur.execute("SELECT 1 FROM promo_codes WHERE user_id=%s", (session["user_id"],))
if cur.fetchone():
return None, error("promo code must be invalidated", 409)
if row["balance"] < row["price"]:
return None, error("insufficient balance", 409)
cur.execute("UPDATE users SET balance=balance-%s WHERE id=%s", (row["price"], session["user_id"]))
@@ -534,6 +540,9 @@ def checkout():
with db() as conn, conn.cursor() as cur:
cur.execute("SELECT balance FROM users WHERE id=%s FOR UPDATE", (session["user_id"],))
buyer = cur.fetchone()
cur.execute("SELECT 1 FROM promo_codes WHERE user_id=%s", (session["user_id"],))
if cur.fetchone():
return error("promo code must be invalidated", 409)
cur.execute(
"""
SELECT p.id product_id,p.seller_id,p.price,p.is_active,c.quantity
+10
View File
@@ -2,6 +2,16 @@
## Confirmed vulnerabilities
### Fresh-buyer cargo purchase
The checker creates flag-bearing products priced within the 200-credit budget of a newly registered buyer: the account starts with 100 credits and its one-time promo adds 100. An attacker can therefore register a buyer, credit the issued promo, buy an active product, wait for automatic warehouse delivery, and read its cargo through `GET /api/orders` without bypassing authentication.
Incident logs and aggregate database checks confirmed this exact path. The observed attacker used `register -> account -> promo/credit -> direct buy -> orders`, while the checker uses `promo/credit -> promo/invalidate -> cart -> checkout -> orders`.
The emergency patch requires the buyer to finish the existing promo lifecycle before either direct purchase or checkout. `promo/invalidate` now succeeds only after credit, and both purchase paths return 409 while a promo row remains. Routes, successful response bodies, prices, delivery, existing orders, and cargo retrieval are unchanged. A synthetic route-level regression confirmed that purchase before invalidation is blocked, credit followed by invalidation preserves direct buy and checkout, and an uncredited promo cannot be deleted to bypass the gate.
This is containment for the observed exploit, not a durable confidentiality boundary. An adaptive attacker can call the public invalidate endpoint and reproduce the checker workflow. A permanent fix requires a checker-compatible non-public purchase capability or moving flags out of buyer-deliverable cargo.
### Cross-seller review cursor BOLA
Before the patch, `GET /api/seller/reviews` skipped the cursor HMAC check when `limit <= 3`. An authenticated seller could supply unsigned Base64url JSON containing another `seller_id`, `is_private=true`, and a high `last_id`; the response returned that seller's private review bodies.