-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Webcmdlets display an error on https to http redirect #18595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webcmdlets display an error on https to http redirect #18595
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a behavior of other utils in the scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also text in WebCmdletStrings.InsecureRedirection assumes we should throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add new test.
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
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).