Repository navigation
Hosted NuGet mapping reads commented-out package sources #561
Description
Activity
- addedbugSomething isn't workingSomething isn't workingpm:nugetNuGet / dotnetNuGet / dotnetarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)Filed by a scheduled architecture audit routine (see the architecture review discussion)
on Oct 2, 2026 - added a commit that references this issue
on Oct 2, 2026 mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] Triage: priority:p3 (NuGet). Confirmed on main:
nuget_package_source_keys(patch/redirect/mod.rs:4357) regex-scans raw XML without masking comments, while restore and VEX useformats::nuget::parse_config. Distinct from #462/#354 (mapping exclusivity / inherited sources); no open PR covers it.
Generated by Claude Code
mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] Shares root cause with #585: the hosted NuGet rewriter (
add_nuget_sourceinpatch/redirect/mod.rs) runs every regex lookup (source keys, the<packageSources>/<packageSourceMapping>splice anchors) on the rawnuget.configtext instead of comment-masked text. Will be fixed together.
Generated by Claude Code
mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] Re-checked on main
203e092: still present. The code moved, so here are fresh permalinks.nuget_package_source_keysstill regex-scans the rawnuget.config, and it is called fromadd_nuget_sourceandrewrite_nuget.The splice-anchor half that this issue's "Out of scope" note mentions is now #585. The wider unification (hosted, vendored and restore readers and anchors on
formats::nuget) is #594, which this issue can land ahead of.
Generated by Claude Code
mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] Open PR #597 addresses this (together with #585) by moving the hosted NuGet reader and splice anchors onto
formats::nuget. Leaving open until it merges.
Generated by Claude Code
[agent] Filed by the scheduled architecture audit routine (ecosystems and formats). Register: #560 (comment).
Kind: bug. Source: review §1 #5; Part 5.4; register E01 (first step of E11).
Problem
The hosted NuGet rewriter reads the pre-existing
<packageSources>keys with two regexes over the raw XML and never masks<!-- … -->:redirect/mod.rs#L4343-L4376:``NUGET_PACKAGE_SOURCES_REGION_RE, `NUGET_ADD_KEY_RE` and `nuget_package_source_keys`.add_nuget_source(#L4159-L4231) uses those keys for two decisions. It skips seedingnuget.orgwhen the list is non-empty (seed_nuget_org = creating_mapping && pre_existing_keys.is_empty()). It also fans<package pattern="*" />out to every key in the list.The other two readers of the same file both skip comments:
formats::nuget::parse_config(formats/nuget/mod.rs#L51-L91) is a real tag walk. It is already used by hosted restore (upstream/nuget.rs#L26) and by VEX (vex/discover/nuget.rs#L77).blank_commentsbeforeparse_config_source_keys(vendor/nuget_feed.rs#L1014-L1075).``So hosted forward and hosted restore disagree about the same
nuget.config.Reproduced on
d63ae5f(a unit test inredirect/mod.rs, run twice). The input is anuget.configwhose only source is commented out:The comment counts as a pre-existing source, so
nuget.orgis never seeded. The catch-all*goes toold, which is not a source in this file. Once the mapping exists it is exclusive, so restore of every other package then depends on a key that NuGet does not read from this file. A commented<packageSources>block placed before the real one is mis-read the same way, becauseNUGET_PACKAGE_SOURCES_REGION_REcaptures the first match.Symptoms
None filed for the comment case. Related, but a different defect: #354 (the
*fan-out ignores sources inherited from parent and user configs) and #462. Both live in the same function.Impact: any hosted NuGet project whose
nuget.confighas commented-out sources (common in templates and docs) can get a mapping that routes*to a source this file doesn't define. That breaks restore or sends packages to the wrong feed. Size: small.Proposed change
pre_existing_keysfromformats::nuget::parse_config(config): itssourceskeys, minusdisabledif that matches the vendored behavior. Do this when the parse returnsNone(malformed config): skip the dep fail-closed, as the other readers do.nuget_package_source_keysandNUGET_ADD_KEY_RE, plusNUGET_PACKAGE_SOURCES_REGION_REif nothing else uses it.insert_nuget_source,nuget_mapping_open_end) are also regex-based. Moving them onto a span-awareformats::nugetmodel is E10/E11 follow-up work. Note in the PR whetherinsert_nuget_source's open-tag regex can match inside a comment; if it can, file that as a separate issue.Size and scope
crates/socket-patch-core/src/patch/redirect/mod.rsonly. About −30 / +15 production lines, plus tests.Acceptance criteria
nuget_package_source_keysis gone, and hosted forward reads sources throughformats::nuget::parse_config.nuget.organd maps*only to defined sources.<packageSources>block before the real one, plus a commented<add>beside real ones, both yield the real keys only.group_equivalence_tests, and the hosted/memory parity tests stay green.Dependencies
Blocked by nothing. This is the first step of the E11 consolidation (one NuGet config reader). The vendored
parse_config_source_keysis the next one.