Cargo config files pulled in with `include` are not read: a vendored crate is reported as patched, and attested, while cargo builds the unpatched copy
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start with config_layer_paths in core/formats/cargo/source_replacement.rs, then inspect its callers in the Cargo crawler, build cache, hosted rewriter, and user patch gate. The issue supplies three failing tests; run cargo test -p socket-patch-core --lib -- from_an_included_config to reproduce them. Done means all config readers follow Cargo's include order and path rules, while respecting the repository bound described in the planned fix.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L46), on main at cfc870f.
Problem
Cargo reads more config files than socket-patch does. A .cargo/config.toml may pull other files in with the top-level include key, and cargo 1.97.0 follows it on stable (cargo 1.93.1, the toolchain this repository pins, still ignores the key). socket-patch reads .cargo/config or .cargo/config.toml in each ancestor and in $CARGO_HOME, and nothing those files include. So whatever a project sets in an included file is invisible to it, and four mechanisms decide wrongly:
- Which copy cargo builds. A
cargo vendorproject whose source replacement sits in an included file builds fromvendor/. An agent-modescanorapplypatches the copy in the shared registry cache instead, which cargo does not build, and reportsApplied 1 patchandPatched 1 package, exit 0.apply --checksaysPatches are in sync, andvexwrites anot_affectedstatement. The build is unpatched. - Which build directory holds the compiled copy. With
build.target-dirin an included file, the crate is patched, but its fingerprints in that directory are not deleted, so the nextcargo buildcompiles nothing and the binary keeps the pre-patch code. Nocargo_build_cache_stalewarning is raised. - Whether the project overrides the crate. A
pathsoverride in an included file does not protect the crate: the scan patches the registry copy andvexattests it, while cargo builds the override. - Whether a hosted pin would break an offline build. A hosted scan refuses to pin a crate of a project that builds from a directory source (
redirect_cargo_directory_source). With the same source replacement in an included file it writes the pin.
CLI_CONTRACT.md ("Cargo and Go in agent mode") states the rule for the first: "The directory source is the one cargo builds from: the [source.crates-io] replace-with chain of every .cargo/config* cargo reads (the working directory and each ancestor, then $CARGO_HOME's), wherever it points (#338). A vendor/ no config wires is not crawled, and a configured directory that is missing yields nothing rather than the registry copy cargo ignores."
Who it hurts
- A project that keeps the output of
cargo vendorin a file of its own (cargo vendor > .cargo/vendor.toml) and includes it, or shares one config file between several workspaces, or keeps developer-local settings in an optional included file.includeexists for these layouts. - Their release build: it ships the vulnerable crate while the scan step says
Patched 1 package. - Anyone who reads the VEX document: it says
not_affectedfor a crate the build takes unpatched.
Evidence on main
The binary is built from cfc870f. cargo is 1.97.0, offline, with a CARGO_HOME of its own that holds fnv-1.0.7. The app prints fnv::FnvHasher::default().finish(); the patch changes the offset basis in lib.rs to 0x1111111111111111, so the output shows which bytes the build linked. The patch API is a local stand-in that serves the one patch.
The source replacement in an included file:
$ cat .cargo/config.toml
include = ["vendor.toml"]
$ cat .cargo/vendor.toml
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
$ cargo metadata --offline --format-version 1 | jq -r '.packages[] | select(.name=="fnv") | .manifest_path'
<w>/app/vendor/fnv/Cargo.toml
$ cargo build --offline -q && ./target/debug/app
cbf29ce484222325
$ socket-patch scan --mode agent
Found 1 package (1 cargo)
Applied 1 patch.
HIGH [email protected] CVE-2026-0001
Next steps:
1. Commit .socket/ to keep the patches.
2. Run `socket-patch apply` after every `cargo fetch`, locally and in CI. A fresh install removes the patches.
Patched 1 package, fixing 1 vulnerability (1 high).
… (exit 0)
$ grep -c 0x1111111111111111 vendor/fnv/lib.rs $CARGO_HOME/registry/src/*/fnv-1.0.7/lib.rs
vendor/fnv/lib.rs:0
<w>/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/fnv-1.0.7/lib.rs:1
$ cargo build --offline -q && ./target/debug/app
cbf29ce484222325
$ socket-patch apply --check
Patches are in sync (1 patch checked). (exit 0)
$ socket-patch vex --product pkg:generic/app@1 -O - | jq -c '.statements[] | {status, impact_statement}'
{"status":"not_affected","impact_statement":"Patched via Socket patch cccccccc-0000-4000-8000-000000000001"}
The same project with the two tables in .cargo/config.toml itself:
$ socket-patch scan --mode agent
…
Patched 1 package, fixing 1 vulnerability (1 high). (exit 0)
$ grep -c 0x1111111111111111 vendor/fnv/lib.rs $CARGO_HOME/registry/src/*/fnv-1.0.7/lib.rs
vendor/fnv/lib.rs:1
<w>/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/fnv-1.0.7/lib.rs:0
$ cargo build --offline -q && ./target/debug/app
1111111111111111
The build directory (no vendoring; .cargo/config.toml is include = ["build.toml"], and .cargo/build.toml sets [build] target-dir = "out"):
$ cargo build --offline -q && ./out/debug/app
cbf29ce484222325
$ socket-patch scan --mode agent --json | jq -c '[.events[] | .action], [.warnings[].code]'
["downloaded","applied"] []
$ cargo build --offline && ./out/debug/app # compiles nothing
cbf29ce484222325
With target-dir = "out" in .cargo/config.toml itself, the build after the scan compiles fnv and app again and prints 1111111111111111.
The override (.cargo/config.toml is include = ["dev.toml"], and .cargo/dev.toml is paths = ["../fnv-fork"]; the fork's constant is 0x2222222222222222):
$ cargo build --offline -q && ./target/debug/app
2222222222222222
$ socket-patch scan --mode agent --json | jq -c '[.events[] | [.action, .errorCode]], [.warnings[].code]'
[["downloaded",null],["applied",null]] []
$ cargo build --offline -q && ./target/debug/app
2222222222222222
$ socket-patch vex --product pkg:generic/app@1 -O - | jq -c '.statements[] | {status, impact_statement}'
{"status":"not_affected","impact_statement":"Patched via Socket patch cccccccc-0000-4000-8000-000000000001"}
With paths in .cargo/config.toml itself the scan skips the crate with user_patch_conflict and writes nothing.
Hosted mode, over the benchmark harness's Cargo project (socket-patch-bench serve cargo/hosted), with a vendor/ directory and the same two layouts:
direct exit 0 events [skipped pkg:cargo/[email protected] redirect_unconfirmed] warnings [redirect_cargo_directory_source]
include exit 0 events [applied pkg:cargo/[email protected]] warnings []
What cargo 1.97.0 does with include, measured with cargo metadata over build.target-dir:
| Case | Result |
|---|---|
include = ["a.toml"], include = [{ path = "a.toml" }], [[include]] with path |
each is followed; a bare string (include = "a.toml") is an error |
| the including file and an included file set the same key | the including file wins |
include = ["a.toml", "b.toml"], both set the key |
b.toml wins |
a relative value in .cargo/sub/c.toml |
resolves against .cargo/: the parent of the included file's directory |
config.toml includes a.toml, which includes b.toml |
followed |
{ path = "missing.toml", optional = true } |
skipped |
a required file that is missing, or a path that does not end in .toml |
cargo fails to load its configuration |
include in $CARGO_HOME/config.toml |
followed |
Cause
Three readers of cargo's config, and none knows the key:
config_layer_paths(coreformats/cargo/source_replacement.rs, line 114) lists.cargo/configor.cargo/config.tomlfor each ancestor, then$CARGO_HOME's. Its callers are the crawler'sresolve_for(corecrawlers/cargo_crawler.rs, line 373) andConfigDirs::read(coreutils/cargo_build_cache.rs, line 165), which readsbuild.target-dirandbuild.build-dir.- The hosted rewriter judges the project's own config file as a single layer (core
patch/redirect/mod.rs, line 2163) and asks the crawler for the configs outside the project (crates_io_source_for, called from CLIcommands/scan/hosted.rs, line 2045). - The project-patch gate reads
.cargo/config.tomland.cargo/configby name in each directory it walks (cargo, corepatch/user_patches.rs, line 1113).
The failing tests
Three unit tests, each beside the code it exercises. All three fail on main:
// core crawlers/cargo_crawler.rs
#[test]
fn a_directory_source_from_an_included_config_is_the_source() {
let tmp = tempfile::tempdir().unwrap();
let root = std::fs::canonicalize(tmp.path()).unwrap();
std::fs::create_dir_all(root.join(".cargo")).unwrap();
std::fs::create_dir_all(root.join("vendor")).unwrap();
std::fs::write(root.join(".cargo/config.toml"), "include = [\"vendor.toml\"]\n").unwrap();
std::fs::write(
root.join(".cargo/vendor.toml"),
"[source.crates-io]\nreplace-with = \"vendored-sources\"\n\n\
[source.vendored-sources]\ndirectory = \"vendor\"\n",
)
.unwrap();
assert_eq!(
resolve_for(crate::utils::repo_root::ReadScope::Workspace, &root, None),
CratesIoSource::Directory(root.join("vendor"))
);
}
// core utils/cargo_build_cache.rs
#[test]
fn a_target_dir_from_an_included_config_is_a_build_dir() {
let t = tempfile::tempdir().unwrap();
let root = std::fs::canonicalize(t.path()).unwrap();
std::fs::create_dir_all(root.join(".cargo")).unwrap();
std::fs::create_dir_all(root.join("out")).unwrap();
std::fs::write(root.join(".cargo/config.toml"), "include = [\"build.toml\"]\n").unwrap();
std::fs::write(root.join(".cargo/build.toml"), "[build]\ntarget-dir = \"out\"\n").unwrap();
let d = build_dirs_with(crate::utils::repo_root::ReadScope::Workspace, &root, &|_| None, None);
assert_eq!(d.dirs, vec[root.join("out")]);
}
// core patch/user_patches.rs
#[tokio::test]
async fn a_cargo_paths_override_from_an_included_config_protects_cargo() {
let tmp = tempfile::tempdir().unwrap();
write(tmp.path(), ".cargo/config.toml", "include = [\"dev.toml\"]\n");
write(tmp.path(), ".cargo/dev.toml", "paths = [\"../fnv-fork\"]\n");
let index = UserPatchIndex::discover(tmp.path()).await;
assert!(!index.conflicts("pkg:cargo/[email protected]").is_empty(), "{index:?}");
}
$ cargo test -p socket-patch-core --lib -- from_an_included_config
test utils::cargo_build_cache::tests::a_target_dir_from_an_included_config_is_a_build_dir ... FAILED
test crawlers::cargo_crawler::tests::a_directory_source_from_an_included_config_is_the_source ... FAILED
test patch::user_patches::tests::a_cargo_paths_override_from_an_included_config_protects_cargo ... FAILED
---- utils::cargo_build_cache::tests::a_target_dir_from_an_included_config_is_a_build_dir stdout ----
assertion `left == right` failed
left: []
right: ["/tmp/.tmpnpyq9a/out"]
---- crawlers::cargo_crawler::tests::a_directory_source_from_an_included_config_is_the_source stdout ----
assertion `left == right` failed
left: Registry
right: Directory("/tmp/.tmpChhZiC/vendor")
---- patch::user_patches::tests::a_cargo_paths_override_from_an_included_config_protects_cargo stdout ----
UserPatchIndex { entries: [] }
Planned fix
One function lists the config files cargo reads, and every reader takes its files from it.
config_layer_pathsexpands each file it lists into that file followed by the files it includes, in cargo's order of precedence: the including file first, then itsincludeentries from last to first, each expanded the same way. A relative value in an included file resolves against the parent of that file's directory. An optional file that is missing is skipped. A cycle stops the expansion.- The repository bound stays: in a workspace run an included file outside the git repository root is not read, and the run says so the way it does for a config above the root (
config_above_repo). - The hosted rewriter and the project-patch gate take their layers from the same list, so a directory source in an included file refuses the pin, and a
pathsoverride or a[patch]table in an included file protects what it names. - The three tests above, and one end-to-end test with a real cargo build beside
tests/e2e_safety_cargo_build.rs, gated on a cargo that followsinclude.
What the fix changes: which copy an agent-mode apply patches, which fingerprints it deletes, which crates the gate protects and which pins hosted mode refuses, all for projects that use include. A project without the key is read as before.
Generated by Claude Code
- Ngôn ngữ chính
- Rust
- Star
- 9
- Fork
- 2
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 313
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
SocketDev/socket-patch#2306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit bug priority:p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
SocketDev/socket-patch#2296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:needs-human agent:triaged ci-janitor priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SocketDev/socket-patch#2270 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit bug priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
SocketDev/socket-patch#2259 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit priority:p3 refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
SocketDev/socket-patch#1860 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của SocketDev/socket-patch
Issue tương tự
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Có thể đã có người làm @iliqiliev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ajeetdsouza/zoxide#1381 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
kornia/kornia-rs#1416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
paritytech/revive#749 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
swc-project/swc-next-issues#1043 ·