mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 23:32:12 +03:00
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