Hello Sean Ronan,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
I understand that you have deployed a .NET Core 6.0 MVC website to an Azure App Service with both production and staging deployment slots and you are experiencing an issue where the HTTP Strict Transport Security (HSTS) header appears in the staging slot but is missing in the production slot.
Solution
Regarding your scenario and information provided, to solve the issue of the missing HSTS header on the production slot of your Azure App Service while it appears on the staging slot, you will need to examine the following steps because the reason could be due to several factors.
- Sometimes, the configuration related to custom domains and certificates can affect the headers. Verify that there are no settings or restrictions in the custom domain configuration that could be interfering with the HSTS header. Steps to Check Custom Domain Configuration:
- Go to the Azure Portal.
- Navigate to your App Service.
- Under "Settings," select "Custom domains."
- Verify the custom domain settings and ensure there are no rules or configurations that might prevent the HSTS header from being applied. Link: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-custom-domain
- It's possible that there are differences in the
web.config
files between the staging and production slots. Although unlikely, but it is advisable to double-check that theweb.config
file deployed to both slots is indeed identical, especially the sections related to headers and security settings. The below is a revisedweb.config
snippet to ensure proper HSTS header handling:
Link1: https://learn.microsoft.com/en-us/azure/app-service/configure-common Link2: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-get-started-dotnet<configuration> <system.webServer> <security> <requestFiltering removeServerHeader="true" /> </security> <rewrite> <rules> <rule name="Redirect to https" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> </rules> <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> <httpProtocol> <customHeaders> <clear /> <add name="X-Xss-Protection" value="1; mode=block" /> <add name="X-Content-Type-Options" value="nosniff" /> <add name="X-Frame-Options" value="SAMEORIGIN"/> <add name="Content-Security-Policy" value="default-src 'self'" /> </customHeaders> </httpProtocol> </system.webServer> </configuration>
- Even though you mentioned the App Service configurations are identical, reverify specific settings that might impact headers, such as "HTTP Version" or "ARR Affinity."
- Determine if there are any intermediate proxies or CDNs (e.g., Azure Front Door, Application Gateway) that might be stripping or modifying the HSTS header. Steps to Check Intermediate Proxies/CDNs:
- Identify if any intermediate services are being used.
- Review the configuration of these services to ensure they are not configured to strip or modify headers.
- Adjust the configuration to allow the HSTS header through if necessary. Link: https://learn.microsoft.com/en-us/azure/application-gateway/overview
- Ensure that your web.config is correctly redirecting all HTTP traffic to HTTPS and no HTTP requests are slipping through without being redirected. I provide an example of code snippet is here below:
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
At this point, use the link provided in the solution to learn more details about recommended solutions, also use the below references for more reading and more areas you review to resolve this kind of the issue.
References
- Verifying
web.config
Consistency: - Checking Custom Domain Configuration:
- Inspecting App Service Configuration:
- Checking for Intermediate Proxies or CDNs:
- Testing with Direct URLs:
- Verifying HTTPS Redirection:
- Reviewing Logs and Diagnostics:
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam