File tree Expand file tree Collapse file tree 4 files changed +12
-46
lines changed
main/java/org/sonar/plugins/xml/checks/security/web
test/resources/checks/MimeNosniffCheck
webconfig-missing-nosniff Expand file tree Collapse file tree 4 files changed +12
-46
lines changed Original file line number Diff line number Diff line change 2020import org .sonarsource .analyzer .commons .xml .XPathBuilder ;
2121import org .sonarsource .analyzer .commons .xml .XmlFile ;
2222import org .w3c .dom .Document ;
23+ import org .w3c .dom .Element ;
2324import org .w3c .dom .NodeList ;
2425
2526import javax .xml .xpath .XPathExpression ;
27+ import java .util .Collections ;
2628
2729/**
2830 * Ensure that the X-Content-Type-Options header is set to "nosniff" to prevent MIME type sniffing.
@@ -55,7 +57,10 @@ protected void scanWebConfig(XmlFile file) {
5557 .stream ()
5658 .findFirst ()
5759 .ifPresent (target ->
58- reportIssue (target , "Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true." ));
60+ reportIssue (
61+ XmlFile .nameLocation ((Element ) target ),
62+ "Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true." ,
63+ Collections .emptyList ()));
5964 }
6065 }
6166}
Original file line number Diff line number Diff line change 22<configuration >
33 <system .webServer>
44 <httpProtocol >
5- <customHeaders > <!-- Noncompliant -->
5+ <customHeaders > <!-- Noncompliant {{Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.}} -->
6+ <!-- ^^^^^^^^^^^^^ -->
67 <remove name =" X-Powered-By" />
78 <add name =" X-Frame-Options" value =" SAMEORIGIN" />
89 </customHeaders >
910 </httpProtocol >
1011 </system .webServer>
11- <location path =" ." inheritInChildApplications =" false" >
12- <system .webServer>
13- <handlers >
14- <add name =" aspNetCore" path =" *" verb =" *" modules =" AspNetCoreModuleV2"
15- resourceType =" Unspecified" />
16- </handlers >
17- <aspNetCore processPath =" bin\Debug\net8.0\WebApp.exe" arguments =" " stdoutLogEnabled =" false"
18- hostingModel =" InProcess" >
19- <environmentVariables >
20- <environmentVariable name =" ASPNETCORE_HTTPS_PORT" value =" 443" />
21- </environmentVariables >
22- </aspNetCore >
23- </system .webServer>
24- </location >
2512</configuration >
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
2- <configuration > <!-- Noncompliant -->
3- <location path =" ." inheritInChildApplications =" false" >
4- <system .webServer>
5- <handlers >
6- <add name =" aspNetCore" path =" *" verb =" *" modules =" AspNetCoreModuleV2"
7- resourceType =" Unspecified" />
8- </handlers >
9- <aspNetCore processPath =" bin\Debug\net8.0\WebApp.exe" arguments =" " stdoutLogEnabled =" false"
10- hostingModel =" InProcess" >
11- <environmentVariables >
12- <environmentVariable name =" ASPNETCORE_HTTPS_PORT" value =" 443" />
13- </environmentVariables >
14- </aspNetCore >
15- </system .webServer>
16- </location >
2+ <configuration > <!-- Noncompliant {{Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.}} -->
3+ <!-- ^[sc=2;ec=14] -->
174</configuration >
Original file line number Diff line number Diff line change 22<configuration >
33 <system .webServer>
44 <httpProtocol >
5- <customHeaders > <!-- Noncompliant -->
5+ <customHeaders > <!-- Noncompliant {{Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.}} -->
6+ <!-- ^^^^^^^^^^^^^ -->
67 <add name =" X-Content-Type-Options" value =" yes" />
78 </customHeaders >
89 </httpProtocol >
910 </system .webServer>
10- <location path =" ." inheritInChildApplications =" false" >
11- <system .webServer>
12- <handlers >
13- <add name =" aspNetCore" path =" *" verb =" *" modules =" AspNetCoreModuleV2"
14- resourceType =" Unspecified" />
15- </handlers >
16- <aspNetCore processPath =" bin\Debug\net8.0\WebApp.exe" arguments =" " stdoutLogEnabled =" false"
17- hostingModel =" InProcess" >
18- <environmentVariables >
19- <environmentVariable name =" ASPNETCORE_HTTPS_PORT" value =" 443" />
20- </environmentVariables >
21- </aspNetCore >
22- </system .webServer>
23- </location >
2411</configuration >
You can’t perform that action at this time.
0 commit comments