Skip to content

Confine --seal-out to the checkout and create it fresh before sealed code runs (#1182) - #1185

Merged
brettheap merged 11 commits into
mainfrom
fix/1182-confine-seal-out
Sep 27, 2026
Merged

brettheap merged 11 commits into
mainfrom
fix/1182-confine-seal-out

Conversation

@brettheap

@brettheap brettheap commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openxfactory-5 (openXfactory-5)

What was open

The refresh lane's --seal-out was unconfined (#1182). #1166 (landed 8fb505ab) bound --seal-result-out and the seal's recipe/, but left --seal-out as it was: Copilot thread PRRT_kwDOTAvnrs6mX2tk on #1166 was scoped out, and SonarCloud kept reporting pythonsecurity:S8707 findings reached through it. Measured at 133e37d9:

  • a seal was made beside the checkout, out of it by .., or through a link on the way;
  • an empty directory the lane found was adopted, and mkdir(parents=True) made missing directories on the way;
  • a link at the seal's own name was looked through (a target holding files was refused as "not empty"), and a dangling one escaped as a bare FileExistsError;
  • a seal directory swapped after the lane made it had the corpus and the validator extracted through the swap, and the probe (sealed code) ran from the other directory.

SonarCloud's analysis of main shows eight open S8707 findings on scripts/ideation_dashboard/dashboard_refresh_lane.py whose taint source is args.seal_out (seal_dir=Path(args.seal_out), line 4211 at 133e37d9), not only the two #1182 names: _open_directory (1405-1406, AaDiiKjiuh_NfUB9MPP8), _create_new_file (1452, AaDiiKjiuh_NfUB9MPP7), _write_new_recipe (1519, AaDiiKjiuh_NfUB9MPP9), file_sha256 (1310, AaCIil7G1WTeVOIYRVvd), _extract_seal_archive (1780, 1791, 1793: AaCIil7G1WTeVOIYRVvj, AaCIil7G1WTeVOIYRVvW, AaCIil7G1WTeVOIYRVvi) and seal_source (2907, AaCIil7G1WTeVOIYRVvk). Each flow was read from the SonarCloud issue API. This change removes that source, so all eight are in scope.

What this changes

  • --seal-out is held before the seal starts (_seal_out_path, in main). Its canonical path (os.path.realpath) must be inside --repo-root (startswith(root + os.sep), the rule's own sanitizer form). It must be its own spelling made absolute, so there is no link at any component, the last included, dangling or not, even one leading back inside. Nothing may exist at the path, and its directory must exist (no mkdir on the way). Anything else is refused as a recorded outcome: nothing of the seal runs, sealed code least of all, the result is written, and the step exits 0. The exit-3 fail-closed path from Render the refresh lane through the pinned products, and mount them in the nightly (#1161) #1166 (a result the lane could not write) is unchanged.
  • --seal-out and --seal-result-out are two paths (_seal_paths_overlap, in main; Copilot, this PR). They are compared before the result's path is cleared. They overlap if they are the same path, or one is inside the other, in any of three spellings: absolute, with the directories above the last component resolved, or resolved whole. On an overlap neither path is touched: nothing is cleared, sealed or written, and the step fails (SEAL_RESULT_UNWRITTEN_EXIT). A --seal-out refused on its own keeps its own reason. --seal-out . overlaps every result path inside the checkout, so it fails the step too.
  • The lane makes the seal directory itself, and holds it (_new_seal_directory, in seal_source). An existing path is refused before the validator is resolved. Then comes a plain mkdir, relative to a handle reached by walking from --repo-root, with each directory opened relative to the one before and without following a link. The new directory is opened the same way and must be empty. Once it is made, its way is walked again by name, through no link, and must reach it (Copilot, this PR). A confined seal is refused before anything is made where the platform opens nothing relative to a handle, or names no path through one (no /proc/self/fd), since it would then be written through its name (Copilot, this PR). A direct call that confines nothing keeps the path fallback the manifest's write always had.
  • Every write and read the lane makes under the seal goes through that handle (_HeldSealDirectory.root: /proc/self/fd/<fd>). This covers the legs, the corpus, the validator copy, the index and the manifest's byte count. The sealed code the lane runs, the validator's probe and the pre-dispatch render, is handed that directory too, never the name (Copilot, this PR). Before the corpus, the recipe and the manifest, the name is held to the directory by walking its way from the root through no link, by identity (leads_here). After the manifest is written, the name is held once more. A seal whose name no longer leads there is refused, and its manifest is withdrawn through the handle (Copilot, this PR).
  • Callers. scripts/dashboard-refresh-nightly.py passes argv through unchanged. .github/workflows/doc-health-reusable.yml runs the seal step from the checkout root with --repo-root . --seal-out dfr-seal --seal-result-out dfr-seal-result.json. That is one relative name inside the checkout, which no earlier finalize step makes or names, apart from its result, so it satisfies every rule unchanged. test_the_workflows_own_relative_spelling_seals holds it to that. The upload step reads the same name, gated on sealed == 'true'. The aggregation's worker intake is untouched.
  • The CLI tests name their seal inside the checkout, as the workflow does. test_a_non_empty_seal_directory_is_refused became test_a_seal_directory_that_already_exists_is_refused: an empty directory and a file are refused too, before the validator is resolved. test_a_seal_directory_that_is_a_link_is_refused now covers three targets.
  • SonarCloud's three new code smells at 81807067 are fixed. _new_seal_directory is split into its parts (S3776), and three pytest.raises blocks now make one call each (S5778).

Code-only under add-nightly-dashboard-refresh (ratified); no OpenSpec change. Seal schema unchanged (2.2.0).

Evidence

Failing-first at 133e37d9

The 22 new cases were run against 133e37d9's lane module (commit 1a9d1a27 adds only the tests). All 22 fail there and pass at the head.

Rule Test (case) At 133e37d9
outside the checkout is refused test_a_seal_out_the_lane_may_not_make_is_refused_before_anything_is_sealed[beside-the-checkout] assert True is False (sealed beside the checkout)
…[climbing-out-of-it] assert True is False
…[through-a-link-out-of-it] assert True is False (sealed where the link points)
a link at its own name is never followed test_a_seal_directory_that_is_a_link_is_refused[an-empty-directory] assert 'the seal dir...ctory at all)' == 'the seal dir...hrough a link' (refused late, after the validator was resolved)
…[a-directory-holding-files] '…is not empty — a seal must be materialized into a fresh tree' (it looked through the link)
…[nothing] FileExistsError: [Errno 17] File exists: '<tmp>/seal' (escaped seal_source)
CLI …[a-link-at-its-own-name] reason the seal directory …/aggregation/dfr-seal is not a directory of its own (a link, or not a directory at all), after the seal had started
CLI …[a-dangling-link-at-its-own-name] reason FileExistsError: [Errno 17] File exists: '…/aggregation/dfr-seal'
a pre-existing path is never adopted test_a_seal_directory_that_already_exists_is_refused[an-empty-directory] Failed: DID NOT RAISE SealRefused (adopted)
…[a-directory-holding-files] '…is not empty — a seal must be materialized into a fresh tree'
…[a-file] NotADirectoryError: [Errno 20] Not a directory: '<tmp>/seal'
CLI …[an-existing-directory-inside-it] assert True is False (adopted and sealed)
CLI …[the-checkout-itself] reason the seal directory …/aggregation is not empty — …
test_a_seal_directory_that_appears_before_the_lane_makes_it_is_refused Failed: DID NOT RAISE SealRefused
a link on the way is never followed CLI …[through-a-link-inside-it] assert True is False (sealed where the link points)
test_a_link_put_on_the_seal_out_path_after_its_check_is_never_made_through assert ['dfr-seal'] == [] (made through the link, outside)
no directory is made on the way CLI …[in-a-directory-that-does-not-exist] assert True is False
a swap redirects nothing test_a_seal_directory_swapped_after_the_lane_made_it_gets_nothing_more assert ['openxFactory', 'validator'] == [] (extracted through the swap)
test_a_seal_directory_swapped_while_the_lane_writes_it_keeps_the_writes assert ['openxFactory', 'validator'] == []
test_a_seal_directory_swapped_as_the_lane_makes_it_is_refused[a-link-out] Failed: DID NOT RAISE SealRefused
…[a-directory-holding-files] Failed: DID NOT RAISE SealRefused
the caller satisfies the rule test_the_workflows_own_relative_spelling_seals AttributeError: … has no attribute '_seal_out_path'

Failing-first for each Copilot round (each at the head the review was made at)

Round Thread Test (cases) At that head
1, review 5331245942 at 81807067 PRRT_kwDOTAvnrs6mcgSB: a directory on the way swapped as the seal is made test_a_directory_on_the_way_swapped_as_the_seal_is_made_gets_nothing[a-fresh-directory] assert ['openxFactory'] == []: the legs were written into the seal made inside the moved directory, out of the root
…[a-link-to-the-moved-one] Failed: DID NOT RAISE SealRefused: the whole seal completed out of the root
test_a_directory_on_the_way_swapped_for_a_link_gets_nothing_more[as-the-legs-are-sealed], [as-the-render-runs] DID NOT RAISE, twice: the name check (an lstat) looked through the link
PRRT_kwDOTAvnrs6mcgSK: the render was run from the name test_the_render_is_handed_the_directory_the_lane_made_not_its_name[a-copy-in-its-place], [a-directory-of-its-own] assert [(181, 3376635)] == [(181, 3376574)]: the render resolved to the replacement
2, review 5331401098 at 725f92e0 PRRT_kwDOTAvnrs6mc4kc: the no-handle fallback test_a_confined_seal_is_never_made_by_its_path_alone DID NOT RAISE
PRRT_kwDOTAvnrs6mc4kl: the result cleared before the fresh check test_a_seal_out_that_overlaps_the_seal_result_is_never_touched, six cases then an earlier seal removed as a stale result (NotADirectoryError … dfr-seal.json/kept.txt); seal_source run on a free path; a stale result replaced; the directory at the result's path removed, twice; the directory a link led to removed
3, review 5331459386 at c3829b64 PRRT_kwDOTAvnrs6mdCHa: no path through a handle test_a_confined_seal_is_never_written_by_its_path DID NOT RAISE
4, review 5331632101 at 5aa2193f PRRT_kwDOTAvnrs6mdeRY: no check of the name after the manifest test_a_seal_directory_swapped_as_its_manifest_is_written_is_not_published[a-link-to-the-moved-seal], [a-copy-in-its-place] DID NOT RAISE, twice
the review's summary: "overlap refusal can write into an existing seal" overlap [one-free-path], [a-free-result-inside-an-existing-seal], [the-checkout-itself] the refusal was created at the result's path: inside an existing seal, and inside the checkout

Each round's tests were committed before its fix (20f9fa35, 08247617, 26ae3b5f, 58d93294), and each round's new cases fail against the module of the head before it.

Mutation checks (each guard reverted by hand at cf081af9, one at a time): 25 of 25 killed

# Guard reverted Fails
M1 _seal_out_path: canonical path inside --repo-root 3: test_a_seal_out_the_lane_may_not_make_is_refused_before_anything_is_sealed (beside-the-checkout, climbing-out-of-it, through-a-link-out-of-it)
M2 _seal_out_path: canonical path is its own spelling (no link) 3: test_a_seal_out_the_lane_may_not_make_is_refused_before_anything_is_sealed (a-dangling-link-at-its-own-name, a-link-at-its-own-name, through-a-link-inside-it)
M3 _seal_out_path: nothing exists at the path 6: test_a_seal_out_that_overlaps_the_seal_result_is_never_touched (a-free-result-inside-an-existing-seal, one-path-holding-a-seal, the-checkout-itself, the-result-inside-the-seal, the-seal-inside-the-result); test_a_seal_out_the_lane_may_not_make_is_refused_before_anything_is_sealed (an-existing-directory-inside-it)
M4 _seal_out_path: its directory exists 1: test_a_seal_out_the_lane_may_not_make_is_refused_before_anything_is_sealed (in-a-directory-that-does-not-exist)
M5 main: --seal-out held by _seal_out_path at all 8: test_a_seal_out_the_lane_may_not_make_is_refused_before_anything_is_sealed (a-dangling-link-at-its-own-name, a-link-at-its-own-name, an-existing-directory-inside-it, beside-the-checkout, climbing-out-of-it, in-a-directory-that-does-not-exist, through-a-link-inside-it, through-a-link-out-of-it)
M6 seal_source: existing path refused before the validator 6: test_a_seal_directory_that_already_exists_is_refused (a-directory-holding-files, a-file, an-empty-directory); test_a_seal_directory_that_is_a_link_is_refused (a-directory-holding-files, an-empty-directory, nothing)
M7 _made_and_opened: exclusive mkdir (no adoption) 1: test_a_seal_directory_that_appears_before_the_lane_makes_it_is_refused
M8 _seal_directory_way: walk from --repo-root through no link 1: test_a_link_put_on_the_seal_out_path_after_its_check_is_never_made_through
M9 _made_and_opened: new directory opened without following a link 1: test_a_seal_directory_swapped_as_the_lane_makes_it_is_refused (a-link-out)
M10 _new_seal_directory: new directory must be empty 1: test_a_seal_directory_swapped_as_the_lane_makes_it_is_refused (a-directory-holding-files)
M11 writes and reads go through the held handle (/proc/self/fd) 1: test_a_seal_directory_swapped_while_the_lane_writes_it_keeps_the_writes
M12 seal_source: name held to the directory before the corpus 1: test_a_seal_directory_swapped_after_the_lane_made_it_gets_nothing_more
M13 recipe and manifest writes: name held to the directory 5: test_a_seal_directory_swapped_while_the_lane_writes_it_keeps_the_writes; test_a_seal_directory_the_render_replaced_gets_no_manifest (a-copy-in-its-place, a-link-to-the-moved-seal); test_the_recipe_is_never_written_through_anything_sealed_code_left (the-seal-directory-replaced, the-seal-directory-replaced-by-a-copy)
M14 _new_seal_directory: its way walked again once made (Copilot r1) 2: test_a_directory_on_the_way_swapped_as_the_seal_is_made_gets_nothing (a-fresh-directory, a-link-to-the-moved-one)
M15 leads_here: the name held along its way, not by lstat (Copilot r1) 3: test_a_directory_on_the_way_swapped_as_the_seal_is_made_gets_nothing (a-link-to-the-moved-one); test_a_directory_on_the_way_swapped_for_a_link_gets_nothing_more (as-the-legs-are-sealed, as-the-render-runs)
M16 _reached_by_name: each name opened without following a link 3: test_a_directory_on_the_way_swapped_as_the_seal_is_made_gets_nothing (a-link-to-the-moved-one); test_a_directory_on_the_way_swapped_for_a_link_gets_nothing_more (as-the-legs-are-sealed, as-the-render-runs)
M17 seal_source: the render handed the held directory (Copilot r1) 2: test_the_render_is_handed_the_directory_the_lane_made_not_its_name (a-copy-in-its-place, a-directory-of-its-own)
M18 main: the overlap of --seal-out and --seal-result-out found (Copilot r2) 8: test_a_seal_out_that_overlaps_the_seal_result_is_never_touched (a-free-result-inside-an-existing-seal, a-free-seal-inside-the-result, a-link-to-the-result, one-free-path, one-path-holding-a-seal, the-checkout-itself, the-result-inside-the-seal, the-seal-inside-the-result)
M19 main: the result's path not cleared on an overlap 5: test_a_seal_out_that_overlaps_the_seal_result_is_never_touched (a-free-seal-inside-the-result, a-link-to-the-result, one-path-holding-a-seal, the-result-inside-the-seal, the-seal-inside-the-result)
M20 main: an overlap gets no result written (Copilot r4) 8: test_a_seal_out_that_overlaps_the_seal_result_is_never_touched (a-free-result-inside-an-existing-seal, a-free-seal-inside-the-result, a-link-to-the-result, one-free-path, one-path-holding-a-seal, the-checkout-itself, the-result-inside-the-seal, the-seal-inside-the-result)
M21 _new_seal_directory: no confined seal without a handle (Copilot r2) 1: test_a_confined_seal_is_never_made_by_its_path_alone
M22 _spellings: the paths compared as resolved too 1: test_a_seal_out_that_overlaps_the_seal_result_is_never_touched (a-link-to-the-result)
M23 _new_seal_directory: a confined seal needs a path through a handle (Copilot r3) 1: test_a_confined_seal_is_never_written_by_its_path
M24 seal_source: the name held once more after the manifest (Copilot r4) 2: test_a_seal_directory_swapped_as_its_manifest_is_written_is_not_published (a-copy-in-its-place, a-link-to-the-moved-seal)
M25 seal_source: the manifest withdrawn from a seal not published 2: test_a_seal_directory_swapped_as_its_manifest_is_written_is_not_published (a-copy-in-its-place, a-link-to-the-moved-seal)

Real seal run (the lane's own CLI, the workflow's spelling)

A scratch driver adapted from seat z's read-only kit (z526-kit/measure-real-seal.py) calls main() from a fresh root, exactly as the seal step does: --repo-root . --phase seal --seal-out dfr-seal --seal-result-out dfr-seal-result.json --decision-in dfr-decision.json. It uses the real leg sealer, resolver, corpus archive, validator copy and probe, pre-dispatch render and sealed validator under --strict. As in the kit, the only stub is the recipe read.

Run Result Seal tree left on disk
head cf081af9 (its corpus carries #1184's repair) SEALED …, 4133 files, 50950876 bytes, exit 0; precheck validated under --strict over 400 documents; verify_seal(...) == []; no substitution tree digest 4a30ea63af4898f1…
head, --seal-out ../outside-seal NOT SEALED — the seal cannot be made: --seal-out '../outside-seal' is not inside the checkout …, exit 0, nothing created none
head, --seal-out dfr-seal-result.json beside that result NOT SEALED — … overlap, and neither is touched …, ::error:: the result could not be written, exit 3; the root holds only dfr-decision.json none
earlier: 81807067 and 133e37d9, each sealing corpus revision 133e37d9 the same strict_failed verdict on #1159's three findings, exit 0 4133 files, 46a08c1e6c208963… for both: the same paths and the same bytes
earlier: 133e37d9, --seal-out ../outside-seal sealed code ran; strict_failed 4133 files materialized outside the checkout

Counts

  • tests/ideation-dashboard/test_dashboard_source_seal.py + test_dashboard_refresh_lane.py: 388 passed at cf081af9 (352 at 133e37d9).
  • Full suite: local, at cf081af9 (-m "not postgres"): 8759 passed, 7 skipped, 391 subtests passed, 1 failed. The failure is tests/doc-health/test_tag_hygiene_pinned_targets.py::test_a_lexically_malformed_value_builds_no_path_and_reads_nothing, which asserts that no argument on its read surface contains the substring one. This clone's path, …/clone-sealout/…, contains it, so the test fails here only. The same file passes 41 of 41 from a scratch worktree of cf081af9 whose path does not contain it.
  • CI pytest-suite: at cf081af9, run 36343750922: selected=9181 passed=9175 skipped=6 failures=0 errors=0 (floors: selected>=7050, passed>=7044, skipped==6). At c3829b64: selected=9175 passed=9169 skipped=6. At 81807067: selected=9162 passed=9156 skipped=6.

Gates at cf081af9 (all exit 0)

  • scripts/validate-openspec-cli-pin.py --all: 0 UNDISPOSITIONED failures (1 accepted exception, named in its output).
  • scripts/validate-code-surface.py: passed.
  • scripts/validate-estate-inventory.py: passed.
  • scripts/doc-health.py --single-repo .: "Findings: 31 critical, 26 error, 49 warning, 21 info. New regressions vs previous report: 0."
  • pyflakes on both files: only redefinition of unused 'build', which main carries at line 4305.

SonarCloud

At cf081af9 (analysis, 2026-09-27T19:21:08Z) the quality gate is OK. There are 0 new vulnerabilities, 0 security hotspots, 0 bugs and 0 code smells. The three code smells it reported at 81807067 are CLOSED/FIXED.

No S8707 is reported in this PR's scope, open or closed. Of the eight on main reached through --seal-out:

  • two are in functions this PR rewrote: _write_new_recipe (AaDiiKjiuh_NfUB9MPP9) and seal_source (AaCIil7G1WTeVOIYRVvk). A flow that still reached them would be reported here as new, and none is;
  • six are in functions it leaves unchanged: _open_directory (AaDiiKjiuh_NfUB9MPP8), _create_new_file (AaDiiKjiuh_NfUB9MPP7), file_sha256 (AaCIil7G1WTeVOIYRVvd), and _extract_seal_archive three times (AaCIil7G1WTeVOIYRVvj, AaCIil7G1WTeVOIYRVvW, AaCIil7G1WTeVOIYRVvi). SonarCloud tracks these against main and does not re-report them on a pull request. Their flows now start at _seal_out_path's realpath + startswith(root + os.sep) + raise, and they close in the first analysis of main after the landing.

Copilot

Five reviews: 5331245942 (81807067, 2 threads), 5331401098 (725f92e0, 2), 5331459386 (c3829b64, 3), 5331632101 (5aa2193f, 1, plus its summary line), and 5331679024 (cf081af9: "Findings: None"). All 8 threads were answered, Lane line first, and resolved; 0 are unresolved. Six were fixed test-first. Two are answered as residuals, below.

Residuals (answered, not changed)

  • An empty directory swapped in between the lane's mkdir and its open (PRRT_kwDOTAvnrs6mdCHH). No call makes a directory and returns a handle on it, so the lane uses mkdirat and openat(O_NOFOLLOW) as two adjacent calls relative to a held parent. They run before any sealed code has run. A process able to act then could rewrite the lane itself, which runs from the checkout. An empty replacement brings nothing into the seal.
  • The checkout root replaced before the walk (PRRT_kwDOTAvnrs6mdCHP). A replaced checkout would also be the corpus the seal archives and the lane's own code. After the making, every check of the name requires the directory the lane holds, by identity.
  • A swap after the lane exits and before the upload reads the name. No check the lane makes can reach that window. It predates this PR.

Out of scope (open S8707 on this module not reached through --seal-out)

These flows start at other arguments, so they are left as they are (lines at 133e37d9): main() 4170 --decision-in (AaCIil7G1WTeVOIYRVvZ), main() 4293 --digest-in (AaCIil7G1WTeVOIYRVvf), main() 4330-4337 --decision-out (AaCIil7G1WTeVOIYRVvb), run_refresh_lane() 4001/4004/4006-4010 --pin-out (AaCIil7G1WTeVOIYRVvY, …Vva, …VvV), and append_report_section() 3788/3791 --report-in (AaCIil7G1WTeVOIYRVvc, …Vvg, and S2083 AaCIil7G1WTeVOIYRVvU).

Held for

DRAFT. It lands by the coordinator under Brett Heap's word to lane openXfactory-5, verbatim "land #1159 and #1182 when green", once the checks are green, Copilot is clean at the head, SonarCloud shows the S8707 findings reached through --seal-out gone, and 0 threads are unresolved. #1159 landed as #1184 (a9e7db75).

Refs #1182
Refs #1161

🤖 Generated with Claude Code

brettheap and others added 2 commits September 27, 2026 16:19
The refresh lane's --seal-out path was unconfined (#1182). These tests
state the rules it is now held to, and every one of them fails against
the lane module at 133e37d, which this commit leaves untouched:

- `--seal-out` resolves inside `--repo-root`, through no link at any
  component, names nothing that exists yet, in a directory that does,
  and a path that breaks any of that is refused before the seal starts,
  as a recorded outcome (exit 0), with nothing of the seal run;
- the seal directory is made by the lane itself, exclusively: an existing
  directory, empty or not, a file, or a link, dangling or not, is refused
  before the validator is resolved, and one that appears in between, or
  is swapped as it is made, is refused too;
- the lane walks from `--repo-root` to make it, so a directory on the way
  swapped for a link after the check is never made through;
- every later write under it goes through the handle the lane holds, so a
  swap of its path redirects nothing, and a swapped seal gets nothing more.

The CLI tests now name their seal inside the checkout, as the workflow's
own `--seal-out dfr-seal` does, and the workflow's spelling is held to the
rule. The fix follows in the next commit.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The refresh lane's --seal-out was unconfined (#1182, Copilot thread
PRRT_kwDOTAvnrs6mX2tk on #1166). At 133e37d a seal was made beside the
checkout, out of it by `..` or through a link, in an empty directory the
lane found, and in a directory `mkdir(parents=True)` made on the way; a
dangling link escaped as a bare FileExistsError; and a seal directory
swapped after the lane made it had the corpus and the validator
extracted through the swap, with the probe run from the other directory.

- `main` holds `--seal-out` before the seal starts (`_seal_out_path`):
  its canonical path must be inside `--repo-root`, must be its own
  spelling (no link at any component, the last included, dangling or
  not), must not exist, and must be in a directory that does. A path
  that breaks any of that is a recorded refusal: nothing of the seal
  runs, the result is written, and the step exits 0 as before.
- `seal_source` refuses an existing path before the validator is
  resolved, then makes the directory itself (`_new_seal_directory`): a
  plain `mkdir` relative to a handle, reached by walking from
  `--repo-root` without following a link, then opened without following
  one and required empty. It holds that handle until the seal is done.
- Every write and read the lane makes under the seal goes through the
  handle (`/proc/self/fd/<fd>` on Linux, the checked path elsewhere); the
  recipe and the manifest are written through it, once the name is held
  to still lead to it; and the name is held again before the corpus is
  extracted. A swapped seal gets nothing more written and is refused.

The eight SonarCloud pythonsecurity:S8707 findings on this module whose
taint source is args.seal_out (_open_directory, _create_new_file,
_write_new_recipe, file_sha256, _extract_seal_archive x3, seal_source)
now only see the checked path, or the handle's own path.

Tests: the 22 new cases of the previous commit fail against 133e37d's
module and pass here; both modules 371 passed (352 at 133e37d).

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 27, 2026 16:55
@sourcery-ai

sourcery-ai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR hardens --seal-out as a lane-owned, fresh directory confined to the checkout: it validates the destination up front, creates and holds it without following links, routes subsequent seal I/O through its identity-bound handle, and refuses races or name substitution while preserving the workflow contract and seal schema.

Sequence diagram for confined seal creation and materialization

sequenceDiagram
    participant Main
    participant SealPath as _seal_out_path
    participant SealSource as seal_source
    participant NewDir as _new_seal_directory
    participant Held as _HeldSealDirectory
    participant SealedCode
    participant Manifest as _write_new_manifest

    Main->>SealPath: _seal_out_path(args.seal_out, repo_root)
    SealPath-->>Main: Path inside checkout
    Main->>SealSource: seal_source(seal_dir, seal_within=repo_root)
    SealSource->>NewDir: _new_seal_directory(seal_dir, within=repo_root)
    NewDir->>NewDir: Walk from repo_root without links
    NewDir->>NewDir: mkdir(path.name, dir_fd=parent)
    NewDir->>NewDir: Open and verify fresh directory
    NewDir-->>SealSource: _HeldSealDirectory
    SealSource->>Held: refuse_if_replaced(corpus)
    SealSource->>Held: Write legs and extract corpus via root
    SealSource->>SealedCode: precheck_render(held.path)
    SealedCode-->>SealSource: Render and validator result
    SealSource->>Held: refuse_if_replaced(recipe)
    SealSource->>Held: _write_new_recipe(held, recipe)
    SealSource->>Held: refuse_if_replaced(manifest)
    SealSource->>Manifest: _write_new_manifest(held, text)
    Manifest-->>SealSource: Manifest created
    SealSource->>Held: close()
Loading

Flow diagram for --seal-out validation and refusal

flowchart TD
    A[main receives --seal-out] --> B[_seal_out_path]
    B --> C{Canonical path inside repo-root?}
    C -- No --> R[Record refusal; do not run seal]
    C -- Yes --> D{Absolute spelling equals canonical path?}
    D -- No --> R
    D -- Yes --> E{Path does not exist and parent exists?}
    E -- No --> R
    E -- Yes --> F[seal_source]
    F --> G{Path still absent?}
    G -- No --> R
    G -- Yes --> H[_new_seal_directory]
    H --> I{Walk and mkdir without links succeeds?}
    I -- No --> R
    I -- Yes --> J{New directory is still the held, empty directory?}
    J -- No --> R
    J -- Yes --> K[Write seal data through held.root]
    K --> L{Seal name still resolves to held identity?}
    L -- No --> R
    L -- Yes --> M[Run sealed code and write recipe/manifest]
    M --> N[Seal result recorded]
Loading

File-Level Changes

Change Details Files
Constrain and preflight the seal output path before any sealing work begins.
  • Canonicalize --seal-out and require it to be inside --repo-root without traversing symlinks.
  • Reject existing paths, missing parent directories, checkout-root targets, and other invalid destinations.
  • Record refusal outcomes without invoking seal_source or sealed code.
scripts/ideation_dashboard/dashboard_refresh_lane.py
tests/ideation-dashboard/test_dashboard_source_seal.py
Create the seal directory exclusively and maintain an identity-bound handle throughout materialization.
  • Walk from the checkout using directory handles and no-follow semantics, then create and reopen the destination with exclusive mkdir.
  • Reject races, symlink substitutions, non-empty replacements, and directories that appear during creation.
  • Use the held directory handle or /proc/self/fd root for seal reads and writes, while checking that the upload name still points to the created directory.
scripts/ideation_dashboard/dashboard_refresh_lane.py
tests/ideation-dashboard/test_dashboard_source_seal.py
Route seal construction and finalization through the held directory while preserving workflow and artifact behavior.
  • Guard corpus extraction, recipe creation, validator materialization, indexing, byte counting, and manifest writing against directory swaps.
  • Close the held directory reliably and keep sealed-code rendering addressed by the named seal path.
  • Pass --repo-root as the containment root from the CLI and update tests to use the workflow's in-checkout spelling.
scripts/ideation_dashboard/dashboard_refresh_lane.py
tests/ideation-dashboard/test_dashboard_source_seal.py
Expand regression coverage for path confinement, freshness, race handling, and caller compatibility.
  • Add unit and CLI cases for outside paths, symlinks, dangling links, pre-existing destinations, missing parents, and checkout-root targets.
  • Exercise swaps during creation, extraction, and writes to verify no data is redirected or adopted.
  • Verify refusal happens before validator resolution and that the workflow's relative dfr-seal path remains valid.
tests/ideation-dashboard/test_dashboard_source_seal.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical race and execution-path issues, plus incomplete symlink-component validation, remain unresolved.

Review effort: Lite
Findings: 2 High severity

Open (2)
What changed in this PR

Hardens --seal-out against path traversal, symlink redirection, and directory swaps during seal creation.

Changes:

  • Confines destinations to the checkout and requires fresh directories.
  • Uses held directory handles for seal reads and writes.
  • Adds coverage for unsafe paths, links, replacements, and races.
File Description
scripts/​ideation_dashboard/​dashboard_refresh_lane.py Implements confined, handle-backed seal creation and writing.
tests/​ideation-dashboard/​test_dashboard_source_seal.py Tests confinement, links, freshness, and replacement scenarios.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

brettheap and others added 3 commits September 27, 2026 17:35
Copilot's review of #1185 at 8180706 (review 5331245942) found two
gaps, and these tests state the rules that close them. All six new cases
fail against the lane module at 8180706, which this commit leaves
untouched:

- a directory on the seal's way that is moved out of the root, and
  replaced, as the seal is made gets nothing written into the seal made
  inside it, and the seal is refused (thread PRRT_kwDOTAvnrs6mcgSB): at
  8180706 the legs were written there, out of the root, and with a link
  put in its place the whole seal was completed out of the root;
- a directory on the way swapped for a link after the seal is made, as
  the legs are sealed or as the render runs, refuses the seal: at
  8180706 each check of the name looked through the link;
- the render is handed the directory the lane made, not its name
  (thread PRRT_kwDOTAvnrs6mcgSK): at 8180706 a name moved aside and
  replaced once the recipe was written had the render run from the
  replacement.

The stand-in render that replaces the seal now moves it by its name,
since the render is no longer handed the name. SonarCloud's two new
S5778 findings on this module (lines 3682 and 4232 at 8180706), and a
third block of the same shape, now make one call inside each
pytest.raises block.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot's review of #1185 at 8180706 (review 5331245942):

- The walk from the root held each directory on the way by a handle only
  while it went through it, so one moved out of the root after it was
  opened, and replaced, had the seal made inside the moved one, and the
  legs written there before any check of the name
  (PRRT_kwDOTAvnrs6mcgSB). Once the seal is made, its way is now walked
  again from the root, by name and through no link, and must reach the
  directory just made, or the seal is refused before anything is written
  into it.
- Every later check of the name walks the same way
  (`_HeldSealDirectory.leads_here`), so a directory on the way swapped
  for a link no longer satisfies it, as it did when the check was an
  lstat of the name, which looks through every link but the last.
- The pre-dispatch render is handed the directory the lane holds, as the
  validator's probe already was, never the name, which the probe's
  sealed code could have pointed anywhere (PRRT_kwDOTAvnrs6mcgSK). A
  child cannot use this process's handle, so it is handed where that
  directory is when it starts, read through the handle, and the name is
  held to the directory again before the manifest.

`_new_seal_directory` is split into its parts (`_seal_directory_way`,
`_walked_down`, `_made_and_opened`, `_new_seal_directory_by_path`),
which also answers SonarCloud's new S3776 cognitive-complexity finding
on it.

Tests: the six new cases of the previous commit fail against 8180706's
module and pass here.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #1175 and #1184 (a9e7db7). #1184 repairs the three dangling
cl-plane-1 cluster refs (#1159), so the real seal of this branch runs
over the corpus the nightly will seal next. Neither touches a file of
this change.

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical issues remain around overlapping output paths and the unsafe pathname fallback.

Review effort: Lite
Findings: 2 High severity

Open (2)
Resolved since last review (2)

brettheap and others added 2 commits September 27, 2026 18:00
Copilot's review of #1185 at 725f92e (review 5331401098) found two more
gaps, and these tests state the rules that close them. All seven new
cases fail against the lane module at 725f92e, which this commit leaves
untouched:

- a `--seal-out` that overlaps `--seal-result-out` (the same path, one
  inside the other, or a link to it) is never touched, and nothing is
  sealed (thread PRRT_kwDOTAvnrs6mc4kl). At 725f92e the result's path
  was cleared first, so an existing seal, or what it held, was removed
  as a stale result, a directory on a free seal's way was removed with
  it, the directory a linked seal led to was removed, and a free path
  was sealed into;
- where the platform opens nothing relative to a handle, a seal
  confined to a root is refused before anything is made (thread
  PRRT_kwDOTAvnrs6mc4kc). At 725f92e it was made, written and checked
  by its path alone. A direct call that confines nothing still seals by
  the path.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot's review of #1185 at 725f92e (review 5331401098):

- `main` clears the seal result's path before the seal runs, since
  whatever sits there is the lane's to remove (#1166). A `--seal-out`
  that named the same path, held it, or lay inside it lost an existing
  seal, or what it held, and then passed as fresh
  (PRRT_kwDOTAvnrs6mc4kl). The two paths are now compared first, as
  spelled and as resolved (`_seal_paths_overlap`). On an overlap nothing
  is cleared and nothing is sealed. The refusal is written only where
  the result's path is free, and the step fails where it is not. A
  `--seal-out` refused on its own keeps its own reason.
- Where the platform opens nothing relative to a handle, a seal
  confined to a root is refused before anything is made
  (PRRT_kwDOTAvnrs6mc4kc), since it could only be made, written and
  checked by its path. `main` always confines it to `--repo-root`, and
  the nightly's parent runs on Linux, where the handle is taken. A
  direct call that confines nothing is still made by its path, as the
  manifest's write always has been there.

Tests: the seven new cases of the previous commit fail against
725f92e's module and pass here.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 18:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brettheap and others added 2 commits September 27, 2026 18:57
Copilot's review of #1185 at c3829b6 (review 5331459386, thread
PRRT_kwDOTAvnrs6mdCHa): directory handles alone do not route the seal's
writes. Where the platform opens a directory relative to a handle but
names no path through one (no /proc/self/fd), the seal's root fell back
to its name, and the corpus, the validator, the index and the byte count
followed that name, which sealed code may swap.

`test_a_confined_seal_is_never_written_by_its_path` points the handles'
path at nothing and seals with `seal_within`, as `main` does. It fails
against the lane module at c3829b6, which this commit leaves untouched
(`Failed: DID NOT RAISE SealRefused`). A direct call that confines
nothing still seals through its name.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot's review of #1185 at c3829b6 (review 5331459386, thread
PRRT_kwDOTAvnrs6mdCHa). With `within`, `_new_seal_directory` now requires
a path through a handle on the directory the seal goes in
(`_path_through_handle`) before it makes anything, and refuses the seal
where there is none. The seal would otherwise be written, indexed and
counted through its name. `main` always confines the seal to
`--repo-root`, and the nightly's seal step runs on ubuntu-latest, which
has /proc/self/fd. A direct call that confines nothing still falls back
to the name, as the manifest's write always has where no handle serves.

Tests: the new case of the previous commit fails against c3829b6's
module and passes here.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The manifest write lacks a final replacement check, and overlap refusal can write into an existing seal.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (3)

brettheap and others added 2 commits September 27, 2026 19:11
…, first

Copilot's review of #1185 at 5aa2193 (review 5331632101) found two more
gaps, and these tests state the rules that close them. The five cases
below fail against the lane module at 5aa2193, which this commit leaves
untouched:

- a seal whose name is swapped as its manifest is written is not
  published, and its manifest is withdrawn from the directory the lane
  made (thread PRRT_kwDOTAvnrs6mdeRY). At 5aa2193 nothing looked at the
  name after the manifest was written (`Failed: DID NOT RAISE
  SealRefused`, for a link and for a copy);
- on an overlap of `--seal-out` and `--seal-result-out` the result is
  written nowhere, and the step fails (the review's summary: "overlap
  refusal can write into an existing seal"). At 5aa2193 the refusal was
  created at a free result path, even one inside an existing seal
  directory, and so inside the checkout when `--seal-out` named the
  checkout itself. That case moves from the recorded-refusal test to the
  overlap test, since the checkout overlaps every result path inside it.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot's review of #1185 at 5aa2193 (review 5331632101):

- The manifest is the seal's publication marker, and once the seal is
  recorded sealed the workflow uploads whatever its name leads to. The
  name is now held to the directory once more after the manifest is
  written. A seal whose name no longer leads there is refused, and its
  manifest is withdrawn through the handle (`_withdraw_manifest`), so
  the directory the lane made never carries a manifest the lane does not
  stand behind (thread PRRT_kwDOTAvnrs6mdeRY).
- On an overlap of `--seal-out` and `--seal-result-out`, neither path is
  touched. The result is no longer created even where its path is free,
  since that path could lie inside an existing seal (the review's
  summary). The held directory is let go (`_HeldResultPath.release`),
  and the step fails (`SEAL_RESULT_UNWRITTEN_EXIT`). `write` is back to
  its one form.

Tests: the five cases of the previous commit that fail against
5aa2193's module pass here.

Refs #1182
Refs #1161

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The security-sensitive filesystem changes warrant final human review.

Review effort: Lite
Findings: None

Resolved since last review (1)

@sonarqubecloud

Copy link
Copy Markdown

@brettheap
brettheap marked this pull request as ready for review September 27, 2026 19:55

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-5 (openXfactory-5)

LANDING — lane openXfactory-5, session b254fdd5-0bdf-44e0-bb45-5a780234009f@Eagle, 2026-09-27T19:57:06Z, PR #1185 into opensoft/openxFactory main

@brettheap
brettheap merged commit d90df42 into main Sep 27, 2026
16 checks passed
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-5 (openXfactory-5)

LANDED — lane openXfactory-5, session b254fdd5-0bdf-44e0-bb45-5a780234009f@Eagle, 2026-09-27T19:57:22Z, PR #1185 into opensoft/openxFactory main → merge d90df42; Confine --seal-out to the checkout and create it fresh before sealed code runs (#1182)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants