Hosted/vendored NuGet mapping isn't exclusive when nuget.config already maps the exact package id to another source, so restore races the Socket feed against nuget.org (NU1403 with a lock, silently unpatched without one)
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- build-system, cli, devtools
Hướng nghiên cứu
Start with the hosted mapping logic in crates/socket-patch-core/src/patch/redirect/mod.rs:4132-4140 and the vendored paths in crates/socket-patch-core/src/vendor/nuget_feed.rs:896 and :915. Use crates/socket-patch-cli/tests/e2e_nuget_dotnet_build.rs and the described NuGet fixture to verify that an existing exact-id mapping no longer leaves the Socket source tied with another source; locked and lockless restores should resolve only the patched package.
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 scheduled NuGet / dotnet bug-hunt routine (ledger #320).
Summary
When the project's nuget.config already has a <packageSourceMapping> that names the patched package's exact id under another source (Visual Studio's package-source-mapping UI writes exactly this, e.g. <package pattern="Newtonsoft.Json" /> under nuget.org), scan --mode hosted (and --mode vendored) just adds a second exact-id mapping under socket-patch-<uuid>. Two sources now have the same most-specific pattern, so NuGet treats both as eligible and takes the package from whichever answers first.
The rewriter assumes "most specific pattern wins" (crates/socket-patch-core/src/patch/redirect/mod.rs:6696). That doesn't hold for a tie, and nothing detects the tie, warns about it, or removes the user's entry.
Impact
- With
packages.lock.json: if nuget.org answers before the Socket feed, a freshdotnet restore --locked-modedownloads the upstream nupkg and fails withNU1403: Package content hash validation failed. Whether CI is green or red then depends on feed latency. - Without a lock: the same restore exits 0 and installs the unpatched upstream bytes.
scanreported success and printed no warning.
Repro
This uses the repo's own real-dotnet harness (crates/socket-patch-cli/tests/e2e_nuget_dotnet_build.rs: its Backend wiremock stand-in for the API and the hosted feed, a real nuget.org fixture restore, and fresh_checkout). After restore_fixture, overwrite the fixture's config with the one below and restore it once (--locked-mode, which passes):
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
<package pattern="Newtonsoft.Json" />
</packageSource>
</packageSourceMapping>
</configuration>
Then run:
socket-patch scan --mode hosted --json --yes --api-url <stub> --org test-org --api-token x --patch-server-url <stub>exits 0,warnings: [].- Make a fresh checkout (csproj, nuget.config, lock), then run
dotnet restore --locked-modewith a coldNUGET_PACKAGESand a cold http cache. - Make the stand-in's flat-container
index.jsonanswer 3 s late (ResponseTemplate::set_delay), standing in for a Socket feed that is slower than nuget.org's CDN.
Config after step 1:
<packageSourceMapping>
<packageSource key="socket-patch-4e4e4e4e-…">
<package pattern="Newtonsoft.Json" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
<package pattern="Newtonsoft.Json" /> <!-- still there: a tie -->
</packageSource>
</packageSourceMapping>
Results (2/2 runs, 2 cold restores each):
| shape | Socket feed delay | result |
|---|---|---|
| user exact-id mapping, locked restore | 3000 ms | error NU1403, 0 requests for the Socket nupkg, cache holds the pristine LICENSE.md |
| user exact-id mapping, lockless restore | 3000 ms | exit 0, pristine bytes installed |
| user exact-id mapping, locked restore | 0 ms / 500 ms | pass (the local stand-in wins the race) |
control: default nuget.config (no user mapping), locked restore |
3000 ms | pass (the Socket source is the only eligible one) |
The control shows the failure comes from the tie, not from the delay. Vendored mode writes the same tie (socket-patch-<uuid> → .socket/vendor/nuget/<uuid> beside the user's nuget.org → Newtonsoft.Json). Its local folder feed usually wins the race, so I didn't get a failing vendored restore. The config is equally non-exclusive, though.
Expected vs actual
- Expected: CLI_CONTRACT.md (hosted/vendored table, nuget row) says the rewrite adds "source
socket-patch-<uuid>+ its exclusive exact-id<packageSourceMapping>". docs/ecosystems.md (NuGet row) says hosted pins the id via source mapping plus the lockcontentHash. The patched id should resolve only from the Socket source. So the rewriter should drop or override the user's same-id pattern on other sources, or at least refuse or warn. - Actual: the user's exact-id entry stays, the mapping isn't exclusive, restore is nondeterministic, and the lockless case silently installs the unpatched package.
Matrix
| OS | SDK | hosted | vendored |
|---|---|---|---|
| Linux | 8.0.131 | fail (locked: NU1403; lockless: silently unpatched) | config tie reproduced; restore passed (local feed wins) |
| macOS / Windows, SDK 6/9/10 | untested (SDK downloads from dot.net are blocked in this sandbox). The race is NuGet client behaviour, so I expect the same result | untested |
Main 2463257 (v5 consolidation, #277).
Suspect code
crates/socket-patch-core/src/patch/redirect/mod.rs:4132-4140: when a mapping already exists (!creating_mapping), it appends only the Socket<packageSource>and never looks for the same id under other sources.crates/socket-patch-core/src/vendor/nuget_feed.rs:896/:915: the same append for vendored.
Related, but not the same: #354 (the * fan-out cuts off inherited sources) and #352 (a warm cache shadows the patch).
- Ngôn ngữ chính
- Rust
- Star
- 8
- Fork
- 0
- Merge trung bình
- 1 ngày 31 phút
- Pull request đã merge (30 ngày)
- 151
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 bug bughunt pm:yarn-berry priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
SocketDev/socket-patch#783 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged bug bughunt pm:pipenv priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
SocketDev/socket-patch#744 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged bug bughunt pm:cargo priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
SocketDev/socket-patch#651 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged bug bughunt pm:composer priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
SocketDev/socket-patch#515 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A report-only `scan -g` tells you to run `socket-patch scan --mode agent [PATHS]` without `-g`, so following the hint scans the cwd project instead of the global installCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởagent:triaged bug bughunt pm:npm priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
SocketDev/socket-patch#464 · 1 bình luận ·
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ự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
-
review-drift
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
oxidecomputer/hansei#14 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
rubys/roundhouse#444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Published hardy-bpa-server image is built without the file-cla featureCó thể đã có người làm @EmbryoSpace đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
ricktaylor/hardy#755 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
semaphoreci/docker-images#46 · 1 bình luận ·