From 7e96966188359f21ec71851bb64ce65476df1024 Mon Sep 17 00:00:00 2001 From: scandalist-trash Date: Sun, 25 Oct 2026 04:50:33 -0400 Subject: [PATCH] starpost: require finalized promo before purchase --- starpost/api/app.py | 11 ++++++++++- starpost/resume.md | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/starpost/api/app.py b/starpost/api/app.py index 5ca9179..dbf4664 100644 --- a/starpost/api/app.py +++ b/starpost/api/app.py @@ -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 diff --git a/starpost/resume.md b/starpost/resume.md index 90cb658..7f7928a 100644 --- a/starpost/resume.md +++ b/starpost/resume.md @@ -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.