Skip to content

NuGet: Auto-patch NuGet.Config to allow insecure HTTP feeds#15092

Merged
brettfo merged 1 commit into
mainfrom
brettfo/nuget-insecure-http-feed-patching
May 21, 2026
Merged

NuGet: Auto-patch NuGet.Config to allow insecure HTTP feeds#15092
brettfo merged 1 commit into
mainfrom
brettfo/nuget-insecure-http-feed-patching

Conversation

@brettfo
Copy link
Copy Markdown
Contributor

@brettfo brettfo commented May 20, 2026

Summary

Automatically adds allowInsecureConnections="true" to http:// package sources in NuGet.Config files before running update scenarios. This allows Dependabot to restore packages from insecure HTTP feeds without requiring the attribute in the original config file.

Reasoning

A repo owner might locally use an older version of NuGet.exe that doesn't complain on insecure package feeds along with a custom, you guessed it, insecure package feed. In that instance dependabot should still generate a package update PR.

Changes

  • RunWorker.cs: Added AddInsecureConnectionsAttribute (static, public) to patch NuGet.Config XML content, and PatchNuGetConfigFilesAsync (private) to scan the repo and apply patches before running handlers
  • TestHttpServer.cs: Added CreateTestNuGetV2Feed factory method for V2 OData-based NuGet feeds
  • EndToEndTests.InsecureHttpFeed.cs: End-to-end test with .slnx, SDK-style project (V3 feed), and packages.config project (V2 feed)
  • RunWorkerTests.cs: Unit tests for the XML patching logic covering various config scenarios

Testing

  • 11 unit tests for AddInsecureConnectionsAttribute covering https sources, http sources, local paths, existing attributes, multiple sources, package source mappings, credentials, XML declarations, and other config sections
  • 1 end-to-end test verifying both SDK and packages.config projects can update from insecure HTTP feeds

@brettfo brettfo requested a review from a team as a code owner May 20, 2026 22:28
Copilot AI review requested due to automatic review settings May 20, 2026 22:28
@github-actions github-actions Bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the NuGet helper (NuGetUpdater) to automatically patch NuGet.Config files at runtime so that any http:// package sources get allowInsecureConnections="true" added before update scenarios run, enabling restores from insecure HTTP feeds without requiring users to modify their checked-in config.

Changes:

  • Adds a pre-handler step in RunWorker to scan for NuGet.Config files and patch http:// sources with allowInsecureConnections="true".
  • Extends the test HTTP server with a simple NuGet V2 (OData/Atom) feed implementation to support packages.config scenarios.
  • Adds unit tests for the XML patching logic and an end-to-end test covering mixed SDK-style + packages.config projects using insecure HTTP feeds.
Show a summary per file
File Description
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs Adds NuGet.Config patching logic and runs it before scenario handlers.
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestHttpServer.cs Adds a V2 NuGet feed factory used by new end-to-end coverage.
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs Adds unit tests validating the NuGet.Config patching behavior.
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/EndToEndTests.InsecureHttpFeed.cs Adds an end-to-end test ensuring updates work with insecure HTTP feeds across project types.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 4

Comment thread nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs Outdated
Comment thread nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs Outdated
Comment thread nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs Outdated
@brettfo brettfo force-pushed the brettfo/nuget-insecure-http-feed-patching branch from e883194 to f59ccda Compare May 20, 2026 23:07
return jobFile;
}

internal static string AddInsecureConnectionsAttribute(string nugetConfigContents)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just making sure, this doesn't actually get added in the resulting PR right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct, we never submit a nuget.config file in the PR. In fact, there is internal code to explicitly reject PR creation if anything other than csproj/props/targets/packages.config (and a handful of others) are modified.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The very bottom of the end-to-end test shows that only the appropriate files are edited and not nuget.config.

Add allowInsecureConnections=true to http:// package sources in NuGet.Config
files before running update scenarios. This allows Dependabot to restore
packages from insecure HTTP feeds without requiring the attribute in the
original config.

- Add AddInsecureConnectionsAttribute to RunWorker for XML patching
- Add PatchNuGetConfigFilesAsync to scan and patch all config files
- Add V2 feed support to TestHttpServer
- Add end-to-end test with mixed SDK/packages.config projects
- Add unit tests for the XML patching logic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brettfo brettfo force-pushed the brettfo/nuget-insecure-http-feed-patching branch from f59ccda to 8773f99 Compare May 21, 2026 21:33
@brettfo brettfo merged commit 9a11ae8 into main May 21, 2026
139 of 140 checks passed
@brettfo brettfo deleted the brettfo/nuget-insecure-http-feed-patching branch May 21, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: dotnet:nuget NuGet packages via nuget or dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants