fix(codex): stop 502ing empty CLI output, GET /file no longer mkdirs or leaks paths

This commit is contained in:
2026-09-08 20:15:12 +07:00
parent 29ed86d672
commit aca8fd02ee
6 changed files with 82 additions and 14 deletions
+7 -3
View File
@@ -153,15 +153,19 @@ function rmTreeSync(p) {
*
* `trustedRoot` is created first (mkdirSync recursive — safe, it is never
* attacker-controlled) so the walk is guaranteed to bottom out at or below
* it, never wander past it into whatever happens to contain it.
* it, never wander past it into whatever happens to contain it. Pass
* `{create: false}` for a read-only caller (codex-discovery.js's
* readFileSafe): a GET must have no filesystem side effect, so it skips the
* mkdir and instead lets a missing `trustedRoot` surface as the native
* `ENOENT` from `realpathSync` — the caller treats that as "not found".
*
* ponytail: this check and the write/delete that follows are not atomic —
* a symlink swapped in between them could still redirect one write. Closing
* that needs O_NOFOLLOW-style fd work with real platform variance; out of
* scope for this task (see task-5 fix round 2).
*/
function assertNotSymlinkEscape(trustedRoot, target) {
fs.mkdirSync(trustedRoot, { recursive: true });
function assertNotSymlinkEscape(trustedRoot, target, opts = {}) {
if (opts.create !== false) fs.mkdirSync(trustedRoot, { recursive: true });
const realRoot = fs.realpathSync(trustedRoot);
let dir = target;