HSTS support for windows based Azure app service

Mukesh Kumar 0 Reputation points Microsoft Employee
2024-03-11T05:18:14.6466667+00:00

we are using a windows based azure app service and currently we are looking for remediation our webapp concerning security.

I approached to resolve concerning security by

  1. Redirect http to https through Azure web app setting.
  2. Set HSTS options at our service startup as c# code snippet.

services.AddHsts(options =>

{

options.Preload = true;

options.IncludeSubDomains = true;

options.MaxAge = TimeSpan.FromDays(365);

});

Seems like solution is not enough, is there any other recommended solution require to implement? or is it the app service the wrong place implemented?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,971 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. brtrach-MSFT 17,741 Reputation points Microsoft Employee Moderator
    2024-03-12T04:12:38.18+00:00

    @Mukesh Kumar Can you share what your URL redirect rule looks like? It should look similar to this:

    <rule name="RedirectToHTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
    </rule>
    
    
    

    Your HSTS settings should look like:

    <configuration>  
     <system.webServer>
      <rewrite>
        <outboundRules>
          <rule name="Add Strict-Transport-Security only when using HTTPS" enabled="true">
            <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
            <conditions>
              <add input="{HTTPS}" pattern="on" ignoreCase="true" />
            </conditions>
            <action type="Rewrite" value="max-age=31536000; includeSubdomains; preload" />
          </rule>
        </outboundRules>
      </rewrite>
    </system.webServer>
    </configuration>
    

    You can validate the HSTS behavior by navigating to edge://net-internals/#hsts Enter your domain name and check if you have the following attributes set. image.png

    Can you please check on the above to ensure they are properly configured? We look forward to your reply.

    0 comments No comments

  2. brajeshrajput 0 Reputation points
    2024-10-22T11:16:56.1366667+00:00

    HSTS working with windows based Azure app service but not working with linux based azure app service.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.