-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"The `internal/api/hosts.go` file in nebula-mesh v0.3.0 contains a comment at line 384.\n\n```go\n// API trusts the bearer token for authorisation; per-CA ownership is\n// enforced only in the Web layer (handleHostUpdate). Matches\n// handleCreateHost/handleDeleteHost behaviour.\n```\n\nThe comment sits inside `handleUpdateHost`, the handler that lets the caller change which network a host belongs to, which IP it claims, and which firewall rules apply. The function it names, `handleHostUpdate`, exists in a different package, `internal/web/handlers.go`, and looks like this at line 940:\n\n```go\nif op.Role != \"admin\" {\n network, err := w.store.GetNetwork(r.Context(), host.NetworkID)\n if err != nil {\n http.Error(rw, \"Internal Server Error\", http.StatusInternalServerError)\n return\n }\n ca, err := w.store.GetCA(r.Context(), network.CAID)\n if err != nil || ca.OwnerOperatorID != op.ID {\n http.Error(rw, \"Unauthorized\", http.StatusForbidden)\n return\n }\n}\n```\n\nTwo packages. Same Postgres rows. Same multi-tenant invariant, that an operator can only modify hosts under a CA they own. The Web layer reads `cas.owner_operator_id` and compares it against the session operator. The API layer reads the bearer token and trusts it.\n\nThe maintainer wrote the comment that explained why, and shipped the gap that the comment explained. CVE-2026-47724 is what that gap let through.\n\n## The bearer token\n\nnebula-mesh is the open-source control plane for Slack's Nebula mesh VPN. An operator runs it to sign certificates for hosts (laptops, phones, servers) joining a private overlay. v0.3.0 introduced multi-tenant operation: a single deployment can host multiple CAs, each owned by a different operator, and the ownership column `cas.owner_operator_id` is the line between \"your CA\" and \"someone else's CA.\"\n\nThe browser-facing Web UI gates every CA-scoped operation against that column. The HTTP API does not.\n\nThe bearer-token middleware lives in `internal/api/middleware.go`. It hashes the `Authorization: Bearer …` value with SHA-256, looks the hash up in `operator_api_keys`, attaches the resolved operator to the request context, and calls the next handler. If the token resolves, you are the operator who owns the key. If you are any operator with any active API key, you are authenticated to the entire `/api/v1/*` surface.\n\nThere is also a legacy fallback. If the deployment still uses a config-file `api.token`, that token resolves to no operator, and the `actorIsAdmin` helper treats no-operator as admin.\n\nTwo ways into the API. One of them does not even resolve to a person.\n\n## What the API layer let through\n\nI counted authorization calls across `internal/api/*.go` at v0.3.0. The pattern is unambiguous.\n\n| File | `canAccessCA` / `canAccessHost` / `actorIsAdmin` calls |\n| --- | --- |\n| `cas.go` | 7 |\n| `settings.go` | 2 |\n| `operators.go` | 1 (admin-only on create) |\n| `hosts.go` | 0 |\n| `networks.go` | 0 |\n| `firewall.go` | 0 |\n| `mobile_bundle.go` | 0 |\n| `audit.go` | 0 |\n\nThe author knew the pattern. `cas.go` uses it seven times. Every handler that touches a CA row reads `canAccessCA` first. The handlers that touch hosts, networks, firewall rules, mobile bundles, and audit logs do not.\n\nThree exploit chains follow directly. The GHSA-598g-h2vc-h5vg advisory, which is the upstream half of CVE-2026-47724, calls each of them out by route.\n\n### 1. Mint an admin API key for an admin you are not\n\n`POST /api/v1/operators/{id}/api-keys` is handled by `handleCreateOperatorAPIKey` at `internal/api/operators.go:118`. The handler loads the target operator, generates 32 bytes of random key material, hashes it, persists the hash against the target operator, and returns the plaintext to the caller.\n\n```go\nfunc (s *Server) handleCreateOperatorAPIKey(w http.ResponseWriter, r *http.Request) {\n id := chi.URLParam(r, \"id\")\n if _, err := s.store.GetOperator(r.Context(), id); err != nil {\n ...\n }\n var req createAPIKeyRequest\n if r.ContentLength > 0 {\n _ = json.NewDecoder(r.Body).Decode(&req)\n }\n\n keyBytes := make([]byte, 32)\n if _, err := rand.Read(keyBytes); err != nil {\n writeError(w, http.StatusInternalServerError, \"failed to generate api key\")\n return\n }\n plaintext := hex.EncodeToString(keyBytes)\n ...\n}\n```\n\nThere is no check that the caller is the target operator. There is no check that the caller is an admin. The peer handler one screen up, `handleCreateOperator`, has `if !actorIsAdmin(r.Context())`. The peer handler one screen down, `handleRevokeOperatorAPIKey`, does not.\n\n```\n$ curl -X POST -H \"Authorization: Bearer $LOW_PRIV_KEY\" \\\n https://mesh.example.com/api/v1/operators/$ADMIN_ID/api-keys \\\n -H \"Content-Type: application/json\" \\\n -d '{\"name\":\"audit\"}'\n\n{\"key\":\"a1b2c3...\",\"entry\":{\"id\":\"...\",\"operator_id\":\"$ADMIN_ID\",...}}\n```\n\nThe returned `key` resolves through the bearer middleware as the admin operator. You now have admin.\n\n### 2. Reenroll a host you do not own\n\n`POST /api/v1/hosts/{id}/reenroll` mints a fresh enrollment token for a host. The token is short-lived and grants the bearer the right to register a Nebula identity for that host on next call-in.\n\n```go\nfunc (s *Server) handleReenroll(w http.ResponseWriter, r *http.Request) {\n id := chi.URLParam(r, \"id\")\n host, err := s.store.GetHost(r.Context(), id)\n ...\n token, err := s.mintEnrollmentTokenForHost(r.Context(), host)\n ...\n writeJSON(w, http.StatusOK, map[string]string{\"token\": token})\n}\n```\n\nNo CA-ownership check. Any operator, or anyone holding the legacy config-file token, can mint an enrollment token for any host on the mesh: a laptop on the CTO's CA, a production database server on the platform CA, a field engineer's tablet on a customer CA. Redeem the token from a machine you control. The new identity inherits the host's network membership, IP, and firewall groups. The original host's next callback fails authentication.\n\n### 3. Walk away with a mobile device's identity\n\n`POST /api/v1/hosts/{id}/mobile-bundle` returns the YAML config plus a freshly generated private key for a mobile host, intended to be flashed onto the device during provisioning. The private key is not persisted on the server. The handler generates it, embeds it in the response, and forgets it.\n\n```go\nfunc (s *Server) handleMobileBundle(w http.ResponseWriter, r *http.Request) {\n id := chi.URLParam(r, \"id\")\n\n host, err := s.store.GetHost(r.Context(), id)\n ...\n if host.Kind != models.HostKindMobile {\n writeError(w, http.StatusBadRequest, \"host must be a mobile host\")\n return\n }\n\n caMgr, err := s.caForHost(r.Context(), host)\n ...\n bundle, err := mobilebundle.Build(r.Context(), s.store, resolver, host)\n ...\n w.Header().Set(\"Content-Type\", \"application/yaml; charset=utf-8\")\n w.WriteHeader(http.StatusOK)\n w.Write(bundle)\n}\n```\n\nThe only check is that the host's `Kind` is mobile. There is no check that the caller owns the CA that signed it. Any operator with an API key on the deployment can request the YAML bundle for any mobile host on the mesh, and the response is a complete, ready-to-flash Nebula identity for that device. The legitimate device, when it tries to provision later, gets a different identity from a later signing call; the attacker, having received the first one, has already joined the mesh as that host.\n\nThese three are not subtle. The Slack engineer who wrote the GHSA advisory wrote three exploit chains, and they were these three.\n\n## The Web layer had the check\n\nThe Web layer's version of host-update lives at `internal/web/handlers.go:917`. It does what the API comment said happens elsewhere:\n\n```go\nfunc (w *WebServer) handleHostUpdate(rw http.ResponseWriter, r *http.Request) {\n ...\n host, err := w.store.GetHost(r.Context(), hostID)\n ...\n op := getOperatorFromSession(r)\n\n // Ownership check\n if op.Role != \"admin\" {\n network, err := w.store.GetNetwork(r.Context(), host.NetworkID)\n if err != nil {\n http.Error(rw, \"Internal Server Error\", http.StatusInternalServerError)\n return\n }\n ca, err := w.store.GetCA(r.Context(), network.CAID)\n if err != nil || ca.OwnerOperatorID != op.ID {\n http.Error(rw, \"Unauthorized\", http.StatusForbidden)\n return\n }\n }\n ...\n}\n```\n\nThree rows. Host to network. Network to CA. CA to owner. If the owner is not the session operator, return Forbidden. The same chain appears in `handleHostCreate`, `handleHostDelete`, `handleHostBlock`, `handleHostRotateCert`, `handleNetworkUpdate`, `handleFirewallRuleCreate`. The Web layer is built on the assumption that an operator can only touch their own CA's hosts.\n\nThe API layer is built on the assumption that the Web layer is built on that assumption.\n\n## The function existed\n\n`internal/api/authz.go` lands in nebula-mesh as a small file at v0.3.3, but the helpers it consolidates existed in earlier versions split across files. `cas.go` had `canAccessCA`. The same module that imports `chi/v5` and `uuid` and `bcrypt` for `handleCreateOperatorAPIKey` could have imported `canAccessCA`. It did not.\n\nThe comment at `hosts.go:384` was not a TODO. It was not `// FIXME: add authz check later`. It was a flat declarative sentence about where authorization happened. The API trusts the bearer token. Ownership is enforced in the Web layer. Matches sibling behaviour.\n\nThe sibling behaviour was the bug.\n\n## The fix is the comment, removed\n\nCommit `8baaace` landed on May 20, 2026, five days after v0.3.0 shipped. The commit message reads:\n\n> fix(api): enforce CA-ownership and admin gates on /api/v1/\\* (GHSA-598g-h2vc-h5vg)\n>\n> New internal/api/authz.go consolidates per-handler authorisation. Mirrors internal/api/cas.go canAccessCA pattern. Discharge comment about per-CA ownership being Web-only removed.\n\nThe diff for `handleUpdateHost` deletes the four lines of comment and inserts three lines of call:\n\n```diff\n- // API trusts the bearer token for authorisation; per-CA ownership is\n- // enforced only in the Web layer (handleHostUpdate). Matches\n- // handleCreateHost/handleDeleteHost behaviour.\n+ ok, err := s.canAccessHost(r.Context(), host)\n+ if err != nil || !ok {\n+ writeError(w, http.StatusForbidden, \"forbidden\")\n+ return\n+ }\n```\n\nThe comment occupied the lines where the call needed to be. The fix was to delete the comment and write the call.\n\nThe other twenty-three vulnerable handlers got the same treatment. `handleCreateOperatorAPIKey` gained an `actorIsAdmin` check. `handleReenroll` gained `canAccessHost`. `handleMobileBundle` gained `canAccessHost`. The diff is large and boring. The hard part was deciding that the API layer needed an authorization check at all, and the maintainer had decided against it in writing, in the file, with a comment that named the sibling handlers it was modeling itself on. The fix is not a feature. The fix is a reversal of a decision.\n\n## What the pattern is\n\nThe Web layer and the API layer are two packages in the same repository implementing the same contract over the same database. Both have a `handleHostUpdate`. Both call `store.UpdateHost`. Both produce HTTP responses. One imports the shared authorization helper from a sibling file in the same package. The other names the helper's call site in a comment and does not call it.\n\nThis is the **parallel-implementation-gap** pattern. The canonical module enforces the check. The divergent module exposes the same client-facing contract and does not. The CVE names the divergent module. CVE-2026-47724's affected-versions field is `<= 0.3.0`. The Web layer is not affected. The API layer is the entire CVE.\n\nThe within-pattern variant in nebula-mesh is unusual only in its explicitness. In most exhibits, Astro's Cloudflare adapter, mcp-atlassian's Bitbucket branch, MLflow's FastAPI surface, the divergent module never mentions the shared utility. The author of the divergent module has not, as far as the commit history reveals, ever read the code in the canonical module. The gap is silent.\n\nIn nebula-mesh the gap is documented. The maintainer wrote the comment. The maintainer named `handleHostUpdate` in the comment. The maintainer named `handleCreateHost` and `handleDeleteHost` as the siblings whose behaviour was being matched. Every authoring step that would normally signal \"I should go look at the canonical module and check whether my divergent module agrees\" was taken. The comment is the evidence that the lookup happened. The conclusion was that the divergent module would not enforce the check.\n\nThe pattern usually surfaces in code review as \"did the second author know about the first author's check.\" Here the answer is yes. The second author was the first author. They knew. They wrote it down.\n\nThe deeper pattern, the one Arcane's CVE-2026-47125 named four weeks ago and that CVE-2026-47724 re-instances now, is **design-debt-driver**: when the authorization primitive is per-handler, when every handler has to remember to call `canAccessHost`, the recurring symptom is handlers that forget. The `cas.go` author remembered seven times. The `hosts.go` author named the primitive in a comment and did not call it. The natural home for an authorization check that applies to every CA-scoped endpoint is the middleware layer. nebula-mesh's middleware authenticates the bearer token and stops there. Every handler is on its own.\n\nA reader who wants to know which handlers are gated has to read each handler. A maintainer adding a new endpoint has to remember to add the check. A reviewer auditing the surface has to count `canAccessCA` calls against route definitions and check that the count matches. The `hosts.go` comment is what it looks like when that audit happens, finds the gap, and decides the gap is fine.\n\n## What the comment was\n\nThe comment was the policy. It told future readers, including the future maintainer who would write the fix, exactly what the design was: API trusts the bearer token, per-CA ownership is Web-only, the siblings agree. The siblings did agree. The comment was an accurate description of the code.\n\nCVE-2026-47724 is the description of why an accurate description of the code was not enough.\n","closing_line":"The comment was the policy. The fix was deleting the comment.","hook_md":"A comment at `internal/api/hosts.go:384` of nebula-mesh v0.3.0 reads: *\"API trusts the bearer token for authorisation; per-CA ownership is enforced only in the Web layer (handleHostUpdate). Matches handleCreateHost/handleDeleteHost behaviour.\"* The Web layer's `handleHostUpdate` does have the check. The API layer's does not. CVE-2026-47724 is what happens in the four lines of comment between writing it and removing it.","post_id":593,"slug":"nebula-mesh-api-documented-the-authorization-gap","title":"CVE-2026-47724: nebula-mesh's API Layer Documented the Authorization Gap. The Web Layer Had the Check.","type":"initial","unreadable_sentence":"The comment explaining why the gate was missing was in the file the gate should have been in."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCasK06gAKCRDeZjl4jgkQ Jmq/AQCQBT9P5aWmfHN33d/lAwVQyj0+2i1gTu9abcjSo0C9XwD/ViKLs+zclKWh CWQHa7Qx2UHO8IzEb54Wpz/iD8sxvgQ= =ux91 -----END PGP SIGNATURE-----