{"id":"XE-0138","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"236","source_url":"https://github.com/xeprotocol/xe/issues/236","reporter_id":45,"title":"node: canAttest accepts forged provider identifiers via a zero-mid directory match, and RequestAttestation has no timekeeper gate","area":null,"claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0116","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-10-31T15:36:12.691862+00:00","updated_at":"2026-11-10T18:15:38.814475+00:00","source_created_at":"2026-10-31T15:35:08+00:00","told_at":"2026-11-05T22:24:42+00:00","status_changed_at":"2026-11-05T22:24:29.653359+00:00","url":"https://bounty.xe.network/XE-0138","body":"node: canAttest accepts forged provider identifiers via a zero-mid directory match, and RequestAttestation has no timekeeper gate\n\n**Suggested severity: Low–Medium** (I am deliberately not claiming a higher tier — see Impact)\n\n**Area:** timekeeper attestation issuance — `node/attestation.go`, `node/node.go`\n**Pin:** `xeprotocol/xe` HEAD `978785929bc17a2f4ab30c383e5fc9cf4d634512` (2026-10-15)\n**Duplicate check:** searched for `canAttest`, `zeroMid`, `\"0000000000000000\"`, `forged attestation`, `identifier forgery`, `directory attestation` — no existing issue covers this. Related but distinct: #54 (rate-limit TOCTOU), #19/#23 (freshness on sync), #25 (VM existence gate).\n\n## Summary\n\n`Node.canAttest` (`node/attestation.go:32-55`) is the authorisation gate for attestation requests. For any identifier that is not a live lease, it falls through to a directory check that accepts an identifier of the form\n\n    account[:32] + \"0000000000000000\" + account[48:]\n\nfor **any** registered provider `account`. That identifier is neither a lease nor a directory account, yet the node signs it.\n\nSeparately, `Node.RequestAttestation` (`node/node.go:2218-2235`) signs with `n.KeyPair` without checking whether this node is actually a timekeeper (i.e. whether its key is in the `sys.timekeepers` keyset).\n\n## Affected code\n\nnode/attestation.go:32-55\n\n    func (n *Node) canAttest(identifier string) error {\n        if lease := n.GetLease(identifier); lease != nil {\n            switch lease.State {\n            case core.LeaseCreated, core.LeaseAccepted:\n                return nil\n            }\n            return fmt.Errorf(\"lease %s is %s: no attestation-gated transitions remain\", ...)\n        }\n        if n.Directory != nil && len(identifier) == 64 {\n            if _, ok := n.Directory.Lookup(identifier); ok {\n                return nil\n            }\n            const zeroMid = \"0000000000000000\"\n            if identifier[32:48] == zeroMid {\n                for _, reg := range n.Directory.List() {\n                    a := reg.Account\n                    if len(a) == 64 && a[:32] == identifier[:32] && a[48:] == identifier[48:] {\n                        return nil          // <-- accepts a forged identifier\n                    }\n                }\n            }\n        }\n        return fmt.Errorf(\"unknown attestation identifier %s: not a live lease or a registered provider\", ...)\n    }\n\nnode/node.go:2218-2235\n\n    func (n *Node) RequestAttestation(source, identifier string) (*core.TimekeeperAttestation, error) {\n        if len(identifier) != 64 { return nil, fmt.Errorf(\"invalid attestation identifier length: %d\", len(identifier)) }\n        if err := n.allowAttestation(source, identifier); err != nil { return nil, err }\n        if err := n.canAttest(identifier); err != nil {\n            logging.Warnf(\"Attestation request from %s rejected: %v\", source, err)\n            return nil, err\n        }\n        n.recordAttestation(source, identifier)\n        ts := core.Now().UnixNano()\n        return core.SignAttestation(identifier, ts, n.KeyPair)   // no timekeeper gate\n    }\n\nThe directory is public: `GET /directory` returns every registered provider account.\n\n## Reproduction\n\n    GOTOOLCHAIN=auto go build -trimpath -buildvcs=false -o xe ./cmd/xe\n    ./xe node --api-port 18080 --api-bind 127.0.0.1\n\nRegistered directory account (from GET /directory):\n\n    c20d6fc8151ae99de5fd06c2b6dc8225ce22697448fba94abcd72b3d2cf8ff1b\n\nForged identifier = account[:32] + \"0000000000000000\" + account[48:]:\n\n    c20d6fc8151ae99de5fd06c2b6dc82250000000000000000bcd72b3d2cf8ff1b\n\n### Request — HTTP 200, attestation issued\n\n    POST /attestation/request\n    Content-Type: application/json\n\n    {\"lease_hash\":\"c20d6fc8151ae99de5fd06c2b6dc82250000000000000000bcd72b3d2cf8ff1b\"}\n\n    {\n      \"public_key\":\"b5373a066fad131039357c292caf0f2fe97101ba05b4fc7623fd765c898e32d2\",\n      \"timestamp\":1793395907883507785,\n      \"signature\":\"83242ebcabddb7c875a23204fd40936140498a1b47a30f55dc94b1033139040d3a601bebceb257d975dd72a111ebc231323cdb6a0439514ee08fd894ba1a8906\"\n    }\n\n### Control 1 — same prefix/suffix, middle NOT zeros → rejected\n\n    {\"lease_hash\":\"c20d6fc8151ae99de5fd06c2b6dc82251111111111111111bcd72b3d2cf8ff1b\"}\n    HTTP 400 {\"error\":\"unknown attestation identifier c20d6fc8151a...: not a live lease or a registered provider\"}\n\n### Control 2 — unrelated identifier → rejected\n\n    HTTP 400 {\"error\":\"invalid attestation identifier length: 60\"}\n\nThe only difference between acceptance and rejection is the 16 middle hex characters. Deterministic, and requires no secret material — only the public directory listing.\n\n## Impact — stated honestly\n\nI am **not** claiming this is a mint bypass or escrow theft. Two independent controls stop that:\n\n1. **Attestations are bound to the settled lease hash.** `core/attestation.go:82` calls `VerifyAttestation(&a, leaseHash)`, and `AttestationPayload` (`core/attestation.go:11-21`) hashes the lease hash into the signed payload.\n2. **An attacker cannot choose a lease hash.** `core/ledger.go:1592` sets `LeaseHash: b.Hash` — the lease hash is the block hash, not an attacker-supplied field.\n\nWhat it does give:\n\n- **Attestation issuance for identifiers that are neither leases nor accounts.** The gate's stated contract is not what the code enforces. Any future consumer that trusts \"the timekeeper signed this identifier\" inherits the defect.\n- **Rate-limit amplification beyond #54.** `allowAttestation` keys on `source + \":\" + identifier`, and the identifier space is unbounded (any provider account; the middle 16 hex only needs to be zeros). #54 covers concurrent requests for one identifier; this widens the key space without limit.\n- **No timekeeper gate.** A node not in the `sys.timekeepers` keyset still signs. `core.ValidateAttestations` rejects untrusted public keys, so there is no direct consensus impact today — but a misconfigured or compromised non-timekeeper node will burn signing CPU and produce well-formed-looking signatures.\n\n## Suggested fix\n\n1. In `canAttest`, drop the zero-mid fallback entirely, or require the constructed identifier to resolve to a lease whose `Provider` matches the matched directory account. The current check compares only account bytes, with no lease lookup and no provider binding.\n2. In `RequestAttestation`, verify the node's own key is a member of the active `sys.timekeepers` keyset before signing, and error otherwise. This makes the endpoint safe to expose on any node.\n3. Consider binding the attestation payload to the operation type (as PR #23 does for freshness) so an attestation cannot be replayed across lease operations.\n\n## Notes\n\n- Verified against upstream `master` at the pin: the zero-mid branch is still present.\n- All testing was done against a node I ran myself on `127.0.0.1`. No third-party node was contacted.\n- No PR opened; happy to prepare one if the fix direction is acceptable.\n","patch_refs":[{"id":236,"repo":"xeprotocol/xe","kind":"pr","ref":"237","title":"fix(node): reject forged zero-mid attestation identifiers and enforce timekeeper gate (fixes #236)","url":"https://github.com/xeprotocol/xe/pull/237","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-31T21:12:23.136192+00:00"}],"thread":[{"id":185,"source":"github","source_ref":"6627347741","author":"fahriiri206","team":false,"body":"Additional delta on the same endpoint, from an independent review (commit 02e9641b, PoCs executed against a repo copy): the 15 s attestation limit in `allowAttestation` (`node/attestation.go:86-105`) is keyed on `source + \":\" + identifier`, where `source` is `clientIP(r)` — and `clientIP` (`api/handler.go:375-393`) returns the last `X-Forwarded-For` element verbatim whenever the TCP peer is loopback, which is the default `--api-bind 127.0.0.1` deployment. Rotating the header therefore makes the limit non-binding (observed: 3/3 requests signed with rotating XFF vs the limit's intent), and the same string lands in `logging.Warnf(\"Attestation request from %s rejected: ...\")`, so the audit trail is attacker-forgeable. Second vector: unbounded XFF length pins memory in `node.attRateMap` (swept every 15 s) — observed `XFF len=900002 -> 200`, source length 900002 bytes. Filed separately as the inverse-direction rate-limit issue; noting here so the #236 fix scope covers keying the limit on something the client cannot choose.","created_at":"2026-11-04T09:24:47+00:00"},{"id":518,"source":"github","source_ref":"6671123865","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0116, 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, reply with what differs and we will look again.","created_at":"2026-11-05T22:24:42+00:00"}]}