Files
OmniRoute/tests
Diego Rodrigues de Sa e Souza fb6e381b96 fix(mitm): gate sudo prompts on server platform, not browser UA
The MITM control surface decided whether to prompt for a sudo password by
reading `navigator.userAgent` in the dashboard tool card and by checking
`process.platform === "win32"` in the API route. Two real cases broke:

1. Windows browser hitting a Linux/macOS server: the card skipped the modal
   (UA said Windows), POST/DELETE rejected the request with `Missing
   sudoPassword` (server said Linux). The MITM never started.
2. Linux server running as root, under NOPASSWD sudoers, or in a minimal
   container without `sudo` on PATH: the card forced an unnecessary password
   modal even though `sudo` would never have prompted.

Fix:
- `src/mitm/dns/dnsConfig.ts` gains `isSudoAvailable()`,
  `canRunSudoWithoutPassword()`, and `isSudoPasswordRequired()`. The probe
  uses `execFileSync("sudo", ["-n", "true"], { stdio: "ignore" })` — fixed
  args, no shell expansion, per Hard Rule #13.
- `GET /api/cli-tools/antigravity-mitm` now reports `isWin` and
  `needsSudoPassword` so the UI can decide based on the server's platform.
- POST/DELETE drop the unconditional non-Windows password requirement and
  only return 400 when sudo is genuinely needed (`!isWin && !pwd &&
  !isRoot() && isSudoPasswordRequired()`). The cached-password write also
  guards against caching an empty string.
- `AntigravityToolCard.tsx` replaces the `navigator.userAgent` check with
  `status?.isWin === true`, `status?.hasCachedPassword === true`, and
  `status?.needsSudoPassword === false`.

TDD: `tests/unit/mitm-sudo-gate-822.test.ts` pins the helper contract on
the native platform (5 cases). Helpers short-circuit on Windows / root /
no-sudo before invoking `sudo`, so the tests never exercise real sudo.

Co-authored-by: Rezky Hamid <hiepau1231@gmail.com>
Inspired-by: https://github.com/decolua/9router/pull/822
2026-06-21 14:16:30 -03:00
..
2026-06-17 19:26:32 -03:00
2026-05-23 01:46:59 -03:00
2026-06-20 07:09:43 -03:00
2026-06-19 06:49:01 -03:00
2026-06-10 13:49:08 -03:00
2026-06-13 17:27:40 -03:00