{"id":"XE-9889","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":730,"title":"Unbounded State Inflation & OOM DoS: Directory.Register lacks map capacity limit permitting unauthenticated memory exhaustion","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0001","tracked":true,"internal_ref":"#1062","internal_url":"https://github.com/xeprotocol/core/issues/1062","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T08:04:23.015061+00:00","updated_at":"2026-11-25T17:15:51.184343+00:00","source_created_at":null,"told_at":"2026-11-20T00:33:18.278058+00:00","status_changed_at":"2026-11-20T00:33:18.264881+00:00","url":"https://bounty.xe.network/XE-9889","body":"## Vulnerability Summary\n\nIn `directory/directory.go:17-50`, `Directory` manages peer routing registrations mapping accounts to libp2p peer addresses:\n```go\ntype Directory struct {\n\tmu            sync.RWMutex\n\tregistrations map[string]*Registration\n\tttl           time.Duration\n}\n```\n\nIn `directory/directory.go:35-50`:\n```go\nfunc (d *Directory) Register(reg *Registration) error {\n\tif err := VerifyRegistration(reg); err != nil {\n\t\treturn err\n\t}\n\n\td.mu.Lock()\n\tdefer d.mu.Unlock()\n\n\texisting, ok := d.registrations[reg.Account]\n\tif ok && existing.Timestamp >= reg.Timestamp {\n\t\treturn nil\n\t}\n\n\td.registrations[reg.Account] = reg\n\treturn nil\n}\n```\n\nNotice that:\n1. `Directory.Register` is publicly exposed via the unauthenticated HTTP API endpoint `POST /directory/register` (`api/directory.go:11-23`) and via P2P gossip.\n2. Generating a valid `directory.Registration` requires only generating an arbitrary ephemeral Ed25519 keypair in memory and signing `canonicalBytes`. It requires **zero native tokens, zero gas, zero on-chain transactions, and zero PoW**!\n3. `d.registrations` has **NO capacity cap (no MaxRegistrations)**, no LRU eviction, and relies solely on passive periodic pruning (`d.Prune()`, which only evicts items older than 30 minutes).\n\n---\n\n## Vulnerable Code Locations\n\n- `directory/directory.go:35-50`:\n  `Directory.Register` inserts new registrations directly into `d.registrations[reg.Account]` without checking any maximum map capacity or bounding overall memory usage.\n- `directory/verify.go:29-53`:\n  `VerifyRegistration` checks only cryptographic Ed25519 signature validity. It does not enforce proof-of-work, account on-chain existence, or rate limiting per IP/subnet.\n\n---\n\n## Attack & Failure Scenario\n\n1. An unauthenticated attacker runs a simple script that generates ephemeral Ed25519 keypairs in a tight loop (~5,000 to 10,000 keys per second).\n2. For each keypair, the attacker sends a signed `directory.Registration` to `POST /directory/register` or floods the `/xe/dir-gossip/1.0.0` libp2p topic.\n3. Every registration passes `VerifyRegistration` because the signature is mathematically valid for the newly generated ephemeral public key.\n4. The node stores all incoming registrations into `d.registrations`.\n5. In less than 10 minutes, the attacker floods several million unique registration objects into memory (~1 GB to 4 GB of RAM), driving the node host into kernel Out of Memory (OOM) panic and terminating the node daemon!\n\n---\n\n## Impact\n\n1. **Remote Unauthenticated Node Crash (Denial of Service)**:\n   Any external entity can trigger complete OOM node crashes across all network validators and seed nodes without spending gas or solving PoW.\n2. **Directory Lookup Degradation**:\n   Memory bloat degrades lookup performance and list pagination (`d.List()`).\n\n---\n\n## Remediation\n\nEnforce a strict maximum capacity on `d.registrations` with FIFO / LRU eviction, and require minimum proof-of-work or an active on-chain account balance to register in the directory:\n```go\nconst MaxDirectoryEntries = 50000\n\nfunc (d *Directory) Register(reg *Registration) error {\n\tif err := VerifyRegistration(reg); err != nil {\n\t\treturn err\n\t}\n\n\td.mu.Lock()\n\tdefer d.mu.Unlock()\n\n\tif len(d.registrations) >= MaxDirectoryEntries {\n\t\td.pruneLocked()\n\t\tif len(d.registrations) >= MaxDirectoryEntries {\n\t\t\treturn fmt.Errorf(\"directory full: maximum capacity reached\")\n\t\t}\n\t}\n\n\texisting, ok := d.registrations[reg.Account]\n\tif ok && existing.Timestamp >= reg.Timestamp {\n\t\treturn nil\n\t}\n\n\td.registrations[reg.Account] = reg\n\treturn nil\n}\n```","patch_refs":[],"thread":[{"id":13207,"source":"desk","source_ref":"reply:11229","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0001, 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-9889 and says what differs; it is read like any other.","created_at":"2026-11-20T00:33:18.260051+00:00"}]}