TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

HTTPS website+API, confusion about best practices?

5 点作者 epimetheus2超过 3 年前
Let&#x27;s say we have a site www.coolstore.com that accesses api.coolstore.com<p>What is the best practice and possible attack vectors when not sticking to them?<p>It seems that www.coolstore.com should be under https:&#x2F;&#x2F;www.coolstore.com. What about assets? Let&#x27;s say we force a redirect to https:&#x2F;&#x2F; on the site itself, but not on assets. e.g. you copy the request and change it to http you can access some javascript files. Would that be a problem?<p>How about API ? Is it neccesary that also api.coolstore.com requires https, even though it&#x27;s only used by the website? Should it have http:&#x2F;&#x2F; completely turned off?<p>Is there some manual of best practices with deploying react site + api ?

3 条评论

emteycz超过 3 年前
<i>Everything</i> (including links to external sites) should be on HTTPS. Browsers will error if you try to load JS assets from HTTP on a HTTPS site.<p>Don&#x27;t use HTTP for API even if you could. Usually servers will return status 301 (client-side redirect) directed to the same URL but using HTTPS to any HTTP request.<p>Don&#x27;t mix hostnames - do coolstore.com&#x2F;api instead - that frees you from cross-origin security issues.
评论 #29381965 未加载
codegeek超过 3 年前
Any public facing URL should have https (SSL certificate installed) and any http request should always redirect to https. There is such thing called &quot;SSL Termination&quot; where you may have a public facing load balancer&#x2F;proxy which works on https but terminates SSL which means that any upstream backend servers under that load balancer are http only (but are not publicly available).<p>Whether you have api.coolstore.com or not, that is more of a design decision. It is a common practice to setup website and API separate where API is hosted on subdomain. So you could do coolstore.com and api.coolstore.com but install https on both and setup http-&gt;https redirect to both.
theandrewbailey超过 3 年前
HTTP to HTTPS (and vice-versa), even on the same (sub-)domain, is automatically considered cross-origin. This restricts what HTTPS-loaded Javascript and API calls can do on an HTTP-loaded page. Having everything HTTPS from the beginning will cause less issues in the long run.<p>It&#x27;s conceivable that at some point every resource loaded on an HTTPS page will require HTTPS, too.<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;Security&#x2F;Same-origin_policy" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;Security&#x2F;Same-o...</a>