Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#3566) Avoid credential bleed from saved sources with the same hostname #3572

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

corbob
Copy link
Member

@corbob corbob commented Nov 22, 2024

Description Of Changes

Backport #3568 to Chocolatey CLI 1.x

Motivation and Context

See #3566 - the credentials are being reused in places that they shouldn't.

Testing

Ran through Test Kitchen locally and in Team City.

To test with CLE locally I editted the nupkg produced by Team City and changed the version reported to be 1.5.0-pullreques and then tested with CLE 5.0.6.

Screenshot from local test kitchen run:

image

Operating Systems Testing

  • Windows Server 2019
  • Windows Server 2016

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

@corbob corbob force-pushed the source-auth-1.x branch 2 times, most recently from 658b4e7 to 54b7bee Compare November 25, 2024 17:43
The ExplicitSources property is used when looking up credentials. This
backports this property from 2.x to 1.x.
@corbob corbob marked this pull request as ready for review November 25, 2024 19:59
@corbob corbob changed the title WIP: Auth fixes for 1.x (#3566) Avoid credential bleed from saved sources with the same hostname Nov 25, 2024
Copy link
Member

@vexx32 vexx32 left a comment

Choose a reason for hiding this comment

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

LGTM! One small comment. About a comment.

Previously we looked up any available sources in the config by the
hostname, before falling back to trying an exact match if we had
collisions.

This still allowed credentials to be reused in situations where we don't
actually know if they're applicable; many repository servers will
support different credentials for individual repositories, so we cannot
and should not assume that credentials for one repository will actually
match another repository, nor that users want the credentials to be
shared for both.

It also led to the possibility of users storing one repository first,
and then later specifying a different repository on the same server, and
choco would try to use the stored credentials for the first repository
for the explicitly-entered URL which is nowhere in config.

Instead, we should only match the whole URL (which can be done with
Uri. Equals to ensure that we match hostnames case-insensitively, but
routes case-sensitively), and expect users to provide credentials if
they provide a URL that is not explicitly in the sources.

Additionally, we try to ensure that if a user has named a specific
source, rather than themselves providing a URL at the command line, we
prioritise finding that in the already-configured sources and use that
source if the URL matches the current URL that NuGet requires a
credential for.
Comment on lines 7 to 8
[Parameter()]
[switch]$All
Copy link
Member

Choose a reason for hiding this comment

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

This was removed in the other PR, so should also be removed here, right?

@@ -0,0 +1,66 @@
Describe 'Ensuring credentials do not bleed from configured sources' -Tag CredentialProvider -ForEach @(
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here, as per the other PR. I think we need more words here as to what this test is doing, and why the asserts are set the way that they are.

Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

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

Couple things here that I think needs to be addressed.

Add Pester tests to ensure we don't inadvertently bleed configured
credentials into scenarios where they should not be used.
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

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

LGTM!

@vexx32 vexx32 merged commit a71108c into chocolatey:hotfix/1.4.1 Nov 26, 2024
5 checks passed
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.

Credentials from configured source used for a non-configured source when the URL is similar
3 participants