Skip to content

C#: Re-factor FeedManager to allow better unit testing. - #8

Open
anurag6569201 wants to merge 1 commit into
qa/agent-github-codeql/pr-08-22468/basefrom
qa/agent-github-codeql/pr-08-22468/head
Open

anurag6569201 wants to merge 1 commit into
qa/agent-github-codeql/pr-08-22468/basefrom
qa/agent-github-codeql/pr-08-22468/head

Conversation

@anurag6569201

Copy link
Copy Markdown

In this PR we

  • Re-factor the FeedManager to enable unit testing.
  • Add some unit tests.

This is in preparation for using feeds configured via the dependabot proxy as "base" feed(s) (instead of the current hardcoded public nuget.org feed).

DCA looks good.

Source merge-base: 973d5b503fa8fd5f7576253375d81b9b5629aad8
Source head: b76f7939d7fb7d5a10a1de2b271c11516d0a73e3

@shipwright-agent

Copy link
Copy Markdown

✅ Shipwright · Approve

Recommendation: approve PR #8 · Tier T2
Checks: 0 total · 0 needing attention

Next step: ready to merge.

Findings (9)

  • HIGH The new public interfaces expose mutable concrete collection types: IDependabotProxy.RegistryURLs is HashSet<string> and IFileProvider exposes ICollection<string> for Projects, Sol · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDependabotProxy.cs:12
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The new FeedManager constructor overload chain is confusing: the 5-argument constructor delegates to a 6-argument constructor with new FeedManagerIO(logger, dependabotProxy) (FeedM · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs:98
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The refactor changes the contract of RestoreFeeds/FeedsToRestoreArgument: previously the empty-feed case returned [prefix, dummyPath] and non-empty returned interleaved [prefix, fe · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs:142
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The empty-feed dummy-source behavior is now inconsistent between dotnet restore and nuget.exe paths. · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs:142
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The test stub DotNetStub in Semmle.Extraction.Tests/DotNetStub.cs has a Restore method that always returns new RestoreResult(true, Array.Empty<string>()) and ignores the RestoreSet · csharp/extractor/Semmle.Extraction.Tests/DotNetStub.cs:20
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The certificate validation callback moved to FeedManagerIO.IsFeedReachable (FeedManagerIO.cs:52-70) still uses a custom root trust callback that adds dependabotProxy.Certificate to · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManagerIO.cs:52
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The new public interfaces IDependabotProxy, IFeedManagerIO, and IFileProvider are declared public in a namespace that appears to be internal implementation (Semmle.Extraction.CShar · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDependabotProxy.cs:8
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • LOW The new file FeedManagerIO.cs has a leading blank line and an extra blank line before the closing brace (FeedManagerIO.cs:1, 107-108). · csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManagerIO.cs:1
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • …and 1 more findings in the check details.

Fireworks usage: 35,565 input · 1,512 output · 37,077 total tokens · $0.0088 · 22s · 0 fix iteration(s)

Open the Shipwright check for full evidence and the audit bundle. Use /shipwright rerun to verify again.

/// <summary>
/// The full address of the Dependabot proxy, if available.
/// </summary>
string Address { get; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The new public interfaces expose mutable concrete collection types: IDependabotProxy.RegistryURLs is HashSet<string> and IFileProvider exposes ICollection<string> for Projects, Sol

Impact: The new public interfaces expose mutable concrete collection types: IDependabotProxy.RegistryURLs is HashSet<string> and IFileProvider exposes ICollection<string> for Projects, Solutions, NugetConfigs, etc. This leaks implementation details and allows callers to mutate state shared with the implementation. For example, FeedManager copies RegistryURLs into an ImmutableHashSet in the constructor (FeedManag…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

this.sdks = sdks;
this.nugetFeedsFromConfig = nugetFeedsFromConfig;
this.nugetFeedsFromFolder = nugetFeedsFromFolder;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The test stub DotNetStub in Semmle.Extraction.Tests/DotNetStub.cs has a Restore method that always returns new RestoreResult(true, Array.Empty<string>()) and ignores the RestoreSet

Impact: The test stub DotNetStub in Semmle.Extraction.Tests/DotNetStub.cs has a Restore method that always returns new RestoreResult(true, Array.Empty<string>()) and ignores the RestoreSettings, including NugetSources. This means the new source-argument behavior in DotNet.GetRestoreArgs is not actually verified by the FeedManager tests; the tests only verify FeedManager's feed selection, not that the final restore com…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

{
httpClientHandler.Proxy = new WebProxy(dependabotProxy.Address);

if (dependabotProxy.Certificate != null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The certificate validation callback moved to FeedManagerIO.IsFeedReachable (FeedManagerIO.cs:52-70) still uses a custom root trust callback that adds dependabotProxy.Certificate to

Impact: The certificate validation callback moved to FeedManagerIO.IsFeedReachable (FeedManagerIO.cs:52-70) still uses a custom root trust callback that adds dependabotProxy.Certificate to the chain's CustomTrustStore and calls chain.Build(cert). This callback is invoked for every HTTPS request made through the proxy, including arbitrary NuGet feed URLs. If the proxy address or certificate is attacker-influenced (e.g., via…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

namespace Semmle.Extraction.CSharp.DependencyFetching
{
public interface IDependabotProxy : IDisposable
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The new public interfaces IDependabotProxy, IFeedManagerIO, and IFileProvider are declared public in a namespace that appears to be internal implementation (Semmle.Extraction.CShar

Impact: The new public interfaces IDependabotProxy, IFeedManagerIO, and IFileProvider are declared public in a namespace that appears to be internal implementation (Semmle.Extraction.CSharp.DependencyFetching). Making these public expands the API surface and allows external code to implement or mock these abstractions, including the certificate validation and proxy configuration. This increases the attack surface and makes…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

@@ -0,0 +1,109 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · LOW

The new file FeedManagerIO.cs has a leading blank line and an extra blank line before the closing brace (FeedManagerIO.cs:1, 107-108).

Impact: The new file FeedManagerIO.cs has a leading blank line and an extra blank line before the closing brace (FeedManagerIO.cs:1, 107-108). This is a minor style inconsistency that suggests the file was not formatted with the project's standard tooling.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

@@ -0,0 +1,16 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · LOW

The interface IFeedManagerIO has a leading blank line before the namespace declaration (IFeedManagerIO.cs:1).

Impact: The interface IFeedManagerIO has a leading blank line before the namespace declaration (IFeedManagerIO.cs:1). This is a minor style issue and inconsistent with the other new interface files.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant