Skip to content

Limit credentials to the origin host - #28399

Open
Justin Chung (jshigetomi) wants to merge 2 commits into
PowerShell:masterfrom
jshigetomi:240bp
Open

Justin Chung (jshigetomi) wants to merge 2 commits into
PowerShell:masterfrom
jshigetomi:240bp

Conversation

@jshigetomi

@jshigetomi Justin Chung (jshigetomi) commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

PR Summary

PR Context

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Existing files retain their copyright headers
  • This PR is ready to merge
  • Breaking changes
    • None
  • User-facing changes
    • Not Applicable
  • Testing - New and feature
    • Added tests for the changed behavior

@jshigetomi
Justin Chung (jshigetomi) requested a review from a team as a code owner November 11, 2026 19:12
Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:12
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@jshigetomi Justin Chung (jshigetomi) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 11, 2026

Copilot AI left a comment

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.

🟡 Changes recommended

Reused web sessions retain default credentials after UseDefaultCredentials is disabled, while credential-cache handling also causes redirect-authentication and connection-reuse regressions.

3 open issues
What changed in this PR

This PR hardens credential handling in PowerShell’s web cmdlets by scoping credentials to the request origin unless redirect authorization preservation is enabled.

Changes:

  • Adds origin-scoped credential caches with authentication-scheme handling for explicit and default credentials.
  • Updates shared session preparation to use the new credential handling.
  • Expands both web cmdlets’ tests to check credential lookup across hosts, preservation settings, and URLs without a scheme.
File Description
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​WebCmdlets.Tests.ps1 Expands credential-scoping tests for both web cmdlets.
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​WebCmdlet/​WebRequestSession.cs Adds origin-scoped credential cache creation.
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​WebCmdlet/​Common/​WebRequestPSCmdlet.Common.cs Routes explicit and default credentials through the new session helper.

Review effort: Balanced

else if (UseDefaultCredentials)
{
WebSession.UseDefaultCredentials = true;
WebSession.SetCredential(CredentialCache.DefaultNetworkCredentials, CheckProtocol(Uri), PreserveAuthorizationOnRedirect);
// Get the relevant NetworkCredential
NetworkCredential netCred = Credential.GetNetworkCredential();
WebSession.Credentials = netCred;
WebSession.SetCredential(Credential.GetNetworkCredential(), CheckProtocol(Uri), PreserveAuthorizationOnRedirect);
cache.Add(origin, scheme, cred);
}

Credentials = cache;
@jshigetomi Justin Chung (jshigetomi) changed the title Protect credentials by limiting them to the origin host Limit credentials to the origin host Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants