Skip to content

feat(setup): report each tool's setup outcome every run [WEB-6392] - #446

Merged
iyadzargar merged 55 commits into
stagingfrom
WEB-6392
Nov 30, 2026
Merged

iyadzargar merged 55 commits into
stagingfrom
WEB-6392

Conversation

@iyadzargar

@iyadzargar iyadzargar commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Refs WEB-6392

What

  1. Every run reports. Each setup run now reports its start and end. It also reports each tool as configured, skipped or deferred, with a reason and the file it wrote. This works from the binary and from the Python MDM scripts on Mac, Linux and Windows, Antigravity's included.
  2. Backfill and hook errors. Every backfill run sends its outcome. Setup forwards new entries from each hook's error.log to the gateway.
On the device Before After
Tool not installed Reported as connected skipped, "Cursor is not installed"
Copilot or Antigravity hooks fail for every user Reported as connected, or nothing sent One deferred report with the tamper state
Backfill run cut short by a cap No outcome sent stopped_by_cap, carried to the next run if unsent
Hook error in error.log Stays on the device Forwarded, up to 25 per tool per run, at most 7 days old

Why

  1. Every tool looked deployed. Support could not tell a working tool from a tool that was never installed.
  2. Errors stayed local. Hook errors stayed in a log on the device, and a cleanup step deleted Cursor's log before anyone read it.

How

  1. One installed check. Each MDM script carries the same tool_installed() check that the binary uses. tests/test_tool_installed.py keeps the copies identical, because the scripts run alone through curl.
  2. Reports never block setup. A report or forwarding failure never stops the install. Keys go to curl through a config file, not the command line.
  3. Forward before cleanup. Hook errors go out before the migration sweep runs.
  4. Default folders only. Forwarding reads each tool's default folder. A user who moves it with CLAUDE_CONFIG_DIR or COPILOT_HOME gets no forwarded errors. Setup ignores these variables at install too, and root cannot see a user's shell variables. Pugaz accepted this limit, because the case is rare.

Testing

  • pytest tests/test_mdm_setup_status.py tests/test_tool_installed.py tests/claude_code binary/tests with a temporary HOME: 2,959 passed, 8 failed
  • pytest on the same 8 tests on plain staging: the same 8 failed, so they come from before this branch
  • install.ps1 onboarding on a Windows Server 2022 Azure VM as SYSTEM: 4 tools configured, Augment skipped as not installed, backfill outcome completed
  • onboard.sh as root in a Linux Docker container: installed, not installed and write-failed tools each sent the right status
  • Not tested: a real macOS VM and Windows as a signed-in user, because access is still pending

Proof

  • 8 failed, 2959 passed, 40 skipped on this branch. The 8 failures need /opt/unbound on the test machine and also fail on staging.

Risk and rollout

Start review at: binary/src/unbound_hook/setup_cmd.py

Unbound Review · Score 5/5 (no findings) · d560a3d

  • codex (own score 5/5): The PR adds per-tool setup outcomes, run reports, backfill outcomes, and forwarding of retained hook errors. I found no defensible merge-blocking defects in the reviewed paths.
  • claude (own score 4/5): This PR makes every setup run, from the binary and from each MDM script, send a configured, skipped or deferred report for each tool. It adds a shared tool_installed check, start and end run reports, and forwarding of each hook's error.log entries to the gateway before the migration sweep runs. I checked the binary's run() ordering, the _report and _tool_reporter wiring and the bounded _as_user path. I also checked the _run_as_user

findings: 0 P0 · 0 P1 · 0 P2 (top 5 P0/P1 inline) · engines: codex ✅ · claude ✅

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

Comment thread copilot/hooks/mdm/setup.py Resolved

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

1 finding: 0 high-confidence, 1 to triage. Reviewers: Claude, Semgrep, Gitleaks.

  • [LOW] Windows race between the junction check and the rename in _replace_user_file 🟡 — augment/hooks/mdm/setup.py (_replace_user_file; the same code is copied into the other MDM scripts)
    • What: On Windows, SYSTEM checks the path for junctions before and after it opens the temp file. It then calls os.replace(tmp, path) and tmp.unlink(), which look up the path again with no check.
    • Why: A user who controls ~/.<tool>/hooks can swap a folder on the path for a junction after _refuse_if_redirected passes. SYSTEM would then create, overwrite or delete a file with a fixed name (.error_log_forwarded or ..error_log_forwarded.<pid>.tmp) in a folder the user picks. The name is fixed and the content is a timestamp in a checked format, so this is a narrow tool for gaining privilege, not an arbitrary write.
    • Fix: Keep the temp file's handle open and rename through that handle (SetFileInformationByHandle with FileRenameInfo), so no path is looked up twice. Another option is to do the state write on Windows as the user, through a process that runs with the user's token.
    • Flagged by: Claude

Pre-existing (not introduced by this PR)

  • pickle.loads of the child's output in _run_as_user: Semgrep avoid-pickle, at augment/hooks/mdm/setup.py:211,264 and the matching lines in the claude-code, codex, copilot and cursor MDM scripts. The parent runs as root and unpickles bytes from a child that runs as the user. This PR only adds a time limit to that read and does not change how the data is read. The risk depends on the user being unable to write into the child's pipe, which non-dumpable processes on Linux and macOS prevent. Consider swapping pickle for JSON when this code is next changed.
  • Semgrep insecure-file-permissions (0o700/0o755/0o775) and exec-detected (copilot/hooks/mdm/setup.py:913) are on lines this diff does not touch. They are not raised here.

⚠️ The diff was cut off at 80 KB of 341 KB. Only the start was reviewed: augment's MDM script, the start of the binary's setup_cmd.py, and some tests. The other four MDM scripts, onboard.sh, install.ps1 and the backfill changes were not reviewed.


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 2b03cdff · 2026-11-26T22:38Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

2 findings — 0 high-confidence, 2 to triage. Reviewers: claude, semgrep, gitleaks.

  • [LOW] Header injection through the device key in a user's config.json 🟡 — binary/src/unbound_hook/setup_cmd.py (_post_json and _home_device_key); the same pattern is in augment/hooks/mdm/setup.py (_post_hook_json and _home_device_key) and the other MDM copies

    • What: _home_device_key takes api_key and device_token from the user-writable ~/.unbound/config.json. It only checks that each is a non-empty str. _post_json then writes f"{name}: {value}\n" into the curl -H @file header file. A CR or LF in the key adds extra header lines to a request that the root or SYSTEM setup process sends.
    • Why: A local user can make the privileged installer send any headers they choose to /v1/hooks/errors. The user could already send that request with their own key. But if the gateway or an upstream proxy trusts internal headers (forwarding, identity or tenant hints), this hands that control to an unprivileged user. ⚠️ The real impact depends on gateway header handling, which is not in this diff.
    • Fix: Refuse any header value that contains \r, \n or other control characters before writing the header file. Also check the key against its expected shape (charset and length) in _home_device_key.
    • Flagged by: claude
  • [LOW] Best-effort redaction lets common credential formats through to the gateway and Sentry 🟡 — binary/src/unbound_hook/setup_cmd.py (_redact_hook_error, _VENDOR_KEY); the same code is in augment/hooks/mdm/setup.py and the other MDM copies

    • What: Forwarded error.log entries can be up to 2,000 characters, and traceback lines are attached to the entry. Redaction removes the home's own keys, Bearer …, name=value pairs and sk-… keys. Tokens with no label pass through, such as ghp_… / github_pat_…, AKIA…, xox[bp]-…, bare JWTs (eyJ…) and PEM private-key blocks.
    • Why: Hook errors often quote the tool input or command that failed. With this PR, device-local error text is sent off the machine on every run and grouped in Sentry. Any credential in that text is copied to a third-party store.
    • Fix: Add patterns for the common token formats (GitHub, AWS access key IDs, Slack, JWT, -----BEGIN … PRIVATE KEY-----). Better still, reuse the gateway's or the DLP engine's secret detector so the copies don't drift apart. Consider a shorter cap on traceback lines.
    • Flagged by: claude

Pre-existing (not introduced by this PR)

  • pickle deserialization of privilege-dropped child output (*/mdm/setup.py _run_as_user, semgrep avoid-pickle): the root parent unpickles bytes from a child that runs as the target user. The PR changes the read and wait loop of _run_as_user (it adds the _timeout bound) but not the pickle calls. It also sends more user-file parsing through this helper. The design is safe only while the user cannot tamper with that child. Replacing pickle with JSON for these return values would remove the risk.
  • The semgrep insecure-file-permissions (0o700/0o755/0o775) and exec-detected hits are on code this PR did not add. They concern directories and executables, which need those modes, so they are not raised here.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 93b17fd9 · 2026-11-26T23:04Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 10fd96a0 · 2026-11-26T23:18Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

3 findings — 0 high-confidence, 3 to triage. Reviewers: claude, semgrep, gitleaks.

  • [MEDIUM] Hook error.log content is forwarded with only best-effort redaction 🟡 — binary/src/unbound_hook/setup_cmd.py (_redact_hook_error / _post_hook_errors), and the same copy in each MDM script, e.g. augment/hooks/mdm/setup.py

    • What: Setup now reads each user's error.log (up to 25 entries per tool per home, up to 2,000 chars each, with traceback lines) and sends it to /v1/hooks/errors, which feeds Sentry. Before sending, it removes only the home's own keys, Bearer …, name=value pairs, a few URL params, and sk-… strings.
    • Why: Hook errors can include tool inputs, command lines, file paths, and exception text. Many common credential shapes get through the redaction: AWS AKIA… keys, GitHub ghp_/github_pat_ tokens, Slack xox… tokens, JWTs, PEM blocks, and user:pass@host URLs. Until now these logs stayed on the device. They now leave it on every run, for every user, with no opt-in.
    • Fix: Add patterns for the missing credential shapes (AKIA, gh*_, xox*, eyJ… JWTs, -----BEGIN, URL userinfo). Better still, send only the error class and the first line, not the whole traceback. Consider an org-level switch to turn forwarding on.
    • Flagged by: claude
  • [LOW] Windows forwarded-state write still uses the path after the handle check (TOCTOU) 🟡 — augment/hooks/mdm/setup.py:~1673 (_replace_user_file, and the same code in the other MDM scripts)

    • What: On Windows these steps run directly as SYSTEM. _refuse_if_redirected checks the opened handle, but tmp.unlink(), the error-path tmp.unlink(), and os.replace(tmp, path) then work on the path again. TOCTOU (time-of-check to time-of-use) means the path can change between the check and the use.
    • Why: If a user swaps a parent folder for a junction after the check, SYSTEM can create, rename, or delete .error_log_forwarded[.<pid>.tmp] inside a folder the user cannot write to. The impact is limited, because the file names are fixed and the content is a timestamp/digest string. It is still a privileged write through a user-controlled path, the same kind of issue as the earlier cursor cleanup P0.
    • Fix: Do the rename and delete through the checked handle (SetFileInformationByHandle with FileRenameInfo / FileDispositionInfo). This matches the _delete_where_asked approach used for cursor cleanup. Or do the write step in a process that runs as the user.
    • Flagged by: claude
  • [LOW] A killed user-side child can be treated as a successful exit 🟡 — augment/hooks/mdm/setup.py:~234-260 (_run_as_user timeout path; ⚠️ the PR says the claude-code and cursor copies got the same change, but those parts of the diff are truncated)

    • What: When the read deadline passes, the parent sends SIGKILL and breaks, keeping the partial output. If the child is already reaped by the first waitpid(WNOHANG), status is a signal status. os.WEXITSTATUS(status) returns 0 for a signal status, so the parent goes on to unpickle the truncated output from a process the user controls.
    • Why: The user can pause their own privilege-dropped child, which is the exact case this timeout exists for. A truncated pickle will most likely fail to load, so this is not shown to be exploitable. But the privilege boundary now relies on that failure, not on an explicit check.
    • Fix: Return None right after the timeout kill. Also require os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0 before reading data.
    • Flagged by: claude

Pre-existing (not introduced by this PR)

  • avoid-pickle (semgrep) in _run_as_user across all five MDM scripts: the root parent unpickles output from a child that runs as the user. This PR changed the function but not the pickle lines. JSON would remove this class of risk at the privilege boundary.
  • insecure-file-permissions (semgrep) at 0o700/0o755 and exec-detected at copilot/hooks/mdm/setup.py:913: these lines are not in the diff. 0o700 is already restrictive, so those hits are noise.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 8b31eab4 · 2026-11-26T23:32Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

2 findings — 1 high-confidence, 1 to triage. Reviewers: Codex, Claude, Semgrep, Gitleaks.

  • [HIGH] Windows checkpoint writes retain a SYSTEM path race 🔴 — antigravity/hooks/mdm/setup.py:977

    • What: _replace_user_file validates the opened temporary file, then performs tmp.unlink() and os.replace() by pathname; the same helper appears across MDM scripts.
    • Why: A local user can swap a parent directory for a junction after validation, redirecting privileged deletion or replacement outside their profile. The PR author's claimed Windows fix protects opens but leaves these later mutations exposed.
    • Fix: Perform Windows checkpoint writes under the user's token, or use handle-based deletion and rename with a pinned, validated destination directory.
    • Flagged by: Codex, Claude
  • [MEDIUM] Forwarded log messages can expose unredacted credentials 🟡 — antigravity/hooks/mdm/setup.py:875

    • What: Error forwarding uploads free-form messages and traceback continuations after applying a limited set of credential patterns.
    • Why: If logged exceptions contain GitHub tokens, Authorization: Basic credentials, or other unsupported formats, those values pass unchanged to /v1/hooks/errors; the supplied diff does not establish how frequently such content reaches these logs.
    • Fix: Prefer structured, allowlisted error fields; otherwise expand credential scrubbing across every implementation and apply server-side redaction before downstream reporting.
    • Flagged by: Claude

🤖 consensus review · reviewers: Codex, Claude, Semgrep, Gitleaks · head a374341c · 2026-11-30T09:21Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

Comment thread antigravity/hooks/mdm/setup.py Resolved

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

1 finding: 0 high-confidence, 1 to triage. Reviewers: Claude (own review), Semgrep, Gitleaks.

  • [MEDIUM] User's ~/.npmrc prefix makes SYSTEM reach out to a UNC path (forced NTLM authentication) 🟡 — augment/hooks/mdm/setup.py (_npmrc_cli_dir / tool_installed); the same code is copied into every MDM script (antigravity/hooks/mdm/setup.py and the others)
    • What: on Windows, tool_installed() runs as SYSTEM. It reads the prefix= line from each user's ~/.npmrc and keeps any value that os.path.isabs accepts. That includes UNC paths such as \\attacker.example\share. It then calls Path(value) / "auggie.exe" and .exists() on that path.
    • Why: any local user can write prefix=\\host\share in their own .npmrc. The SYSTEM setup run then opens an SMB connection to that host. This sends the machine account's NetNTLM hash, which the attacker can capture or relay (for example, to LDAP or AD CS). Relaying a machine account is a known route to local privilege escalation. The npm check only runs when no other footprint was found, so it fires on every device where the tool is not installed. The path globs _found checks under a user's home (such as AppData/Roaming/nvm/*) are also checked as SYSTEM, so a symlink there that points to a UNC path has the same effect.
    • Fix: reject prefix values that start with \\ or //, and anything that is not a local drive path. Better still, on Windows run the .npmrc and per-home existence checks through the same link and redirect guards as _read_user_file, or skip the .npmrc lookup when running as SYSTEM. Mirror the fix in all copies; tests/test_tool_installed.py keeps them identical.
    • Flagged by: Claude

Pre-existing (not introduced by this PR)

  • pickle.loads of child output in _run_as_user (Semgrep avoid-pickle, in every MDM script). The privileged parent unpickles bytes sent by a child that has already switched to the user's account. This PR only added a _timeout to it, and it now sends more steps that handle user-controlled data through it (error-log parsing, reading the config key). Exploiting it means taking over that child process. Consider switching the parent–child channel to JSON.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 0925caf7 · 2026-11-30T09:46Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

2 findings — 0 high-confidence, 2 to triage. Reviewers: Claude, Semgrep, Gitleaks.

Note: the diff was cut off at 80 KB of 438 KB. This review covers only the part shown: antigravity, augment, binary/README.md, and the start of binary/src/unbound_hook/setup_cmd.py.

  • [LOW] User-set key can add extra lines to curl's header file 🟡 — antigravity/hooks/mdm/setup.py (_post_hook_json / _post_hook_errors); the same code is in augment/hooks/mdm/setup.py

    • What: _home_device_key reads api_key / device_token from the user's own ~/.unbound/config.json. Root then writes it unchanged into the -H @file header file as Authorization: Bearer {api_key}\n, so a key containing \n adds headers of the user's choosing.
    • Why: a local user can add any headers to the root-run POST to /v1/hooks/errors. The request is already signed with that user's own key, so the impact is small. But a value the user controls flows into a file root writes, with no checks.
    • Fix: refuse, or strip \r/\n, in every header name and value in _post_hook_json. Also accept only keys that match the expected token shape in _home_device_key.
    • Flagged by: Claude
  • [LOW] Only known patterns are redacted before hook errors go to the gateway and Sentry 🟡 — antigravity/hooks/mdm/setup.py (_redact_hook_error, _unsent_hook_errors); the same code is in augment/hooks/mdm/setup.py

    • What: up to 25 error.log entries per tool and home, each up to 2,000 characters with traceback lines, are now sent off the device. Redaction (removing secrets) only catches the home's own keys, Bearer/Basic tokens, name=value secrets, URL query keys, and sk- / ghp_ / github_pat_ tokens.
    • Why: other secret shapes are sent in clear text if a hook error message contains them. Examples: AWS AKIA… keys, JWTs, PEM private keys, or prompt and file text echoed into a traceback. Before this PR those entries never left the device.
    • Fix: add common token shapes (AWS keys, JWTs, -----BEGIN … PRIVATE KEY-----, Slack xox[abp]- tokens). Consider sending only the first line plus the exception type rather than whole tracebacks.
    • Flagged by: Claude

Pre-existing (not introduced by this PR)

  • Root unpickles data from a child process running as the user — _run_as_user in each MDM setup.py (Semgrep avoid-pickle at antigravity:100/155, augment:211/264, claude-code:133/186, codex:127/182, copilot:136/191, cursor:103/156).
    • The pickle code itself is unchanged. This PR adds only the _timeout bound.
    • This PR now sends much more work through it: log reads, key reads, and state writes for every home.
    • The risk is limited today, because the child is no longer dumpable after setuid, so the user cannot ptrace it. ⚠️ If that ever stops holding, root would load data the user controls.
    • A plain JSON return format would remove the risk.
  • The Semgrep insecure-file-permissions hits (0o700 / 0o755 / 0o775) are directory and executable modes, not secrets. None of them is a real issue on the lines shown.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 3f9aaed0 · 2026-11-30T10:12Z

@iyadzargar

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

1 finding: 0 high-confidence, 1 to triage. Reviewers: Claude (lead), Semgrep, Gitleaks.

  • [LOW] globals() lookup with a non-constant index 🟡: claude-code/hooks/setup.py:2301
    • What: Semgrep reports that globals() is indexed with a computed name. This line is outside the part of the diff shown here, so it is not confirmed whether this PR added it or what controls the name. It sits near the backfill-outcome code this PR changes (about lines 2213–2233).
    • Why: If the name can come from a file, config or server response, an attacker could call any module-level function in a setup that runs as root. If the name comes from a fixed internal set, there is no risk.
    • Fix: Use an explicit dict of allowed names, for example {"completed": ..., "failed": ...}[name], instead of globals()[name]. Or show that the index comes only from constants.
    • Flagged by: Semgrep (dangerous-globals-use)

Pre-existing (not introduced by this PR)

  • _run_as_user unpickles the child's output as root: */mdm/setup.py (Semgrep avoid-pickle, all six MDM scripts). The child runs with the user's uid. The root parent then runs pickle.loads on whatever the child wrote to the pipe. Today the child cannot be tampered with because a process that drops from root is non-dumpable (other processes cannot inspect or attach to it). This PR now runs this path on every setup for each home (key read, log read, place save), which makes it a more frequent target. Consider JSON for the return channel, because every new caller returns plain data (strings, lists, dicts, bools).
  • The insecure-file-permissions hits (0o700, 0o755, 0o775, $BITS) are on directory and executable-hook modes. They do not come from this diff's changes and are not real issues. 0o700 is stricter than the rule's suggested 0o644.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head d560a3db · 2026-11-30T10:20Z

@iyadzargar
iyadzargar merged commit d7f4fa4 into staging Nov 30, 2026
5 checks passed
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.

3 participants