M14 finalization: SEC-4, SEC-5, SEC-6, version.sh fix#172
Merged
wkusnierczyk merged 2 commits intomainfrom Feb 24, 2026
Merged
Conversation
- [SEC-4] Reject path traversal in plugin.json path overrides (P011) - [SEC-5] Enforce 1 MiB size limit in all plugin validators - [SEC-6] Re-check file type before write-back in fixer and formatter - Fix non-portable \n in sed replacement in version.sh Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR finalizes M14 security items by hardening plugin validation and reducing file-write race windows, plus makes scripts/version.sh portable across BSD/GNU toolchains.
Changes:
- Add SEC-4 traversal detection for
plugin.jsonpath overrides via new P011 diagnostic. - Add SEC-5 bounded reads (1 MiB cap) by switching plugin validators to
read_file_checked. - Add SEC-6
is_regular_file()re-checks before write-back in the fixer and formatter; makeversion.shchangelog stub insertion portable.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/plugin/manifest.rs | Adds contains_path_traversal() + P011 and switches to bounded file reads for plugin.json. |
| src/plugin/hooks.rs | Switches hooks.json reading to read_file_checked (1 MiB cap). |
| src/plugin/agent.rs | Switches agent file reading to read_file_checked (1 MiB cap). |
| src/plugin/command.rs | Switches command file reading to read_file_checked (1 MiB cap). |
| src/plugin/cross.rs | Switches hooks.json reading to read_file_checked inside cross-component checks. |
| src/diagnostics.rs | Defines new diagnostic code constant P011 and includes it in the codes test list. |
| src/fs_util.rs | Makes is_regular_file public for binary crate use. |
| src/lib.rs | Re-exports is_regular_file from the library API. |
| src/fixer.rs | Re-checks is_regular_file immediately before writing fixes back to disk. |
| src/cli/format.rs | Re-checks is_regular_file before formatting write-back. |
| scripts/version.sh | Replaces non-portable sed newline replacement with a portable awk insertion. |
| CHANGES.md | Adds release notes for SEC-4/5/6 and the version.sh portability fix. |
Comments suppressed due to low confidence (2)
src/cli/format.rs:36
find_skill_md(dir).unwrap()can panic if the SKILL.md path disappears or becomes a symlink/non-regular file betweenformat_skill(dir)and this write-back. That undermines the new TOCTOU hardening because the process may crash before theis_regular_filere-check. Handle theNonecase explicitly and emit an error/exit (or haveformat_skillreturn the resolved path so it can be reused).
let path = aigent::find_skill_md(dir).unwrap();
if !aigent::is_regular_file(&path) {
eprintln!(
"aigent format: target is no longer a regular file: {}",
path.display()
);
std::process::exit(1);
}
src/plugin/cross.rs:143
validate_cross_componentnow usesread_file_checked, but any read error (including the new >1 MiB limit) is silently ignored due toif let Ok(...). This can cause X002 hook-script checks to be skipped with no diagnostic, reducing the usefulness of validation on malformed/oversized hooks.json. Consider switching to amatchand pushing a dedicated cross-component diagnostic when hooks.json can't be read/parsed (including when it exceeds the size limit).
// X002: Hook command references script that doesn't exist
let hooks_path = root.join("hooks.json");
if hooks_path.is_file() {
if let Ok(content) = crate::parser::read_file_checked(&hooks_path) {
if let Ok(raw) = serde_json::from_str::<serde_json::Value>(&content) {
check_hook_script_paths(&raw, root, &mut diags);
}
}
- P011 (path traversal in plugin.json) changed from Warning to Error so validate-plugin exits non-zero, matching P006 (absolute path) and issue #151's recommendation - Document P006 short-circuit (no longer also emits P007) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
..) in plugin.json path overrides (P011)Closes [SEC-4] Path traversal in plugin.json path overrides #151
read_file_checkedCloses [SEC-5] Unbounded file reads in plugin validators #152
is_regular_filebefore write-back in fixer and formatterCloses [SEC-6] TOCTOU window between file validation and write-back #153
\nin sed replacement inversion.sh(awk-based approach)Details
SEC-4: Added
P011diagnostic andcontains_path_traversal()check inmanifest.rs. Paths with..components are rejected as warnings. Traversal paths skip the P007 existence check (same pattern as S006 in structure.rs). 5 new tests.SEC-5: Replaced
std::fs::read_to_string()withcrate::parser::read_file_checked()in all 5 plugin modules (manifest, hooks, agent, command, cross). The bounded reader rejects files over 1 MiB. Error handling uses the existing diagnostic pattern (match Ok/Err → push diagnostic → return).SEC-6: Added
is_regular_file()re-check immediately beforestd::fs::write()infixer.rsandcli/format.rs. This is option 1 from issue #153 (proportionate to the low risk level of a single-user CLI). Exportedis_regular_filefromlib.rsfor binary crate access.version.sh: Replaced
sedi "s/^# Changes$/# Changes\n\n$STUB/"(GNU sed\nextension) with portableawkthat explicitly prints each line — matching the pattern inwrite_changelog().Test plan
cargo clippy -- -D warningscleancargo fmt --checkcleanstd::fs::read_to_stringinsrc/plugin/version.shCHANGES.md stub on macOS (BSD sed)🤖 Generated with Claude Code