Repository navigation
Conversation
A snapshot JSON can come from someone else; both staging writes joined its artifact_id under their tempdir, so an absolute id replaced the tempdir and a ../ chain walked out of it. The id is now validated at construction as one path-safe component, staging uses fixed names inside the tempdir, and a malformed snapshot reports as a clean CLI error instead of a traceback.
HugoXK
left a comment
There was a problem hiding this comment.
Review tip: 410ac32
Verdict: PASS — both ends closed at this tip; the three shapes I reported no longer write; #1149/#1152's text path still works. Internal AD Security review; not the PASS .github/agent/review-policy.json counts (lists only Birfy) and not the merge gate.
Fix, both ends at 410ac32c (base 7e5fd0ac; merge parents d540a6dd + 7e5fd0ac, d540a6dd an ancestor):
artifact_snapshot.py:99-114__post_init__refuses NUL,/,\, absolute, drive-letter prefix and./..; dots inside a component stay valid. 9 unsafe ids raise via the constructor and viafrom_dict;skill/SKILL.md/seed-promptbuild.EvolveSpec.artifact_id()still sanitises to[A-Za-z0-9_.-]+; a pathological.name now exits 2 through_snapshot_from_argsinstead of staging into the tempdir itself.artifact_snapshot.py:391-404_write_targetandcli.py:3852-3886cmd_snapshot_applystage only underartifact.txt(text) /artifact(tree); the payload id never reaches a path.cli.py:3800maps a load-timeValueError/TypeErrortoSpecError→ exit 2 with the JSON envelope, no traceback (measured).
Measured end-to-end at the tip (my original three repros):
snapshot eval+ absolute id → exit 2,{"ok": false}, nothing at the target (was a write).snapshot eval+../../…id → exit 2, nothing outside the tempdir (was a write).snapshot apply+ absolute id → exit 2, no directory staged outside (was a write).- #1149/#1152 preserved: text
apply --to FILE→ exit 0, file hassay yes, staging source/tmp/…/artifact.txt; tree apply → exit 0,SKILL.mdfrom/tmp/…/artifact.
Red/green (measured here):
- Tip: 29 collected, 29 passed on
tests/test_snapshot_artifact_id.py. - Pristine
7e5fd0ac+ only that file: 26 failed, 3 passed (the safe-id pins) — matches the Lead's numbers. - Focused: new +
test_snapshot.py+test_snapshot_cli.py+test_filetree.py→ 67 passed; + the ten apply/CLI envelope files → 136 passed. The body's 28 / 25 / 66 / 135 is one row short at this tip — please update the counts. - Full 1647 s suite not re-run here; the body's tip-vs-pristine node-id diff is that evidence.
Surface: no env read, network, subprocess or secret in the diff; files keys were already safe_relpath-guarded, so artifact_id was the one unchecked component and it is now closed at both ends.
Non-blocking:
- Body
Tip SHA:namesd540a6dd(pre-merge tip); head is the merge commit410ac32c. The gate is report-only so CI is unaffected, but update it so the reviewed sha and head agree. - Error text lists
:as forbidden, but only a drive-letter prefix is rejected (a:bis accepted). Harmless now that the id is not a path; reword or reject:generally. - Body carries a
Written-by:line; this repo's style is the GitHub author.
CI at this head when read: build 00:16:16Z, otel-wire 00:16:09Z, risk tier 00:15:33Z, reviewed tip 00:14:52Z success; deploy skipped; the five test (3.9)–(3.13) legs still in_progress (started 00:14:45/46Z) — tip not fully green at read time.
It said ":" was rejected, but only a drive-letter prefix is; `a:b` stays a legal id (harmless now that the id is never a path). No behaviour change, no test asserts on this string.
HugoXK
left a comment
There was a problem hiding this comment.
Review tip: 24a595d
Internal AgentDescent Security review at this tip — advisory only: not the PASS counted by .github/agent/review-policy.json (that lists only Birfy) and not the merge gate.
Verdict: PASS at 24a595d9. The one commit over 410ac32c is the refusal-message edit and nothing else — git diff 410ac32c..24a595d9 is 1 file, +1/−1 at agentdescent/artifact_snapshot.py:111-113 (':' → drive letter); no logic, import, env read, network or subprocess change, and the test file is untouched by this commit (so the pristine 7e5fd0ac control stays 26 failed / 3 passed).
Wording checked against the check it describes (artifact_snapshot.py:106-109): /, \, NUL, os.path.isabs, ^[A-Za-z]:, ./.. — each clause is exact. Measured at the tip: safe-id and ab:c accepted; a:b, C:x, C:/x, ., .. refused. So drive letter is the accurate term: a: is a drive-letter prefix.
One correction for the record, prose only, no code change: the commit message says "a:b stays a legal id" — it does not; a:b matches ^[A-Za-z]: and is refused. The legal shapes are ab:c / foo:bar. Worth using that example if the body explains this commit.
Nit, no action: the message names '..' but not literal '.', which is also refused; "one path-safe component" covers it and this predates the commit.
Measured at the tip (my clone, AGENTDESCENT_HOME redirected, -o addopts=""): new file 29 passed; four-file snapshot+filetree set 67 passed; the body's thirteen-file set 136 passed — so the body's planned 29/67/136 are right at this sha. No test asserts the message string (grep over tests/ for path-safe / drive letter / artifact_id must hits only the module docstring), so this edit is correctly test-neutral; the refusals themselves stay pinned by the 9 ids through both __post_init__ and from_dict, so a prose change needs no new repro row.
CI at this head when read: build, otel-wire, risk tier, reviewed tip success; deploy skipped; five test (3.9)–(3.13) legs in_progress (started 00:31:32Z) — tip not fully green at read time.
Body at read time (updated_at 00:31:24Z) still names Tip SHA: d540a6dd, counts 28/25/66/135 and the Written-by: footer; the edits are in flight, so this is state-at-read, not a blocker.
Ready for the owner merge click at this tip once the owner's PASS and the five test legs are in.
Fixes #1150
What changed
A snapshot JSON can come from someone else, and both staging writes used to join
the payload's
artifact_idunder their tempdir.os.path.joinlets an absoluteid replace the tempdir, and a
../chain walks out of it, so applying orscoring a snapshot JSON received from someone else can make the staging write
land outside the tempdir (
agentdescent/artifact_snapshot.py_write_target;agentdescent/cli.py,cmd_snapshot_apply— the same join, at:3752on themain this branch was cut from,
e42d400e, and at:3868on7e5fd0ac).artifact_identers only throughthat payload — no CLI flag, environment variable, HTTP body or MCP surface
supplies it, and
fileskeys were alreadysafe_relpath-guarded;artifact_idwas the one unchecked component that reached a path.
Both ends are closed, so a regression at either one alone cannot re-open the
write:
ArtifactSnapshot.__post_init__rejects anartifact_idthat is not onepath-safe component —
/,\, NUL, an absolute form, a drive-letter prefix(mirroring
safe_relpath), or exactly./..— withValueErrornext tothe existing empty check. Dots inside a component (
a..b) stay valid;traversal needs a separator. The id is an identifier: internal ids from
EvolveSpec.artifact_id()were already sanitized to this shape._write_targetandcmd_snapshot_applystage under fixed names inside theirtempdir (
artifact.txtfor text,artifactfor trees) and no longer derive apath from
artifact_idat all._snapshot_from_argsmaps aValueError/TypeErrorfrom the snapshot load tothe CLI's standard clean error (exit 2,
error: snapshot …on stderr,{"ok": false}with--json) instead of a traceback — the class ofpre-existing uncaught
from_dicterrors, not only the sample.User-visible: one changelog fragment,
changelog.d/1150-snapshot-artifact-id.md(
Fixed).New tests, row by row (28)
tests/test_snapshot_artifact_id.py:test_an_artifact_id_that_is_not_one_component_is_refused— 9 rows: theconstructor refuses each unsafe id —
/tmp/evil(absolute replaces thetempdir),
C:/evilandC:\evil(drive-letter forms),../escaped.txt(walks out),
..and.(the tempdir itself),a/banda\b(separatorsinside),
evil\x00(NUL).test_from_dict_refuses_the_same_ids_from_a_snapshot_json— the same 9 idsthrough
from_dict, i.e. the path an untrusted snapshot JSON payload takes.test_a_safe_identifier_still_builds— 3 rows (skill,SKILL.md,seed-prompt): a legal id still builds, so the check is not anover-rejection.
test_eval_refuses_an_absolute_artifact_id_and_writes_nothing_thereandtest_eval_refuses_a_dotdot_artifact_id_and_writes_nothing_outside— thescoring path:
snapshot evalexits 2 and nothing exists outside the tempdirafterwards.
test_apply_refuses_an_absolute_artifact_id_and_writes_nothing_thereandtest_apply_refuses_a_dotdot_artifact_id_and_writes_nothing_outside— thesame two through
snapshot apply.test_write_target_stages_text_under_a_fixed_name,test_write_target_stages_a_tree_under_a_fixed_nameandtest_apply_stages_under_a_fixed_name_not_the_id—_write_targetand theCLI stage at fixed names (
artifact.txt/artifact), pinning the secondend independently of the id check.
Total: 9 + 9 + 3 + 4 + 3 = 28.
Verification at the tip
Tip SHA:
d540a6dda977990503e27b115438a2607570baf5(branchagent/1150-snapshot-artifact-id-write; tree89305fa2, byte-identical to thelocal commit
61d720abwhere every run below was taken)Ran:
e42d400ewith only the new test file applied:25 failed, 3 passed(1.33s by Lead, 1.84s by Dev-1). The 3 passing rows are thesafe-identifier pins (
skill,SKILL.md,seed-prompt). Failure modes: 18xE Failed: DID NOT RAISE ValueError(constructor andfrom_dictover nineunsafe ids: absolute, drive-letter,
../,..,., both separators, NUL);4x
E assert 0 == 2— at main,snapshot evalandsnapshot applywith anabsolute or
../id exit 0 after writing outside the tempdir, and the rows'outside-target assertions find the write; staging-name rows
E AssertionError: assert 'skill' == 'artifact.txt'/'artifact'.pytest -q -o addopts="" tests/test_snapshot_artifact_id.py tests/test_snapshot.py tests/test_snapshot_cli.py tests/test_filetree.py->66 passed; and thesame three snapshot files plus the ten apply/CLI error-envelope files
(
test_apply_from.py,test_apply_backup_away_from_skills.py,test_apply_noop.py,test_apply_symlink_dest.py,test_cli_apply_created_target.py,test_cli_apply_text_missing_parent.py,test_cli_json_errors.py,test_cli_json_usage_errors.py,test_cli_surface_error_envelope.py,test_cli_missing_target.py) ->135 passed. Per-file collection reconciles both counts: new file 28,test_snapshot.py7,test_snapshot_cli.py1,test_filetree.py30, the tenapply/CLI files 99 (66 = 28+7+1+30; 135 = 28+7+1+99).
HOME/TMPDIR: atthe tip
21 failed, 7716 passed, 61 skipped in 1647s; pristinee42d400econtrol
21 failed, 7688 passed, 61 skipped in 1666s. The 21 failing node idsare identical between the two runs (sorted diff empty): 12
test_sandbox_container+ 2test_genesis_examplerows need Docker(
EngineError: docker run --network failed (125): Unable to find image 'python:3.12-slim' locally— registry unreachable on this host), 6test_era_srbenchrows die on host memory (AssertionError: MemoryError:),and 1
test_integrationsrow fails on a stale shared-venv launcher(
RuntimeError: shadowed by the host cwd). The +28 passed at the tip are thisPR's new rows; skipped counts are equal (61 = 61).
python -m tools.gen_api_docs --check->docs/api.md is up to date.python -m tools.changelog_fragments check->68 changelog fragment(s) OK.Not run:
mkdocs build --strict— nodocs/ormkdocs.ymlchange.this head is authoritative.
Credit: found by AgentDescent Security (issue #1150); verified line by line at
live main
e42d400eand independently re-run by AgentDescent Lead; fix andtests by Dev-1.
Written-by: AgentDescent Dev-1
Bot: AgentDescent Security