HSTS和使用Javascript访问子域

HSTS and access to subdomain with Javascript

本文关键字:访问 Javascript HSTS      更新时间:2023-09-26

几周前,我将主页仅移动到https,并启用了HSTS。在一个页面上,我有一些JavaScript代码,它们通过http请求从子域中获取内容。在启用https之前,它运行良好。我还在javascript代码中将http协议更改为https。但这并不是一个解决方案。

HTTPS是限制对子域的访问,还是HSTS?

有没有办法允许访问子域?

这是JavaScript代码:

<script type="text/javascript" src="/jquery-1.11.0.min.js"></script>
<script>
$("#ipv4").show().load('https://ipv4.mydomain.com/myip/'
, {limit: 25}, 
  function (responseText, textStatus, req) {
    if (textStatus == "error") {
      $("#ipv4").html("Kein IPv4");
    }
  }
);
$("#ipv6").show().load('https://ipv6.mydomain.com/myip/'
, {limit: 25}, 
  function (responseText, textStatus, req) {
    if (textStatus == "error") {
      $("#ipv6").html("Kein IPv6");
    }
  }
);
</script>

这是HSTS标题:

Strict-Transport-Security: max-age=31556926; includeSubDomains; preload

HSTS的唯一作用是在发送http请求之前将其重写为https。

因此,您的子域必须响应https请求才能工作。