You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(nuget): look packages up on nuget.org only when NuGet could not take them elsewhere - #171
Third per-ecosystem fix from the registry audit, after Bundler (#168) and Composer (#170). NuGet looked every package up on nuget.org, so a package from a private feed could be looked up there, where its name may be someone else's.
Why not the lockfile
packages.lock.json records versions and hashes but not which source a package came from. With several sources and no mapping, NuGet takes a package from whichever source answers, so no committed file says where a package comes from. NuGet's own answer to that is packageSourceMapping.
Why the Count over-counts sources
The first version followed NuGet's config merging (clear, remove, disabledPackageSources, mapping precedence across files). Review found it wrong in several places:
remove is not a NuGet element.
Disabled sources are matched by exact key, whatever the value.
A closer config's packageSource replaces a farther one rather than merging with it.
Repeated elements are dropped.
Patterns are cut at their first *.
So the reader no longer follows those rules. It counts in the direction that can only fail a lookup.
The rule
Sources: every source any nuget.config from the project's folder up to the repository root adds counts, even one a closer config clears or disables, along with the nuget.org source NuGet adds by default.
nuget.org alone: every package comes from nuget.org.
Any other source:packageSourceMapping decides.
Only a mapping that one config on the chain holds alone is read. Its most specific pattern wins: an exact ID, else the longest prefix.
Mappings in several configs on one chain fail every lookup. NuGet merges them by replacing, dropping and clearing, which the Count does not follow. An earlier version pooled their patterns, and review broke that twice.
A package mapped to nuget.org alone comes from there. Anything else fails its lookup, since private feeds aren't read yet.
With no mapping, every lookup fails, and the message names packageSourceMapping.
Shared files:Directory.Packages.props, other shared MSBuild files and dotnet-tools.json manifests count every folder below them that has a config of its own.
Fails closed: each of these fails every lookup it could affect:
a config the Count can't read;
a section it doesn't know, such as fallbackPackageFolders, or remove;
a repeated mapping section or key, or a clear after mappings;
a pattern NuGet reads differently: a * that isn't last, spaces, non-ASCII, or an exact ID that is also a prefix;
a config file named other than NuGet reads it, or several configs in one folder;
an MSBuild or response file that sets RestoreSources, RestoreAdditionalProject*, RestoreConfigFile or RestoreFallbackFolders (found after decoding XML character references), or one the Count can't read.
Always read:nuget.config, .props, .targets, .rsp, .projitems, .user, .msbuild and project files are read whenever NuGet is enabled. Symlinked or non-text ones count as unreadable.
nuget.config is parsed with roxmltree (new dependency), which rejects DTDs. Adding it also re-resolved some unrelated Windows-only windows-sys/getrandom entries in Cargo.lock.
Known residual: an MSBuild <Import> of a file with another extension isn't scanned for restore properties.
Docs: sources.md (package registries), managers.md, compatibility.md, and departures.md (new #nuget-sources).
Follow-ups
A repository's own regex extractor with source: "nuget" (or pypi, rubygems, packagist) and no registry template skips these origin rules in every ecosystem (crates/manager/src/custom.rs).
An MSBuild <Import> of a file with another extension, or props from an MSBuild SDK package, is not scanned for restore properties.
…ake them elsewhere
NuGet looked every package up on nuget.org, so a package from a private
feed could be looked up there, where its name may be someone else's.
packages.lock.json does not record a package's source, and with several
sources NuGet takes a package from whichever answers, so the nuget.config
files decide through crate::origins:
- The configs from the project's folder up to the repository root apply
as NuGet applies them (clear, remove and disabledPackageSources), after
the nuget.org source NuGet adds by default.
- nuget.org alone: every package comes from it.
- Another source: packageSourceMapping must say which source serves the
package. Its most specific pattern decides; a package mapped to
nuget.org alone comes from there, and any other fails its lookup until
private NuGet feeds are read.
- A shared MSBuild file such as Directory.Packages.props counts every
folder below it with a config of its own.
- A config the Count cannot read, with a section it does not know such as
fallbackPackageFolders, or spelled other than NuGet reads it, and an
MSBuild file that sets RestoreSources or a related property, fail every
lookup they could affect. nuget.config is read with roxmltree, which
rejects DTDs.
We reviewed changes in e44ef52...80c0726 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
The reason will be displayed to describe this comment to others. Learn more.
Invoking `map_or(..)` with the identity function, consider using `unwrap_or(..)` instead
Calling map_or with the identity closure is equivalent to using unwrap_or
which is both easier to read and generally more performant.
Consider replacing map_or with unwrap_or.
…rges
Review found NuGet merges configs in ways the first version modelled
wrongly: remove is not an element, disabledPackageSources is matched by
exact key whatever its value, a closer config's packageSource replaces a
farther one, repeated elements are dropped and patterns are cut at their
first star. Rather than follow each rule, the reader now counts in the
direction that can only fail a lookup:
- Every source any config in the chain adds counts, even one a closer
config clears or disables.
- One config's mapping decides by most specific pattern; with mappings in
several configs, every matching pattern counts.
- remove, repeated mapping sections or keys, a clear after mappings,
patterns NuGet reads differently (a star that is not last, spaces,
non-ASCII, an exact ID that is also a prefix) fail closed.
- A tool manifest covers every config below its folder.
- MSBuild restore properties are found after decoding character
references, under more property names and file types, and an MSBuild
file the Count cannot read counts as one that sets them.
- RestoreRootConfigDirectory and RestoreSolutionDirectory, which move the
folder NuGet reads configs from, override the repository's configs, and
.pubxml files are scanned too.
- Source and mapping keys with spaces around them or outside ASCII fail
closed, since NuGet trims mapping keys but not source keys.
- A shared MSBuild file (.props, .targets) can be imported from any
folder, so it counts every folder with a config.
- Character references are searched within ten bytes, so a long run of
"&#" stays linear.
- On the GitHub path, a settings or MSBuild file that is not UTF-8 is
unreadable, as in read_tree, instead of failing the whole scan.
…rences
- A packageSourceMapping clear in one of several configs' mappings can
turn NuGet's mapping off, so any source serves any package; such a
chain now fails instead of pooling the patterns. A packageSource with
no package patterns is not read.
- Character references are decoded whatever leading zeros their digits
have, still in linear time.
- Each folder's chain of configs is computed once, so shared files in a
large repository no longer recompute them per package.
Pooling mappings from several configs rested on an argument about how
NuGet merges them, and review broke it twice (a closer clear can turn the
mapping off). Mappings in several configs on a chain now fail every
lookup, so the rule is short: sources are over-counted, and the one
mapping NuGet sees is exactly that config's.
The reason will be displayed to describe this comment to others. Learn more.
Invoking `map_or(..)` with the identity function, consider using `unwrap_or(..)` instead
Calling map_or with the identity closure is equivalent to using unwrap_or
which is both easier to read and generally more performant.
Consider replacing map_or with unwrap_or.
…urces
- Only a tool manifest's own .config folder stands for its project, not
any folder ending in .config.
- A project restores in its own folder, so configs below it no longer
count for it; shared MSBuild files and tool manifests still count
every folder below them.
- A source value with quotes or spaces around it, which NuGet keeps and
the Count would trim, is not read.
The reason will be displayed to describe this comment to others. Learn more.
Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead
Calls to unwrap_or followed by a function call should be replaced with unwrap_or_else or unwrap_or_default, to increase laziness. The argument to unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.
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
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.
Third per-ecosystem fix from the registry audit, after Bundler (#168) and Composer (#170). NuGet looked every package up on nuget.org, so a package from a private feed could be looked up there, where its name may be someone else's.
Why not the lockfile
packages.lock.jsonrecords versions and hashes but not which source a package came from. With several sources and no mapping, NuGet takes a package from whichever source answers, so no committed file says where a package comes from. NuGet's own answer to that ispackageSourceMapping.Why the Count over-counts sources
The first version followed NuGet's config merging (
clear,remove,disabledPackageSources, mapping precedence across files). Review found it wrong in several places:removeis not a NuGet element.packageSourcereplaces a farther one rather than merging with it.*.So the reader no longer follows those rules. It counts in the direction that can only fail a lookup.
The rule
nuget.configfrom the project's folder up to the repository root adds counts, even one a closer config clears or disables, along with the nuget.org source NuGet adds by default.packageSourceMappingdecides.packageSourceMapping.Directory.Packages.props, other shared MSBuild files anddotnet-tools.jsonmanifests count every folder below them that has a config of its own.fallbackPackageFolders, orremove;clearafter mappings;*that isn't last, spaces, non-ASCII, or an exact ID that is also a prefix;RestoreSources,RestoreAdditionalProject*,RestoreConfigFileorRestoreFallbackFolders(found after decoding XML character references), or one the Count can't read.nuget.config,.props,.targets,.rsp,.projitems,.user,.msbuildand project files are read whenever NuGet is enabled. Symlinked or non-text ones count as unreadable.nuget.configis parsed withroxmltree(new dependency), which rejects DTDs. Adding it also re-resolved some unrelated Windows-onlywindows-sys/getrandomentries inCargo.lock.Known residual: an MSBuild
<Import>of a file with another extension isn't scanned for restore properties.Docs: sources.md (package registries), managers.md, compatibility.md, and departures.md (new
#nuget-sources).Follow-ups
source: "nuget"(or pypi, rubygems, packagist) and noregistrytemplate skips these origin rules in every ecosystem (crates/manager/src/custom.rs).<Import>of a file with another extension, or props from an MSBuild SDK package, is not scanned for restore properties.