Menu ▾ ▴

#524 Security: confine non-literal fs paths in cli/** (72 detect-non-literal-fs-filename warnings)

open
nobody
6 days ago
6 days ago
Anonymous
No

Originally created by: Redo-San

Baseline (2026-10-06): npm run lint → 112 security/detect-non-literal-fs-filename warnings, 72 of them inside cli/**:

Count File
15 cli/commands/certificate.js
13 cli/commands/audio_watermark.js
11 cli/utils.js
11 cli/menu.js
5 cli/commands/did.js
4 cli/commands/watermark.js
4 cli/commands/c2pa.js
4 cli/commands/pixel_injection.js
3 cli/commands/timestamp.js (plus the remaining CLI hits)

(Other 40: 28 in scripts/**, 12 elsewhere — out of scope for this issue.)

Each hit is an fs sink whose path is not a literal, i.e. it can be influenced by CLI arguments or a previous read. Without a guard a caller can pass ../../… and write outside the intended output directory.

Change

  1. Add one shared guard in cli/utils.js (e.g. resolveInside(baseDir, userPath) → path.resolve + path.relative traversal check) and call it before every non-literal fs sink in cli/**.
  2. Where the value is provably a constant (module-level template, fixed resource path), add a targeted // eslint-disable-next-line security/detect-non-literal-fs-filename with a one-line justification instead of a guard.

Acceptance criteria

  • [ ] npx eslint --config .tools/Developer_Toolkit/eslint.config.mjs cli/ -f json → security/detect-non-literal-fs-filename = 0 (or every residual has an inline justification).
  • [ ] A new unit test proves a path escaping the output/CWD directory is rejected with a clear error.
  • [ ] npm run test:cli and npm run test:quick pass.
  • [ ] npm run lint total warnings ≤ 5,555 (5,627 − 72).

Discussion


Log in to post a comment.