Skip to content

fix(mdm): provider MDM read-only + close webhook trust-injection (T-021/SEC-004) - #270

Merged
Gajesh2007 merged 4 commits into
masterfrom
worktree-mdm-webhook-hardening
Jun 4, 2026
Merged

Gajesh2007 merged 4 commits into
masterfrom
worktree-mdm-webhook-hardening

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes the MicroMDM webhook trust-injection gap (threat-model T-021 / SEC-004) and adds a hard guarantee that the coordinator's MDM capability over a provider's Mac is read-only.

The MDM SecurityInfo callback is the coordinator's independent check that a provider isn't lying about SIP/Secure Boot. That callback arrived over POST /v1/mdm/webhook with no auth, no body cap, and no check that the coordinator asked for it — and the late-arrival path (main.go) upgraded a self_signed provider straight to hardware trust from attacker-controlled SIP/SecureBoot values. A malicious-but-enrolled operator could disable SIP (to read plaintext prompts / run a modified binary / serve manipulated models), then POST a forged SIP=true webhook for their own UDID and be promoted to hardware trust — defeating the core attestation guarantee.

What changed

1. Read-only MDM (you can't do anything to a provider's machine)

  • assertReadOnlyCommand — a single chokepoint with an exhaustive allowlist {SecurityInfo, DeviceInformation} (both pure queries). Both command senders route through it, so any mutating command (DeviceLock, EraseDevice, InstallProfile, RestartDevice, ShutDownDevice, …) fails closed before reaching MicroMDM. Adding a command type now requires an explicit, reviewable allowlist change.

2. Solicited-response gate (the real anti-forgery fix)

  • Every issued command UUID is tracked (TTL-bounded, one-shot). HandleWebhook parses the response's CommandUUID and drops any webhook whose UUID the coordinator didn't issue, before any waiter or trust-upgrade callback runs. UUIDs are random and never exposed, so a reachable attacker can't match an in-flight command. Also rejects a solicited UUID replayed against a different device's UDID. This closes both the waiter path and the late-callback path.

3. HTTP hardening

  • 1 MiB MaxBytesReader body cap — kills the unbounded-body memory DoS.
  • Optional shared secret (EIGENINFERENCE_MDM_WEBHOOK_SECRET, via ?token= or X-Webhook-Token, constant-time) — rejects unauthorized callers before the body is read. MicroMDM is co-located, so the secret never crosses the public network.

Defense-in-depth, layered

Layer Config required Stops
Solicited-command (CommandUUID) gate none — always on Forged/unsolicited trust upgrades
Read-only allowlist none — always on Any mutating command to a provider Mac
Body cap none — always on Unbounded-body DoS
Shared secret optional env Unauthorized callers reaching the endpoint at all

Testing

go test ./... green (12 packages). New tests:

  • TestAssertReadOnlyCommand — reads allowed, every mutating command blocked.
  • TestParseCommandUUID, TestCommandTrackingLifecycle — parse + track→consume (one-shot, TTL, unknown-UUID).
  • TestWebhookDropsUnsolicitedSecurityInfo — forged SIP=true is dropped; solicited is honored.
  • TestWebhookDropsUUIDForDifferentDevice — UUID/UDID replay dropped.
  • TestMDMWebhookSecretGate / ...NoSecretConfigured — HTTP secret layer.

Deployment notes (not code)

  • MicroMDM already listens on localhost:9002 (coordinator-only); keep it bound to loopback.
  • To enable the optional secret: set EIGENINFERENCE_MDM_WEBHOOK_SECRET on the coordinator and append ?token=<same> to MicroMDM's command-webhook-url. Safe to roll out without it — the CommandUUID gate is the mandatory protection.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

@vercel

vercel Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
d-inference Ready Ready Preview Jun 4, 2026 2:56am
d-inference-console-ui-dev Ready Ready Preview Jun 4, 2026 2:56am
d-inference-landing Ready Ready Preview Jun 4, 2026 2:56am

Request Review

@github-actions

github-actions Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

This PR partially mitigates the unauthenticated MDM webhook (T-021/SEC-004) by introducing an optional shared-secret gate, but the mitigation is advisory-only and leaves the critical path open if the secret is not configured.


Trust Boundaries Touched

  • TB-005 — Coordinator → Apple MDM/MDA trust services (MDM webhook ingestion path)
  • TB-009 — Apple attestation chain (cross-cutting; trust-level elevation depends on webhook integrity)

Threat Analysis

T-021 — Unauthenticated MDM webhook injection manipulates provider trust state
⚠️ Partially strengthens, but remains open by default.

  • coordinator/cmd/coordinator/main.go:387–399: A shared secret is now plumbed through SetMDMWebhookSecret() when EIGENINFERENCE_MDM_WEBHOOK_SECRET is set. This is the right direction.
  • However, the secret is opt-in. If the env var is absent, the code emits a logger.Warn and falls through with no authentication — identical security posture to before. SEC-004 remains open in any deployment that doesn't explicitly set the variable.
  • The comment at line 388 claims the "solicited-command (CommandUUID) gate" provides fallback protection, but per TB-005's own description this correlation does not currently exist: "No MDM command UUID correlation: the webhook response is not bound to a specific outbound command." The fallback narrative is inaccurate and may give operators false confidence that skipping the secret is safe.
  • T-036 is also affected: the unauthenticated webhook is one of the paths to fraudulent TrustHardware elevation. The same opt-in caveat applies.

T-038 — Missing ReadHeaderTimeout and MaxHeaderBytes enable slow-header attacks
ℹ️ Neutral — this diff does not touch HTTP server config.

The http.Server struct configuration (reported at cmd/coordinator/main.go:496 in the threat model) is not modified in this PR. SEC-027 remains open.

T-032 — Solana wallet mnemonic exfiltration
ℹ️ Neutral — no changes to billing or mnemonic handling.


New Attack Surface / Uncovered Issues

  1. SetMDMWebhookSecret() implementation not in diff. The actual enforcement logic in coordinator/api/server.go (listed as a changed file but not shown) is the critical piece. If the server validates the secret by reading a query parameter (as the comment implies, ?token=<secret>), ensure:

    • Comparison uses crypto/subtle.ConstantTimeCompare, not ==. A timing attack here leaks the secret byte-by-byte.
    • The secret is extracted from the URL before it is logged anywhere (access logs, tracing, error messages). Query-parameter secrets commonly leak into log aggregators.
    • An empty-string secret (EIGENINFERENCE_MDM_WEBHOOK_SECRET="") must be treated as "not configured" — the current if webhookSecret != "" guard does handle this correctly.
  2. coordinator/deploy/start.sh not shown. If this script is the deployment entrypoint and does not document or enforce EIGENINFERENCE_MDM_WEBHOOK_SECRET, the warn-and-continue path will silently be the default in production. Recommend making the secret required in the start script for production targets, or failing fast (os.Exit(1)) rather than warning.

  3. coordinator/mdm/mdm.go and coordinator/mdm/mdm_security_test.go not shown. These files are listed as changed. If mdm_security_test.go is a new file it should cover: (a) requests with wrong/missing secret are rejected with 401/403, (b) requests with correct secret pass, (c) empty secret does not accidentally match. If the test coverage is absent, the enforcement cannot be considered validated.


Open Findings Status

  • SEC-004 — ⚠️ Partially addressed (optional secret added), not resolved. Requires the secret to be mandatory in production and SetMDMWebhookSecret() enforcement to use constant-time comparison.
  • SEC-027 — Not addressed by this PR.
  • SEC-021 — Not addressed by this PR.

🔐 Threat model: docs/threat-model.yaml · Updates on each push to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d908fbd9a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +391 to +392
if webhookSecret := os.Getenv("EIGENINFERENCE_MDM_WEBHOOK_SECRET"); webhookSecret != "" {
srv.SetMDMWebhookSecret(webhookSecret)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wire the webhook secret into MicroMDM's callback URL

When EIGENINFERENCE_MDM_WEBHOOK_SECRET is set here, the server starts rejecting webhook calls that lack the token, but the repo's MicroMDM launch path still uses coordinator/deploy/start.sh with -command-webhook-url http://localhost:8080/v1/mdm/webhook and does not append ?token=... or set the X-Webhook-Token header. In deployments that follow that script and enable the new recommended secret, every legitimate SecurityInfo/MDA callback will get 403 before the MDM client sees it, so provider hardware trust verification will time out.

Useful? React with 👍 / 👎.

Comment thread coordinator/mdm/mdm.go Outdated
// matching a webhook response. Comfortably longer than the 90s SecurityInfo
// wait to allow for late (Power Nap / APN) delivery, short enough to bound the
// forge window if a UUID ever leaked.
const outstandingCommandTTL = 10 * time.Minute

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Extend the command TTL past APN sleep delays

For providers whose Mac is asleep and APN delivery follows the Power Nap cadence called out in main.go (~15 minutes), this 10-minute window expires before a genuine SecurityInfo response can arrive. consumeCommand then treats that response as stale before dispatching to the late-arrival callback, so the recovery path for timed-out verifications never fires and the provider remains self_signed despite a valid MDM response.

Useful? React with 👍 / 👎.

…injection

Hardens the coordinator↔MicroMDM boundary so (a) the coordinator can only ever
READ a provider's security posture, never act on the machine, and (b) the
unauthenticated webhook can no longer be used to forge a hardware-trust upgrade
(threat-model T-021 / SEC-004).

Read-only enforcement:
- assertReadOnlyCommand is a single chokepoint with an exhaustive allowlist
  {SecurityInfo, DeviceInformation}. Both command senders go through it, so any
  attempt to issue a mutating command (DeviceLock, EraseDevice, InstallProfile,
  RestartDevice, …) fails closed before reaching the device. Enrolling a
  provider grants visibility, never control.

Solicited-response gate (the real anti-forgery fix):
- Every issued command UUID is tracked (TTL-bounded, one-shot). HandleWebhook
  now parses the response's CommandUUID and drops any webhook whose UUID was not
  issued by the coordinator, before any waiter or trust-upgrade callback runs.
  Command UUIDs are random and never exposed, so an attacker who reaches the
  webhook cannot match an in-flight command — closing the path that let a forged
  "SIP=true" SecurityInfo promote a self_signed provider to hardware. Also
  rejects a solicited UUID replayed against a different device's UDID.

HTTP layer:
- Body cap (1 MiB MaxBytesReader) stops the unbounded-body memory DoS.
- Optional shared secret (EIGENINFERENCE_MDM_WEBHOOK_SECRET, via ?token= or
  X-Webhook-Token, constant-time) rejects unauthorized callers before the body
  is read. MicroMDM is co-located, so the secret never crosses the public net.

Tests: read-only allowlist (reads pass / mutating blocked), CommandUUID parse,
track→consume lifecycle (one-shot + TTL), webhook drops unsolicited &
UDID-mismatched responses, and the HTTP secret gate. go test ./... green (12 pkgs).
The solicited-command gate's security rests on CommandUUID secrecy. The verbose
plist preview echoed the device response (incl. the CommandUUID) at Info level —
a side-channel for anyone with log access. Demote the raw preview to Debug; keep
the structured (size/has_*) summary at Info.
…-up)

Threat-model review flagged that the shared-secret check is opt-in. The
CommandUUID gate is the mandatory protection, but emit a startup Warn when MDM
is enabled without EIGENINFERENCE_MDM_WEBHOOK_SECRET so a misconfigured
deployment is visible rather than silent.
…Power Nap

Two review follow-ups:

- start.sh now appends ?token=$EIGENINFERENCE_MDM_WEBHOOK_SECRET to MicroMDM's
  -command-webhook-url when the secret is set. Without this, enabling the
  coordinator's recommended webhook secret would 403 every legitimate
  SecurityInfo/MDA callback (MicroMDM can't set a header on the command
  webhook), stalling provider hardware-trust verification. The coordinator
  accepts the token via ?token= or X-Webhook-Token (HandleMDMWebhook).

- outstandingCommandTTL 10m -> 30m. A sleeping Mac delivers its SecurityInfo
  response on a ~15-minute Power Nap cadence; at 10m the issued command UUID
  expired first, so consumeCommand dropped the genuine response as stale and
  the self_signed->hardware late-recovery path never fired. 30m covers the
  delay while still bounding the forge window for a random, localhost-only UUID.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2ba83d290

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# SecurityInfo/MDA callback and stall provider hardware-trust verification.
MDM_WEBHOOK_URL="http://localhost:8080/v1/mdm/webhook"
if [ -n "${EIGENINFERENCE_MDM_WEBHOOK_SECRET:-}" ]; then
MDM_WEBHOOK_URL="${MDM_WEBHOOK_URL}?token=${EIGENINFERENCE_MDM_WEBHOOK_SECRET}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge URL-encode the webhook token parameter

When EIGENINFERENCE_MDM_WEBHOOK_SECRET contains query-significant characters (for example a standard base64 secret with + or &), this constructs a callback URL whose token value is not the same string the coordinator later compares: r.URL.Query().Get("token") decodes + as space and treats & as a separator before the constant-time comparison. In deployments that generate random/base64 secrets, legitimate MicroMDM callbacks can therefore be rejected with 403; encode the value before appending it or require a URL-safe secret alphabet.

Useful? React with 👍 / 👎.

@Gajesh2007
Gajesh2007 merged commit 93573cb into master Jun 4, 2026
20 of 23 checks passed

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference — b2ba83d2 Deployed Jun 4, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — b2ba83d2 Deployed Jun 4, 2026 by vercel[bot]
Preview – d-inference-landing — b2ba83d2 Deployed Jun 4, 2026 by vercel[bot]
benchmarks — b2ba83d2 Deployed Jun 4, 2026 by Gajesh2007 via E2E Benchmarks #554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant