What is the “Upgrade-Insecure-Requests” HTTP header?

前端 未结 2 1924
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 10:30

I made a POST request to a HTTP (non-HTTPS) site, inspected the request in Chrome\'s Developer Tools, and found that it added its own header before sending it to the server:

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 11:19

    Short answer: it's closely related to the Content-Security-Policy: upgrade-insecure-requests response header, indicating that the browser supports it (and in fact prefers it).

    It took me 30mins of Googling, but I finally found it buried in the W3 spec.

    The confusion comes because the header in the spec was HTTPS: 1, and this is how Chromium implemented it, but after this broke lots of websites that were poorly coded (particularly WordPress and WooCommerce) the Chromium team apologized:

    "I apologize for the breakage; I apparently underestimated the impact based on the feedback during dev and beta."
    — Mike West, in Chrome Issue 501842

    Their fix was to rename it to Upgrade-Insecure-Requests: 1, and the spec has since been updated to match.

    Anyway, here is the explanation from the W3 spec (as it appeared at the time)...

    The HTTPS HTTP request header field sends a signal to the server expressing the client’s preference for an encrypted and authenticated response, and that it can successfully handle the upgrade-insecure-requests directive in order to make that preference as seamless as possible to provide.

    ...

    When a server encounters this preference in an HTTP request’s headers, it SHOULD redirect the user to a potentially secure representation of the resource being requested.

    When a server encounters this preference in an HTTPS request’s headers, it SHOULD include a Strict-Transport-Security header in the response if the request’s host is HSTS-safe or conditionally HSTS-safe [RFC6797].

提交回复
热议问题