Webcmdlets display an error on https to http redirect#18595
Webcmdlets display an error on https to http redirect#18595iSazonov merged 13 commits intoPowerShell:masterfrom
Conversation
src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx
Outdated
Show resolved
Hide resolved
| { | ||
| ErrorRecord er = new(new InvalidOperationException(), "InsecureRedirection", ErrorCategory.InvalidOperation, request); | ||
| er.ErrorDetails = new ErrorDetails(WebCmdletStrings.InsecureRedirection); | ||
| WriteError(er); |
There was a problem hiding this comment.
Shouldn't this be a terminating error here? There doesn't seem to be any point in continuing and we should throw ThrowTerminatingError() here.
There was a problem hiding this comment.
I used WriteError() to mirror the behaviour of lines 1604-1609:
if (WebSession.MaximumRedirection == 0 && IsRedirectCode(response.StatusCode)) // Indicate "HttpClientHandler.AllowAutoRedirect == false"
{
ErrorRecord er = new(new InvalidOperationException(), "MaximumRedirectExceeded", ErrorCategory.InvalidOperation, request);
er.ErrorDetails = new ErrorDetails(WebCmdletStrings.MaximumRedirectionCountExceeded);
WriteError(er);
}I can change it if needed.
There was a problem hiding this comment.
What is a behavior of other utils in the scenario?
There was a problem hiding this comment.
Also text in WebCmdletStrings.InsecureRedirection assumes we should throw.
There was a problem hiding this comment.
Test:
Invoke-WebRequest "https://mockbin.org/redirect/308?to=https://mockbin.org/redirect/302?to=http://mockbin.org/status/200" -SkipHttpErrorCheck --> 302
curl -L "https://mockbin.org/redirect/308?to=https://mockbin.org/redirect/302?to=http://mockbin.org/status/200" --> 200
(HttpClient does not seem to allow insecure redirect: dotnet/runtime#23801)
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@CarloToso Please add tests. |
|
@iSazonov I'm working on the tests. |
|
@CarloToso We could add tests in #18546 after current PR will be merged. |
|
@iSazonov I think we can merge |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@SteveL-MSFT can we merge this? |
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
🎉 Handy links: |
Hrmm, this breaks every IRM across any insecure (corporate|zero-trust) proxies by making Script modules are now completely broken if there is a insecure proxy. Wouldn't that make this a breaking change? Is there an easier way?
|
|
@crlogic Could you please open an issue to discuss this? |
PR Summary
At the moment https to http redirect fail silently, after this PR it will show an error.
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).