Skip to content

Adjust logic of Web Cmdlet Authorization Header Stripping to work with .NET Core 2.1 #6728

Closed

Description

Re #6718 #6632

In dotnet/corefx#26864 the Authorization header is now stripped on redirect. This means that the logic we currently have in place to handle this and to bypass is now reversed. We need to update the logic of the web cmdlets to manually handle redirection when -PreserveAuthorizationOnRedirect is supplied and an Authorization request header is present. Currently, they are doing the exact opposite.

Activity

  1. markekraus commented on Apr 29, 2018

    @markekraus
    ContributorAuthor

    I'm making decent progress on this

    https://github.com/iSazonov/PowerShell/compare/move-to-netcore210preview2...markekraus:Dotnet2.1?expand=1

    There are some authorization related test failing that don't seem to be related to this... seems there is another behavior change to look into:

        [-] Validates Invoke-WebRequest strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'MultipleChoices' 'POST' 79ms
          Expected strings to be the same, but they were different.
          Expected length: 4
          Actual length:   3
          Strings differ at index 0.
          Expected: 'POST'
          But was:  'GET'
          -----------^
          824:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 824
        [-] Validates Invoke-WebRequest strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'Ambiguous' 'POST' 86ms
          Expected strings to be the same, but they were different.
          Expected length: 4
          Actual length:   3
          Strings differ at index 0.
          Expected: 'POST'
          But was:  'GET'
          -----------^
          824:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 824
        [-] Validates Invoke-WebRequest strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'TemporaryRedirect' 'GET' 28ms
          Expected strings to be the same, but they were different.
          Expected length: 3
          Actual length:   4
          Strings differ at index 0.
          Expected: 'GET'
          But was:  'POST'
          -----------^
          824:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 824
        [-] Validates Invoke-WebRequest strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'RedirectKeepVerb' 'GET' 36ms
          Expected strings to be the same, but they were different.
          Expected length: 3
          Actual length:   4
          Strings differ at index 0.
          Expected: 'GET'
          But was:  'POST'
          -----------^
          824:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 824
        [-] Validates Invoke-RestMethod strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'MultipleChoices' 'POST' 24ms
          Expected strings to be the same, but they were different.
          Expected length: 4
          Actual length:   3
          Strings differ at index 0.
          Expected: 'POST'
          But was:  'GET'
          -----------^
          2161:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 2161
        [-] Validates Invoke-RestMethod strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'Ambiguous' 'POST' 42ms
          Expected strings to be the same, but they were different.
          Expected length: 4
          Actual length:   3
          Strings differ at index 0.
          Expected: 'POST'
          But was:  'GET'
          -----------^
          2161:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 2161
        [-] Validates Invoke-RestMethod strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'TemporaryRedirect' 'GET' 28ms
          Expected strings to be the same, but they were different.
          Expected length: 3
          Actual length:   4
          Strings differ at index 0.
          Expected: 'GET'
          But was:  'POST'
          -----------^
          2161:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 2161
        [-] Validates Invoke-RestMethod strips the authorization header redirects and switches from POST to GET when it handles the redirect: 'RedirectKeepVerb' 'GET' 34ms
          Expected strings to be the same, but they were different.
          Expected length: 3
          Actual length:   4
          Strings differ at index 0.
          Expected: 'GET'
          But was:  'POST'
          -----------^
          2161:         $response.Content.Method | Should -Be $redirectedMethod
          at <ScriptBlock>, C:\Git\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Utility\WebCmdlets.Tests.ps1: line 2161
    
  2. SteveL-MSFT commented on Apr 30, 2018

    @SteveL-MSFT
    Member

    Mark Kraus (@markekraus) is the test result implying that on a redirect a GET turns into a POST and vice versa?

  3. markekraus commented on Apr 30, 2018

    @markekraus
    ContributorAuthor

    Steve Lee (@SteveL-MSFT) It looks like we originally shipped some incorrect behavior. This was only exposed when I let HttpClient handle the redirects as the existing tests were now testing HttpClient's redirection behavior and not our own code paths.

    Ambiguous and MultipleChoices should redirect POST requests as GET. I verified this behavior in 5.1's HttpClient. We were letting those pass through POST when stripping authorization headers.

    RedirectKeepVerb and TemporaryRedirect should redirect POST requests as POST (that should be obvious from the name KeepVerb). We were changing these to GET when stripping authorization headers.

    The problem is that we didn't have tests for both scenarios (keep authorization and strip authorization). It makes sense that we didn't have tests for keeping the authorization header since we were not using our own code paths for redirection. However, without testing both ways, we didn't catch the difference in behavior between the two modes.

    I guess fixing this is technically a breaking change... Can you flag this for review?

    I pushed a new commit which fixes all of these and ensures we have tests in both keeping and stripping authorization. It finally passes all of the Web Cmdlets tests.

  4. added
    Breaking-Change
    Review - Committee
    Committee-Reviewed
    and removed
    Review - Committee
    on Apr 30, 2018
  5. SteveL-MSFT commented on Apr 30, 2018

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this and agrees with the breaking change to get back to correct behavior. This is really a bug fix that has an unfortunate breaking change from 6.0.

  6. added a commit that references this issue on May 14, 2018
    525f593
  7. added a commit that references this issue on Aug 6, 2026
    ce2e711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Breaking-ChangeCommittee-ReviewedResolution-FixedWG-Cmdlets

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions