如何仅对identityserver4强制执行Https-only请求



我已在Azure应用程序服务上配置并部署了IdentityServer4,我已使用自定义SSL证书对令牌进行签名。一切都很好,但我想强制身份服务器只接收来自https客户端的请求,否则会抛出错误。

我在identityserver4上阅读了这部分文档(http://docs.identityserver.io/en/latest/topics/crypto.html?highlight=HTTPS)他们说:">我们不强制使用HTTPS,但对于生产,每次与IdentityServer的交互都必须使用HTTPS。">

只是想知道是否可以只强制https客户端请求。

非常感谢任何帮助或指示

这通常是您在web服务器/流量管理器级别而不是应用程序级别配置的内容(当然,您也可以使用应用程序逻辑来强制执行它(。

这应该是有用的:https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-custom-ssl

还要查看HSTS标题:https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet

还可以考虑使用强大的内容安全策略来阻止或升级不安全的资源请求。例如Content-Security-Policy: upgrade-insecure-requests; block-all-mixed-content;退房https://report-uri.com/home/generate和https://scotthelme.co.uk/csp-cheat-sheet/

您可以在Startup类的Configure方法中使用以下调用来强制执行HSTS标头和HTTPS重定向。

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//...
app.UseHsts();
app.UseHttpsRedirection();
//...
}

有关所有配置选项和最佳实践,请参阅此链接:https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl

最新更新