Skip to content

Clear session authorization headers on redirect retries - #28398

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

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

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
    • N/A or can only be tested interactively

@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

Redirect handling permanently removes Authorization from a caller-supplied web session, breaking later requests that reuse it, and regression coverage for redirected retries is missing.

2 open issues
What changed in this PR

This PR hardens redirect retries in the shared web cmdlet implementation by preventing reuse of session-level authorization unless explicitly preserved.

Changes:

  • Removes Authorization from both session headers and redirected requests when -PreserveAuthorizationOnRedirect is disabled.
  • Runs this cleanup even when the redirected request already lacks the header.
File Description
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​WebCmdlet/​Common/​WebRequestPSCmdlet.Common.cs Extends redirect authorization cleanup to session headers used when rebuilding requests for retries.

Review effort: Balanced

if (isRedirect && !PreserveAuthorizationOnRedirect && request.Headers.Contains(HttpKnownHeaderNames.Authorization))
if (isRedirect && !PreserveAuthorizationOnRedirect)
{
WebSession?.Headers?.Remove(HttpKnownHeaderNames.Authorization);
if (isRedirect && !PreserveAuthorizationOnRedirect && request.Headers.Contains(HttpKnownHeaderNames.Authorization))
if (isRedirect && !PreserveAuthorizationOnRedirect)
{
WebSession?.Headers?.Remove(HttpKnownHeaderNames.Authorization);
@jshigetomi Justin Chung (jshigetomi) changed the title Protect redirected requests by clearing session authorization headers Clear session authorization headers on redirect retries 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