test(#4652): failing-first coverage for the four unconfined boundaries
Phase 2 of epic #4636, absorbing #4327 and #4354. Tests only; no fix. These MUST fail. Four CLI boundaries join externally-supplied input to a managed root with no containment validation. Each was driven through the real CLI and confirmed unconfined before the assertions were written: todo complete <name> src/commands.cts cmdTodoComplete check predicate --phase-dir <dir> check-command-router cmdCheckPredicate check decision-coverage-plan <dir> check-command-router resolvePath check gap-analysis.plan-post <dir> check-command-router Boundary 1 is worse than the issue describes. #4327 reports that a traversal name "resolves outside the todos root", which reads as an information leak. Measured, it is destructive: `todo complete ../../../../b1out/leak.md` exited 0, MOVED the outside file into completed/, and unlinked the original. The file was gone. cmdTodoComplete ends in fs.unlinkSync(sourcePath), so an unconfined name does not merely read across the boundary, it consumes across it. Boundary 2 reproduces #4354 exactly: a BLOCKING gate returned {"block":false,"details":{"match":true}} sourced entirely from a SECURITY.md in a directory the caller chose, outside the project. Boundaries 3 and 4 are not named in the epic. Both accepted an outside phase dir and exited 0. Rows that exist because they are the ones nobody enumerates: - ORDERING. A real file is created outside the todos root, then the traversal name targeting it is asserted rejected AND the outside file asserted still present and unmoved. #4327 notes the existence check and the move target BOTH follow the unvalidated join, so a rejection that lands after the read has already leaked — and, per the finding above, after the unlink has already destroyed. - `a/../../b.md` — looks balanced, resolves outside. - --dry-run must reject too; a preview must not leak a resolved outside path. - ${PHASE_DIR} interpolation into a command-exit-zero predicate is the SECOND predicate kind, which a fix inside gate-predicate-evaluator.cts would miss. - An absolute path INSIDE the project must still be accepted at every boundary — absolute is not a synonym for escaping. Cross-boundary rows loop over one shared list of escaping inputs and assert all four reject with the same shape, so four sites adopting one predicate cannot drift into four rejection contracts. Property tests cover BOTH directions — outside is always rejected, inside is always accepted. A property asserting only rejection is satisfied by a predicate that rejects everything, which is the degenerate-implementation trap found in Phase 1's review. Both are seeded. Regressions fold into the owning module suites rather than a new tests/fix-NNNN-*.test.cjs, per scripts/lint-regression-test-names.cjs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,11 +13,15 @@
|
||||
* (a 100ms timeout killing `sleep 1`), so there is no orphan/leak risk.
|
||||
*/
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const { evaluatePredicate } = require('../gsd-core/bin/lib/gate-predicate-evaluator.cjs');
|
||||
const { buildPredicateDeps, parsePredicateFlags } = require('../gsd-core/bin/lib/check-command-router.cjs');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
// ─── buildPredicateDeps: real subprocess exit mapping ─────────────────────────
|
||||
|
||||
@@ -153,3 +157,122 @@ describe('partitionPredicateArgs (#4130 follow-up)', () => {
|
||||
assert.deepEqual(positionals, ['p1', 'p2', 'p3']);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #4354: `check predicate --phase-dir` containment boundary ───────────────
|
||||
//
|
||||
// cmdCheckPredicate passes the `--phase-dir` flag VERBATIM into PredicateContext
|
||||
// (src/check-command-router.cts) with no containment validation. Both predicate
|
||||
// kinds read/interpolate that value: `artifact-frontmatter-equals` resolves it
|
||||
// as `targetDir` for `findPhaseArtifact`, and `command-exit-zero` interpolates
|
||||
// it into `${PHASE_DIR}` in the shelled-out command. These tests reproduce the
|
||||
// issue's exact repro and prove the boundary is currently unconfined.
|
||||
|
||||
describe('check predicate --phase-dir — containment boundary (#4354)', () => {
|
||||
let projDir;
|
||||
let outsideDir;
|
||||
|
||||
beforeEach(() => {
|
||||
projDir = createTempProject();
|
||||
fs.mkdirSync(path.join(projDir, '.planning', 'phases', '05-x'), { recursive: true });
|
||||
outsideDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-predicate-outside-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(projDir);
|
||||
cleanup(outsideDir);
|
||||
});
|
||||
|
||||
test('[RED #4354] the issue\'s exact repro: artifact-frontmatter-equals against a foreign SECURITY.md via an outside --phase-dir must be rejected, not evaluated', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(outsideDir, 'SECURITY.md'),
|
||||
'---\nstatus: passed\n---\n# Security\n',
|
||||
);
|
||||
|
||||
const predicate = JSON.stringify({
|
||||
kind: 'artifact-frontmatter-equals',
|
||||
artifact: 'SECURITY.md',
|
||||
field: 'status',
|
||||
equals: 'passed',
|
||||
});
|
||||
|
||||
const result = runGsdTools(
|
||||
['--json-errors', 'check', 'predicate', '--predicate', predicate, '--phase-dir', outsideDir, '--raw'],
|
||||
projDir,
|
||||
);
|
||||
|
||||
// CURRENT BUG (documented, not asserted as desired): this command today
|
||||
// succeeds and prints {"block":false,...} — a BLOCKING gate passing on
|
||||
// foreign evidence read from OUTSIDE the project. REQUIRED behavior:
|
||||
// the outside --phase-dir must be rejected before evaluation.
|
||||
assert.strictEqual(
|
||||
result.success,
|
||||
false,
|
||||
`an outside --phase-dir must be rejected before evaluating the predicate ` +
|
||||
`(currently: ${result.success ? `SUCCEEDED with output ${result.output}` : 'failed for an unrelated reason'})`,
|
||||
);
|
||||
});
|
||||
|
||||
test('[RED #4354] a command-exit-zero predicate interpolating ${PHASE_DIR} with an outside --phase-dir must also be rejected', () => {
|
||||
fs.writeFileSync(path.join(outsideDir, 'marker.txt'), 'outside-marker\n');
|
||||
|
||||
const predicate = JSON.stringify({
|
||||
kind: 'command-exit-zero',
|
||||
command: 'test -f "${PHASE_DIR}/marker.txt"',
|
||||
});
|
||||
|
||||
const result = runGsdTools(
|
||||
['--json-errors', 'check', 'predicate', '--predicate', predicate, '--phase-dir', outsideDir, '--raw'],
|
||||
projDir,
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
result.success,
|
||||
false,
|
||||
`a command-exit-zero predicate interpolating an outside --phase-dir must be rejected ` +
|
||||
`(currently: ${result.success ? `SUCCEEDED with output ${result.output}` : 'failed for an unrelated reason'})`,
|
||||
);
|
||||
});
|
||||
|
||||
test('[regression] a valid in-project --phase-dir still evaluates', () => {
|
||||
const phaseDir = path.join(projDir, '.planning', 'phases', '05-x');
|
||||
fs.writeFileSync(
|
||||
path.join(phaseDir, 'SECURITY.md'),
|
||||
'---\nstatus: passed\n---\n# Security\n',
|
||||
);
|
||||
const predicate = JSON.stringify({
|
||||
kind: 'artifact-frontmatter-equals',
|
||||
artifact: 'SECURITY.md',
|
||||
field: 'status',
|
||||
equals: 'passed',
|
||||
});
|
||||
|
||||
const result = runGsdTools(
|
||||
['check', 'predicate', '--predicate', predicate, '--phase-dir', phaseDir, '--raw'],
|
||||
projDir,
|
||||
);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.block, false, 'in-project phase-dir evaluation must still pass');
|
||||
});
|
||||
|
||||
test('[regression] no --phase-dir at all still falls back to cwd and evaluates', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(projDir, 'SECURITY.md'),
|
||||
'---\nstatus: passed\n---\n# Security\n',
|
||||
);
|
||||
const predicate = JSON.stringify({
|
||||
kind: 'artifact-frontmatter-equals',
|
||||
artifact: 'SECURITY.md',
|
||||
field: 'status',
|
||||
equals: 'passed',
|
||||
});
|
||||
|
||||
const result = runGsdTools(
|
||||
['check', 'predicate', '--predicate', predicate, '--raw'],
|
||||
projDir,
|
||||
);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.block, false, 'cwd-fallback evaluation must still pass');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user