How to add HTTP Strict Transport Security and other security items to the outbound headers

David Wipper 50 Reputation points
2024-01-10T17:10:08.0333333+00:00

I did a security analysis (https://securityheaders.com/) of our site that is hosted on a Linux App Service server. Our app is in a Docker container. The results indicated that we need to add multiple items to the headers:

Strict-Transport-Security

  • Content-Security-Policy
  • X-Frame-Options
  • X-Content-Type-Options
  • Referrer-Policy
  • Permissions-Policy

I've added a web.config file with the code from this post (https://learn.microsoft.com/en-us/answers/questions/383935/hsts-and-x-xss-in-web-app-linux), but it doesn't seem to working. I've seen a reference that web.config only applies to Windows Server environments, so this is a bit confusing.

Any help would be greatly appreciated!

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

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 19,151 Reputation points Moderator
    2024-01-10T23:30:55.8+00:00

    Hi @David Wipper

    You’re correct, the web.config file is typically used in Windows environments, specifically with IIS servers.

    Since your app is running in a Docker container on a Linux App Service, Nginx is used instead of IIS.

    Here are a couple options to add security headers on a Linux App Service:

    1. Modify your application code to add the headers directly. For example in Node.js:
       
       const helmet = require('helmet') 
    
    app.use(helmet()) 
       
    
    1. Use the Azure Front Door service and configure custom response headers there:
    • Add your App Service as the origin backend pool in Front Door
    • Under "Rules Engine", create a new rule to modify response headers
    • Add your security headers like Strict-Transport-Security, X-XSS-Protection, X-Frame-Options, etc

    This will apply the headers to all responses coming from your App Service through Front Door.


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.