@@ -16,6 +16,17 @@ import csharp
1616import semmle.code.asp.WebConfig
1717import semmle.code.csharp.frameworks.system.Web
1818
19+ XmlElement getAWebServerConfig ( WebConfigXml webConfig ) {
20+ result = webConfig .getARootElement ( )
21+ or
22+ result = webConfig .getARootElement ( ) .getAChild ( "location" ) and
23+ (
24+ not exists ( result .getAttributeValue ( "path" ) ) // equivalent to path="."
25+ or
26+ result .getAttributeValue ( "path" ) = [ "" , "." ]
27+ )
28+ }
29+
1930/**
2031 * Holds if the `Web.config` file `webConfig` adds an `X-Frame-Options` header.
2132 */
@@ -31,15 +42,12 @@ predicate hasWebConfigXFrameOptions(WebConfigXml webConfig) {
3142 // </system.webServer>
3243 // ```
3344 // This can also be in a `location`
34- exists ( XmlElement root |
35- root = webConfig .getARootElement ( ) and
36- [ root , root .getAChild ( "location" ) ]
37- .getAChild ( "system.webServer" )
38- .getAChild ( "httpProtocol" )
39- .getAChild ( "customHeaders" )
40- .getAChild ( "add" )
41- .getAttributeValue ( "name" ) = "X-Frame-Options"
42- )
45+ getAWebServerConfig ( webConfig )
46+ .getAChild ( "system.webServer" )
47+ .getAChild ( "httpProtocol" )
48+ .getAChild ( "customHeaders" )
49+ .getAChild ( "add" )
50+ .getAttributeValue ( "name" ) = "X-Frame-Options"
4351}
4452
4553/**
0 commit comments