Skip to content

Commit 6f8b1f6

Browse files
committed
Csharp: address review
1 parent c728503 commit 6f8b1f6

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

csharp/ql/src/Security Features/CWE-451/MissingXFrameOptions.ql

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ import csharp
1616
import semmle.code.asp.WebConfig
1717
import 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

Comments
 (0)