Method for handling low-risk website vulnerabilities via pseudo-static functionality.

Published: 2023-07-11

Many websites show many low-risk vulnerabilities when scanned by third-party platforms, especially when using 绿盟 for security detection. Linux and virtual hosts also have this situation, which can be configured through pseudo-static rules.

 

l Windows Host

Windows hosts need to add the following rules in the wwwroot directory's web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
        <httpCookies httpOnlyCookies="true"  requireSSL="true"  />
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <verbs allowUnlisted="true">
                    <add verb="OPTIONS" allowed="false"/>
                    <add verb="TRACE" allowed="false"/>
                </verbs>
            </requestFiltering>
       </security>
       <httpProtocol>
           <customHeaders>
               <!--Detected missing X-Content-Type-Options response header-->
               <add name="X-Content-Type-Options" value="nosniff" />
               <!--Detected missing X-XSS-Protection response header-->
               <add name="X-XSS-Protection" value="1;mode=block" />
               <!--Detected missing Content-Security-Policy response header /-->
               <add name="Content-Security-Policy" value="default-src 'self' 'unsafe-inline' ; img-src 'self' data:" />
               <!--Detected missing Strict-Transport-Security response header-->
               <add name="Strict-Transport-Security" value="max-age=31536000" />
               <!--Detected missing Referrer-Policy response header-->
               <add name="Referrer-Policy" value="origin-when-cross-origin" />
               <!--Detected missing X-Permitted-Cross-Domain-Policies response header-->
               <add name="X-Permitted-Cross-Domain-Policies" value="master-only" />
               <!--Detected missing X-Download-Options response header-->
               <add name="X-Download-Options" value="noopen" />
               <!--Clickjacking: X-Frame-Options not configured-->
               <add name="X-Frame-Options" value="SAMEORIGIN" />
           </customHeaders>
       </httpProtocol>
        <rewrite>       
        <outboundRules>
            <rule name="Add HttpOnly" preCondition="No HttpOnly">
                <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
                <action type="Rewrite" value="{R:0}; HttpOnly" />
                <conditions>
                </conditions>
            </rule>
            <preConditions>
                <preCondition name="No HttpOnly">
                    <add input="{RESPONSE_Set_Cookie}" pattern="." />
                    <add input="{RESPONSE_Set_Cookie}" pattern="; HttpOnly" negate="true" />
                </preCondition>
            </preConditions>
        </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

 

Please note that the rules must be added to the correct nodes; if added incorrectly, the website may fail to open.

 

l Linux Host

In the wwwroot directory's .htaccess add the following rules:

 

<IfModule mod_headers.c> 
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
Header set Content-Security-Policy "default-src 'self' 'unsafe-inline' ; img-src 'self' data:"
Header set Strict-Transport-Security: "max-age=31536000 ; includeSubDomains ;"
Header set Referrer-Policy: strict-origin-when-cross-origin
Header set X-Permitted-Cross-Domain-Policies "master-only"
Header set X-Download-Options "noopen"
Header set X-Frame-Options "SAMEORIGIN"
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|OPTIONS)
RewriteRule .* - [F]


# .htaccess can only manage static files; PHP dynamic programs need to be configured in PHP code.

<?php
// Globally set the Secure attribute of Session Cookie; requires deployment of https
// ini_set("session.cookie_secure", "1");
// Also set HttpOnly
ini_set("session.cookie_httponly", "1");
header("X-Content-Type-Options: nosniff");
header("X-XSS-Protection: 1; mode=bloc");
header("Content-Security-Policy: default-src 'self' 'unsafe-inline' ; img-src 'self' data:");
header("Strict-Transport-Security: max-age=31536000 ; includeSubDomains ;");
header("Referrer-Policy: strict-origin-when-cross-origin");
header("X-Permitted-Cross-Domain-Policies: master-only");
header("X-Download-Options: noopen");
header("X-Frame-Options: SAMEORIGIN");
?>

NGINX rules: add to the server block in the site configuration file

add_header Cross-Origin-Opener-Policy "same-origin";
add_header Cross-Origin-Embedder-Policy "require-corp";
add_header Cross-Origin-Resource-Policy "same-origin";
add_header Clear-Site-Data '"cache", "cookies", "storage"';
add_header Permissions-Policy "camera=(self), microphone=(self), autoplay=(self), picture-in-picture=(self), fullscreen=(self), display-capture=(), geolocation=()";
add_header Referrer-Policy "strict-origin-when-cross-origin";
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' ; img-src 'self' data:";
add_header X-Download-Options "noopen";
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Permitted-Cross-Domain-Policies "none";
add_header X-XSS-Protection "1; mode=block";


Note: Regardless of whether it is windows or Linux host, adding the rules will take effect and no other settings are needed.