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

前端 未结 2 1926
伪装坚强ぢ
伪装坚强ぢ 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:01

    This explains the whole thing:

    The HTTP Content-Security-Policy (CSP) upgrade-insecure-requests directive instructs user agents to treat all of a site's insecure URLs (those served over HTTP) as though they have been replaced with secure URLs (those served over HTTPS). This directive is intended for web sites with large numbers of insecure legacy URLs that need to be rewritten.

    The upgrade-insecure-requests directive is evaluated before block-all-mixed-content and if it is set, the latter is effectively a no-op. It is recommended to set one directive or the other, but not both.

    The upgrade-insecure-requests directive will not ensure that users visiting your site via links on third-party sites will be upgraded to HTTPS for the top-level navigation and thus does not replace the Strict-Transport-Security (HSTS) header, which should still be set with an appropriate max-age to ensure that users are not subject to SSL stripping attacks.

    Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/upgrade-insecure-requests

提交回复
热议问题