You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adjust logic of Web Cmdlet Authorization Header Stripping to work with .NET Core 2.1 #6728
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.
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
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.
@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.
Activity
markekraus commentedon Apr 29, 2018
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:
SteveL-MSFT commentedon Apr 30, 2018
Mark Kraus (@markekraus) is the test result implying that on a redirect a GET turns into a POST and vice versa?
markekraus commentedon Apr 30, 2018
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.
AmbiguousandMultipleChoicesshould 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.RedirectKeepVerbandTemporaryRedirectshould 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.
markekraus commentedon Apr 30, 2018
SteveL-MSFT commentedon Apr 30, 2018
@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.
Fix Web Cmdlets for .NET Core 2.1 (#6806)
Fix Web Cmdlets for .NET Core 2.1 (PowerShell#6806)