How can I add custom security headers to CSR angular application deployed on Azure Webapp?

Beltran, Julian Ricardo 0 Reputation points
2024-03-15T22:53:54.8533333+00:00

I have a CSR (Client-side-rendered) angular applicaton that is beying deployed to an Azure Linux Webapp. I have a security requriement to add some security headers to the application responses such as Content-Security-Policy, X-Content-Type-Options, etc.

Is there any way to add this custom headers to the webapp responses withouth making my application SSR (Server-side-rendered) nor using additional Azure services like Azure Front Door or Azure CDN?

Thank you in advance for any help.

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

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 19,151 Reputation points Moderator
    2024-03-21T05:39:19.53+00:00

    Hi @Beltran, Julian Ricardo yes, there are ways to add custom security headers to CSR angular application deployed on Azure Webapp

    Here's the recommended approach using the built-in capabilities of Azure Linux Web App:

    1.Create a file named web.config (or modify an existing one) in the root directory of your Angular application. This file will be used to configure IIS (Internet Information Services) on your Azure Web App.

    2. Inside the web.config file, add the following section to define your custom security headers:

    <system.webServer>
      <staticContent>
        <mimeMaps>
          <add fileExtension=".woff" mimeType="application/font-woff" />
          <add fileExtension=".woff2" mimeType="application/font-woff2" />
          </mimeMaps>
        <headers>
          <remove name="X-Powered-By" /> <add name="Content-Security-Policy" value="your-csp-policy-here" />
          <add name="X-Content-Type-Options" value="nosniff" />
          </headers>
      </staticContent>
    </system.webServer>
    
    • Replace your-csp-policy-here with your actual Content-Security-Policy directive.

    3. Deploy your updated application with the web.config file to your Azure Linux Web App using your preferred deployment method (e.g., Git push, Azure DevOps pipeline)


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.