- `run` can now be scoped to an operator-configured set of allowed working directories via a new `GHANTIKA_CWD_ROOTS` environment variable (a `path.delimiter`-separated list, unset by default, matching the pre-existing behavior of allowing any accessible directory). Unset, or the raw value itself being empty, is the only shape meaning no restriction; any other raw value is a configuration attempt and denies every cwd unless it resolves to at least one effective root - including a value that splits and filters down to zero entries, which denies every cwd rather than being silently read back as unrestricted. A candidate `cwd` is compared against each configured root by its real, symlink-resolved target - never a literal string prefix - so a directory named only through a symlink (either the candidate itself, or the configured root) is judged by where it actually points, and a sibling directory whose name merely starts with a root's name is correctly rejected rather than matched. A root that cannot itself be resolved is silently dropped from the effective set rather than crashing the check or being treated as a wildcard. Disclosed time-of-check-to-time-of-use residual, and the gap is not narrow on either path: the real path is validated once, at the moment of the call, before `run()`'s own concurrency admission. A free slot removes only the queue-duration extension of that gap, not the gap itself - env construction, executable resolution (an unbounded walk of a caller-suppliable PATH), policy resolution, and job-record creation all still sit between validation and spawn even when a slot is immediately free. A job that queues instead of spawning immediately holds that same resolved string, unrevalidated, for its entire time in the queue - arbitrarily long, bounded only by the jobs ahead of it - and the OS itself re-resolves the pathname independently at the moment it actually spawns regardless of which path a job took, so a symlink swap or directory replacement any time before that moment is not something this closes on either path; proven by a real queued-job reproduction that swaps a validated directory for an escaping symlink while a job sits queued. Two things this change explicitly does not claim: it never inspects or filters what a spawned child chooses to write to its own stdout, and it adds no isolation between a job's environment and this server's own internal state or a genuinely external same-uid OS process inspection of the real spawned child - both remain exactly as visible to an operator as before, proven here by dedicated negative-control tests (including a real `ps`-based external inspection of a live child's own environment) rather than left as an unverified sentence in a doc comment.
0 commit comments