{"id":"XE-13372","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"526","source_url":"https://github.com/xeprotocol/xe/issues/526","reporter_id":2252,"title":"`pendingOffers` flood + offer displacement: unauthenticated offers block legitimate leases and steer a victim's lease to an attacker-chosen provider","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0106","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:12.867106+00:00","updated_at":"2026-11-20T00:51:51.113126+00:00","source_created_at":"2026-11-13T03:17:29+00:00","told_at":"2026-11-20T00:50:58+00:00","status_changed_at":"2026-11-20T00:50:05.435606+00:00","url":"https://bounty.xe.network/XE-13372","body":"**Suggested tier:** Medium\n\n**XE address (reward destination):** 9b663fdac108be34a3b715ef78a9f9bd878af6ef8142f388c6514918e6852dd7\n\n## Summary\n\n`node/node.go`, `handleMarketplace` (offer case, ~l.1404–1425) stores an incoming marketplace offer after verifying only its signature — with three missing checks, all in one place:\n\n1. **No request-ownership check.** Offers are stored for *any* `RequestID`, including IDs this node never issued. There is no record of outgoing requests to compare against.\n2. **Single slot per RequestID, last-write-wins.** No timestamp comparison, no price/dimension check, no first-seen-wins. Any later offer for the same RequestID silently displaces the earlier one.\n3. **Hard cap of 1000 with silent drop.** Once the map is full, every further offer is dropped (`len < 1000` gate) — including legitimate ones. The 60 s prune only runs on ingest of another offer, and only evicts pre-existing entries.\n\nThere is no barrier to entry: `core.VerifyPayloadKey` (used by `VerifyOffer`) only checks that the pubkey derives the claimed account address — it never checks that the account exists on the ledger, holds any balance, or has stake. A fresh throwaway keypair can sign valid offers.\n\n## Impact\n\nHonestly bounded — no direct theft. The lease block the consumer builds is still validated by the ledger (`validateAndAddLease` re-checks cost vs. the pinned certificate, cert ownership and expiry), and an unaccepted lease is refundable via cancel, so the victim's funds are locked/delayed, not stolen. What the attacker gains is:\n\n- (a) **Network-wide denial of lease creation** while the flood runs. Sustaining it costs ~17 fresh offers/s (one 1000-offer refill per 60 s prune window) — trivial — and it hits *every* node, because gossip propagates the offers network-wide and every node runs the same handler. Gossip peer-scoring does not mitigate: valid messages incur no `InvalidMessageDeliveries` penalty, and there is no per-topic rate limit in `gossipOptions`.\n- (b) **Steering a victim's lease to a provider of the attacker's choosing** (including themselves, with no stake — `LeaseStake` returns 0 while `LeaseStakeDivisor == 0` — and, per #392, a self-issued certificate). The attacker's offer is freshly signed (new timestamp/signature), so gossipsub's 120 s duplicate-suppression does not apply.\n- A consumer asking for 8 vCPUs can also silently receive fewer: `RequestAndCreateLease` never checks `offer.VCPUs/MemoryMB/DiskGB/Duration` against the request (honest providers copy the request dims, but nothing enforces it).\n\n## Steps to reproduce\n\nUnit tests against the real node code (`github.com/xeprotocol/xe`, testnet-0005, commit `89a542e`):\n\n```\ngit clone https://github.com/xeprotocol/xe\ncd xe\ncp market-node_test.go node/\ncp market-net_test.go net/\ngo test ./node -run TestMarket -v -count=1\ngo test ./net -run TestMarket -v -count=1\n```\n\nNote: `market-node_test.go` / `market-net_test.go` are NOT in the public repository — the PoC test files are attached to this issue; without them, the XE team cannot run this reproduction.\n\n**PoC 1a — flood blocks a legitimate offer** (`TestMarketPendingOffers_FloodBlocksLegit`, in `market-node_test.go`): feed 1000 distinct self-signed offers (fresh keypair, random RequestIDs) through the real `handleMarketplace`, then a legitimate offer for `victim-request`.\n\n**Expected:** the legitimate offer is stored.\n**Actual (reproduced 2026-11-13):** the map holds 1000 attacker offers; the legitimate offer is **not stored**. The victim consumer's `RequestLease` polls for 30 s and returns `no offer received within 30s`.\n```\nCONFIRMED: 1000 attacker offers fill pendingOffers cap; legitimate offer for a real request is dropped (RequestLease would time out after 30s)\n```\n\n**PoC 1b — targeted displacement / lease steering** (`TestMarketPendingOffers_LastWriteWinsAndStaleStored`): a legitimate offer (provider L, `TotalCost` 517) for request `req-R` is stored; then an attacker's offer for the same `req-R` (different provider, `TotalCost` 9999, *older* timestamp) is fed — it **overwrites** the legitimate offer. `RequestLease` polls every 500 ms and returns whatever is in the map, so the consumer's `RequestAndCreateLease` builds the lease against the attacker's offer instead. The same test shows a 1-hour-old offer is stored for a fresh request ID — incoming offers are never freshness-checked.\n```\nCONFIRMED: later offer (different provider, 9999 vs 517, older ts) overwrote legit offer for same RequestID — single-slot map, no timestamp/price/matching check; RequestLease polls first-seen and would take the attacker's offer\nCONFIRMED: offer with 1-hour-old timestamp is stored in pendingOffers (incoming offers are never freshness-checked)\n```\n\n**Supporting PoC — no account needed** (`TestMarketFlood_AttackerNeedsNoAccount`, in `market-net_test.go`, `go test ./net -run TestMarket -v -count=1` → PASS 6/6): 1000/1000 self-signed offers from a fresh, never-funded keypair all verify.\n```\nCONFIRMED: 1000/1000 self-signed offers from a fresh, never-funded keypair all verify — flood needs no account, stake, or prior request\n```\n\n## Root cause\n\n`node/node.go`, `handleMarketplace` (offer case):\n\n```go\nn.pendingOffersMu.Lock()\n    cutoff := time.Now().Add(-60 * time.Second).UnixNano()\n    for id, o := range n.pendingOffers {\n        if o.Timestamp < cutoff { delete(n.pendingOffers, id) }  // prunes OLD entries only\n    }\n    if len(n.pendingOffers) < 1000 {\n        n.pendingOffers[msg.Offer.RequestID] = msg.Offer   // unconditional overwrite\n    }\nn.pendingOffersMu.Unlock()\n```\n\nNo outgoing-request tracking, no per-RequestID offer set or first-seen-wins, no freshness check on the incoming offer, and a hard cap that drops legitimate offers once full. The gossip entry (`net/gossip_validate.go`, `marketplaceValidator`) likewise applies no freshness or request-ownership check.\n\n## Suggested fix\n\nTrack outgoing request IDs with an expiry; store offers only for requests this node issued; keep *all* offers per RequestID (or first-seen-wins) and let `RequestLease` pick (e.g. cheapest valid, or explicit provider choice); enforce a freshness window on `offer.Timestamp` (e.g. 60 s, matching the prune); rate-limit / per-provider cap on `pendingOffers` inserts; validate offer dims against the request before returning it.\n\n## Controls verified (same PoC files, all PASS)\n\n- Cross-context signature reuse (ad ↔ request ↔ offer) is rejected — distinct domain tags (`xe/marketplace-advertisement/v1`, `-request/v1`, `-offer/v1`) plus different field sets (`TestMarketCrossContext_SignatureReuseRejected`).\n- `TotalCost` / `Timestamp` forgery is rejected — both fields are signature-covered; only exact replays pass (`TestMarketTamper_TotalCostAndTimestampSigned`). Even a tampered cost could not create a bad lease (ledger recomputes `LeaseCost` from the pinned cert).\n- Stale-price lease via a replayed offer is not reachable through the honest consumer flow: `RequestLease` generates a fresh `RequestID` per call and only accepts offers for it, and the ledger re-verifies cost against the pinned certificate.\n- Directory impersonation / registration replay is neutralised (monotonicity + 30 min TTL, `TestMarketDir_MonotonicityRejectsOldReplay`, `market-dir_test.go`).\n\n[market-node_test.txt](https://github.com/user-attachments/files/34781488/market-node_test.txt)\n[market-net_test.txt](https://github.com/user-attachments/files/34781486/market-net_test.txt)\n[market-dir_test.txt](https://github.com/user-attachments/files/34781487/market-dir_test.txt)","patch_refs":[{"id":741,"repo":"xeprotocol/xe","kind":"pr","ref":"913","title":"fix(xe): pendingoffers--flood---offer (fixes #526)","url":"https://github.com/xeprotocol/xe/pull/913","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-20T00:19:17.355069+00:00"}],"thread":[{"id":13532,"source":"github","source_ref":"7026823278","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0106, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-13372 and says what differs; it is read like any other.","created_at":"2026-11-20T00:50:58+00:00"}]}