Skip to content

Add warning to web cmdlets if it defaults to HTTP #19316

Closed

Description

@CarloToso

Summary of the new feature / enhancement

In WebRequestPSCmdlet.Common.cs line 1399 if we provide a -Uri with no scheme it defaults to http, is this the desired behaviour in 2023? Discussed with Ilya (@iSazonov) in #19162 comments

        private static Uri CheckProtocol(Uri uri)
        {
            ArgumentNullException.ThrowIfNull(uri);

            return uri.IsAbsoluteUri ? uri : new Uri("http://" + uri.OriginalString);
        }

Test:

$x = Invoke-WebRequest google.com
$x.BaseResponse.RequestMessage.RequestUri.Scheme
#--> http

Proposed technical implementation details (optional)

http --> https

Activity

  1. added
    Issue-Enhancementthe issue is more of a feature request than a bug
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Mar 13, 2023
  2. iSazonov commented on Mar 13, 2023

    @iSazonov
    Collaborator

    HTTPS is preferred as default in modern world.
    But it can be a breaking change.
    Perhaps we could try HTTPS first and then HTTP - since the user didn't specify the exact protocol, this is probably acceptable, but I'd prefer not to.

  3. jhoneill commented on Mar 13, 2023

    @jhoneill

    HTTPS is preferred as default in modern world. But it can be a breaking change. Perhaps we could try HTTPS first and then HTTP - since the user didn't specify the exact protocol, this is probably acceptable, but I'd prefer not to.

    We have conflict between modern world assumptions and things that existing scripts may rely on, so I think there must be a fall back to http to avoid breaking scripts.

    Even then a new script for a server which does not allow http which relies on the assumption of https would work on updated PowerShell and fail on older versions (e.g. Windows PowerShell). Documentation must be very clear that the behaviour has changed and if you require https AND can't rely on the script running on a recent version then you must specify it explicitly.

    I'll bring this to the cmdlets working group and see what the view is.

  4. iSazonov commented on Mar 14, 2023

    @iSazonov
    Collaborator

    We have conflict between modern world assumptions and things that existing scripts may rely on, so I think there must be a fall back to http to avoid breaking scripts.

    I suppose that specifying a URL without a protocol is too careless and it is very unlikely that someone does that in a working script, rather only on the command line which is not critical. Then we can conclude that switching from HTTPS to HTTP is unnecessary, even harmful.

  5. jhoneill commented on Mar 14, 2023

    @jhoneill

    We have conflict between modern world assumptions and things that existing scripts may rely on, so I think there must be a fall back to http to avoid breaking scripts.

    I suppose that specifying a URL without a protocol is too careless and it is very unlikely that someone does that in a working script, rather only on the command line which is not critical. Then we can conclude that switching from HTTPS to HTTP is unnecessary, even harmful.

    I'm not sure what is safe to conclude.
    Generally if something can be called in a particular way someone, somewhere will call it that way.
    It's good practice to write http or https explicitly and everyone SHOULD do that, but not everyone WILL.
    If the service supports https and http then using https is preferable.
    But if the service doesn't support https, then (a) should the command line short cut stop working? and (b) is it acceptable to break the small number of scripts that contain that shortcut ?
    I think the answer to both is no, and the expectation is things work like browsers work - try https first and only if that fails try http. (There should probably be a warning message if the non secure version is used but not explicitly specified).

  6. iSazonov commented on Mar 14, 2023

    @iSazonov
    Collaborator

    There is a security aspect to this fallback. As long as the default is HTTP this is not an issue, but if the default is HTTPS and we add a fallback to HTTP, then there is a security issue.
    So it must either be rejected altogether or be bound to the AllowInsecureRedirect parameter, or it must be approved by the WG-Security.
    But it all looks unnecessarily complicated.

    I wouldn't overcomplicate it, just make HTTPS the default and expect feedback. If users do run into a problem, but then we will have more information to make things more right.

  7. SteveL-MSFT commented on Mar 15, 2023

    @SteveL-MSFT
    Member

    @PowerShell/wg-powershell-cmdlets reviewed this and concerned about the impact of a breaking change. We looked at curl as a precedent and they also default to http. We suggest adding a warning message if no scheme is specified and HTTP is being used.

  8. changed the title [-]Should Invoke-WebRequest default to http or https?[/-] [+]Add warning to web cmdlets if it defaults to HTTP[/+] on Mar 15, 2023
  9. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    on Mar 15, 2023
  10. ghost added
    In-PRIndicates that a PR is out for the issue
    on Mar 15, 2023
  11. iSazonov commented on Mar 16, 2023

    @iSazonov
    Collaborator

    curl has very old history and it is unlikely that they will change anything there.

  12. jhoneill commented on Mar 22, 2023

    @jhoneill

    rhubarb-geek-nz one could. However that would break existing scripts.

  13. 3 remaining items

  14. jhoneill commented on Apr 14, 2023

    @jhoneill

    CarloToso I think that change of plan needs wider discussion, it was set as up for grabs because

    • When the cmdlets were added to Windows PowerShell (IIRC in V3) browsers still defaulted to HTTP instead of HTTPS and user expectation was a "naked" URL was HTTP
    • Today that expectation has changed and a naked URL is expected to be HTTPS
    • Changing the behaviour of the cmdlets to be HTTPS only for naked URLS will break existing scripts which talk to HTTP only services.
    • Changing the behaviour to try HTTPS and fall back to HTTP if it fails is a possible security issue (I think solvable with warnings, others disagree)
    • There is a precedent for breaking these commands for security, URLs are no longer printed in verbose / debug message making debugging harder in order to avoid leaks of info contained as parameters in a URI.

    Therefore a warning that says "you didn't specify http or https, so for legacy reasons I'm using http even though the server might support https" was seen as the best solution.
    It could break a script which runs with -warningAction stop but that's rare and unlikely to combine with a naked URL.
    Annoying people who don't write their URLs properly was understood when it was set as up for grabs.

  15. iSazonov commented on Apr 14, 2023

    @iSazonov
    Collaborator
    • Changing the behaviour of the cmdlets to be HTTPS only for naked URLS will break existing scripts which talk to HTTP only services.

    Can you demonstrate such scripts?

  16. jhoneill commented on Apr 15, 2023

    @jhoneill
    • Changing the behaviour of the cmdlets to be HTTPS only for naked URLS will break existing scripts which talk to HTTP only services.

    Can you demonstrate such scripts?

    I have seen them at 2 of the last 3 clients. My last long contract included enabling HTTPS on a bunch of internal servers and the about half the places I needed to change http to https and half I was adding https where there had been nothing. 2 clients before that had some of the oddest PowerShell I've ever seen (their main scripter had never heard of "if" and used switch for everything) They included server names as constants at the start of some scripts sometimes they would build a unc as a "\$name\path" and sometimes a url as "$name/api_path", some cases did have http:// in them, others didn't

    I wrote this https://github.com/jhoneill/OctopusTools/blob/main/Public/Connect-Octopus.ps1 on the recent engagement, and if the user supplies the URL as a command line parameter without the http, I don't add it. I'm fairly sure the octopus servers still didn't support https when I finished so a CI/CD pipeline which uses my code where someone has specified the server name instead of a URL would break.

    I've said before I believe in the original formulation of Murphy's law "If it can be done wrongly, sooner or later someone will do it wrongly". The same is true for APIs (and command lines are APIs), if you allow something to be used in some fashion, someone will come to depend on its continued working in that fashion.
    The view that this only breaks things for people whose practices were sloppy (omitting the protocol is sloppy) therefore it's OK, is dangerous. It sends the message that if the powers that be don't like how you write code they can break your past work, and therefore upgrades carry a risk, so staying on Windows PowerShell 5 forever is the smart thing to do - I have seen aversion to upgrading in many organisations over a long career.

    GitHub
    Work in progress: PowerShell bits for Octopus deploy - OctopusTools/Connect-Octopus.ps1 at main · jhoneill/OctopusTools
  17. iSazonov commented on Apr 15, 2023

    @iSazonov
    Collaborator

    My question was very specific. A better answer would be to give examples of popular apps that would stop working, it would be hard to fix, it would degrade the UX, etc.
    Right now all we have are statements of concern.

    We were in the same situation when the question arose about changing the default encoding to Utf8 in pwsh. The situation was even more uncertain. What did we do? We released a preview and then a release version afterwards. It was the only way to move forward with the uncertainty.
    The uncertainty of this issue is much less and the scope is much smaller since it only affects a couple of cmdlets. And I see no reason why we can't release a preview with this change. Name them if you know the specific reasons but not the general reasoning.

    Another very strange point is that the concern expressed is about scripts (sloppy in nature), but not about the more obvious danger when the user uses these cmdlets in an interactive session and could leak credentials and other sensitive information. Obviously, we all often omit http/https when typing in the console. Then why shouldn't these cmdlets work in a secure way like their big brothers?

  18. jhoneill commented on Apr 16, 2023

    @jhoneill

    Ilya (@iSazonov) "Right now all we have are statements of concern." Well yes.

    Do we have any numbers for how many internal servers support / don't support HTTPS? I don't think so. Do we know how many scripts call http (only) services on those ? Doubt it. And of those scripts how many are sloppily written without the protocol. Complete unknown.

    What I can tell you is I have worked in places where, if the default changed, they would either need to get their act together and ensure all services could be accessed over https OR they must review every script which uses these cmdlets to (1) ensure that everywhere any parameter passed in is checked and their script adds http if it is not specified, and (2) fix hard-coded urls OR Simply not deploy the version concerned. Realistically they have enough other work to do that they will simply not deploy. You would put me in the position of telling my clients not to deploy releases after X.

    As for UTF-8 - if there are text files which are written with codepage 1252 - which is what PowerShell 5 assumes with files without a byte-order-mark, which a script needs to read, or other tools which read correctly if the file is UTF-16 but assume another code page with no bom , then it is possible to set encoding as a parameter default and work around the problem.
    Working round the problem being a parameter which has become necessary is easy; working round a parameter that has become wrong needs a Proxy function to be deployed which fixes them.

    The reason for printing a warning was precisely to say to sloppy cmdline users "hey if you're going through an insecure network to a server that supports https, don't write it like that". curl doesn't work in a secure way and the model is to provide native functionality which is like curl (which is now pre-installed on Windows) . If users find this annoying which was the reason cited for not giving a warning, they can set a default parameter for warningaction in these cmdlets.

    As Steve posted above the cmdlets wg decided that a warning was the least bad of a set of imperfect choices. It was not appropriate for CarloToso to change this back to "not planned" without at least asking the steve or the wg to reconsider.

  19. microsoft-github-policy-service commented on Nov 15, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  20. microsoft-github-policy-service commented on Nov 15, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  21. microsoft-github-policy-service commented on Nov 15, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  22. microsoft-github-policy-service commented on Nov 22, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions