Skip to content

Commit 91229f8

Browse files
authored
Merge pull request github#3398 from hvitved/csharp/missing-x-frame-option
C#: More results for `cs/web/missing-x-frame-options`
2 parents b3498bd + a4d933d commit 91229f8

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import semmle.code.asp.WebConfig
1616
import semmle.code.csharp.frameworks.system.Web
1717

1818
/**
19-
* Holds if there exists a `Web.config` file in the snapshot that adds an `X-Frame-Options` header.
19+
* Holds if the `Web.config` file `webConfig` adds an `X-Frame-Options` header.
2020
*/
21-
predicate hasWebConfigXFrameOptions() {
22-
// Looking for an entry in a Web.config file that looks like this:
21+
predicate hasWebConfigXFrameOptions(WebConfigXML webConfig) {
22+
// Looking for an entry in `webConfig` that looks like this:
2323
// ```
2424
// <system.webServer>
2525
// <httpProtocol>
@@ -29,17 +29,13 @@ predicate hasWebConfigXFrameOptions() {
2929
// </httpProtocol>
3030
// </system.webServer>
3131
// ```
32-
exists(XMLElement element |
33-
element =
34-
any(WebConfigXML webConfig)
35-
.getARootElement()
36-
.getAChild("system.webServer")
37-
.getAChild("httpProtocol")
38-
.getAChild("customHeaders")
39-
.getAChild("add")
40-
|
41-
element.getAttributeValue("name") = "X-Frame-Options"
42-
)
32+
webConfig
33+
.getARootElement()
34+
.getAChild("system.webServer")
35+
.getAChild("httpProtocol")
36+
.getAChild("customHeaders")
37+
.getAChild("add")
38+
.getAttributeValue("name") = "X-Frame-Options"
4339
}
4440

4541
/**
@@ -57,6 +53,6 @@ predicate hasCodeXFrameOptions() {
5753

5854
from WebConfigXML webConfig
5955
where
60-
not hasWebConfigXFrameOptions() and
56+
not hasWebConfigXFrameOptions(webConfig) and
6157
not hasCodeXFrameOptions()
6258
select webConfig, "Configuration file is missing the X-Frame-Options setting."

0 commit comments

Comments
 (0)