Commit 0310cc2
WEB-4656: address review findings — MDM creds, secret leak, matcher allowlist
Three CRITICAL fixes from elite-pr-reviewer plus two WARNINGs.
CRITICAL #1: MDM install now writes ~/.unbound/config.json per user.
The hook scripts read this file at runtime via _common.py::load_credentials.
Without it, every PreToolUse silently fail-opens and org policy is never
enforced on managed devices. New _write_unbound_config_payload mirrors
claude-code/hooks/mdm/setup.py's pattern: privilege-dropped fork, tmp +
rename, O_NOFOLLOW + 0o600, dir 0o700. Called BEFORE the settings.json
merge so a settings failure never strands a device with an entry-point
hook pointing at missing creds.
CRITICAL #2: API keys no longer leak via curl argv. Both
notify_setup_complete (user + MDM) and fetch_api_key_from_mdm now use
stdlib urllib.request so the Authorization / X-API-KEY header stays inside
our process. Previously ps auxe / /proc/<pid>/cmdline exposed the secret
to every other user on the device. The hook-script POST in
scripts/_common.py is left as-is per review notes — it runs under the
user's own UID so the leak is bounded by user permissions, not cross-user.
CRITICAL #3: PreToolUse / PostToolUse matchers switched from the
"Bash|bash|Write|Edit|Read|Glob|Grep|Task" allowlist to the catch-all "*".
Antigravity 2.0 ships at minimum with WebFetch, WebSearch, MultiEdit,
NotebookEdit, TodoWrite (none of which were in the allowlist) — every
unfamiliar tool was silently bypassing the policy gate. Server-side
filtering via the gateway's APP_NATIVE_FILE_TOOLS / tools_to_check is the
correct defang point, not the matcher.
WARNING fixes:
- mdm/setup.py settings.json read now uses O_NOFOLLOW, consistent with
the script-write loop above it.
- scripts/_common.py drops the -L flag from the hook-POST curl. Gateway is
one hop; following redirects masks misconfig instead of surfacing it.
Tests:
- antigravity/hooks/test_setup.py: matcher tests rewritten to assert
catch-all "*" (per-event), regression assert no "|" allowlist, plus a
new TestNotifySetupCompleteNoCurl class that puts a fake curl shim on
PATH and asserts it's never invoked.
- antigravity/hooks/mdm/test_setup.py: new file. Covers the credentials
write (api_key present, 0o600 mode, 0o700 dir mode, preserves unrelated
fields), the full install payload (config + scripts + settings all
land), the ordering invariant (config written before settings), the
catch-all matcher shape, and curl-shim assertions for both
notify_setup_complete and fetch_api_key_from_mdm.
Skipped per brief:
- WARNING #4 (gateway URL string replace): speculative, "don't design for
hypothetical futures."
- WARNING #5 (--foo=bar form): matches claude-code convention.
- WARNING #8 (operator log on hook failures): out of scope for v1.
- INFO #9-12: cosmetic / matches claude-code / out of scope.
Decisions made:
- Catch-all matcher uses "*", not "" or omitted, to match claude-code's
established settings.json convention (verified in tree). Both forms work
per Antigravity docs; "*" is what every other tool's setup ships.
- fetch_api_key_from_mdm was also migrated to urllib though the brief only
explicitly named notify_setup_complete — same exact leak (bearer token
on curl argv), same fix, same blast-radius file.
- MDM --clear path does NOT remove ~/.unbound/config.json (matches the
claude-code MDM clear behaviour; config is shared across tools so we
don't own removal).
Test commands run (all green):
cd antigravity/hooks && python3 -m unittest test_setup.py -v # 13 ok
cd antigravity/hooks/scripts && python3 -m unittest test_hooks.py -v # 14 ok
cd claude-code/hooks && python3 -m unittest test_setup.py -v # 7 ok
cd antigravity/hooks/mdm && python3 -m unittest test_setup.py -v # 10 ok
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8542e68 commit 0310cc2
5 files changed
Lines changed: 584 additions & 54 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
48 | 55 | | |
49 | | - | |
50 | | - | |
| 56 | + | |
| 57 | + | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
| |||
281 | 288 | | |
282 | 289 | | |
283 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
284 | 295 | | |
285 | 296 | | |
286 | 297 | | |
287 | 298 | | |
288 | 299 | | |
289 | 300 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
294 | 305 | | |
295 | | - | |
296 | | - | |
297 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
298 | 321 | | |
299 | | - | |
300 | | - | |
301 | | - | |
| 322 | + | |
| 323 | + | |
302 | 324 | | |
303 | 325 | | |
304 | 326 | | |
| |||
307 | 329 | | |
308 | 330 | | |
309 | 331 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | 332 | | |
314 | 333 | | |
315 | 334 | | |
| |||
407 | 426 | | |
408 | 427 | | |
409 | 428 | | |
410 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
411 | 497 | | |
412 | 498 | | |
413 | | - | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
414 | 504 | | |
415 | 505 | | |
416 | 506 | | |
| |||
419 | 509 | | |
420 | 510 | | |
421 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
422 | 518 | | |
423 | 519 | | |
424 | 520 | | |
| |||
444 | 540 | | |
445 | 541 | | |
446 | 542 | | |
447 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
448 | 550 | | |
449 | 551 | | |
450 | 552 | | |
| |||
616 | 718 | | |
617 | 719 | | |
618 | 720 | | |
| 721 | + | |
| 722 | + | |
619 | 723 | | |
620 | 724 | | |
621 | | - | |
| 725 | + | |
622 | 726 | | |
623 | 727 | | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
632 | 737 | | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
633 | 743 | | |
634 | 744 | | |
635 | 745 | | |
| |||
659 | 769 | | |
660 | 770 | | |
661 | 771 | | |
662 | | - | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
663 | 776 | | |
664 | 777 | | |
665 | 778 | | |
| |||
0 commit comments