-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMissingXFrameOptions.ql
More file actions
55 lines (51 loc) · 1.76 KB
/
MissingXFrameOptions.ql
File metadata and controls
55 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @name Missing X-Frame-Options HTTP header
* @description If the 'X-Frame-Options' setting is not provided, a malicious user may be able to
* overlay their own UI on top of the site by using an iframe.
* @kind problem
* @problem.severity error
* @precision high
* @id cs/web/missing-x-frame-options
* @tags security
* external/cwe/cwe-451
* external/cwe/cwe-829
*/
import csharp
import semmle.code.asp.WebConfig
import semmle.code.csharp.frameworks.system.Web
/**
* Holds if there exists a `Web.config` file in the snapshot that adds an `X-Frame-Options` header.
*/
predicate hasWebConfigXFrameOptions() {
/*
* Looking for an entry in a Web.config file that looks like this:
* ```
* <system.webServer>
* <httpProtocol>
* <customHeaders>
* <add name="X-Frame-Options" value="SAMEORIGIN" />
* </customHeaders>
* </httpProtocol>
* </system.webServer>
* ```
*/
exists(XMLElement element |
element = any(WebConfigXML webConfig).getARootElement().getAChild("system.webServer").getAChild("httpProtocol").getAChild("customHeaders").getAChild("add") |
element.getAttributeValue("name") = "X-Frame-Options"
)
}
/**
* Holds if there exists a call to `AddHeader` or `AppendHeader` adding the `X-Frame-Options`
* header.
*/
predicate hasCodeXFrameOptions() {
exists(MethodCall call |
call.getTarget() = any(SystemWebHttpResponseClass r).getAppendHeaderMethod() or
call.getTarget() = any(SystemWebHttpResponseClass r).getAddHeaderMethod() |
call.getArgumentForName("name").getValue() = "X-Frame-Options"
)
}
from WebConfigXML webConfig
where not hasWebConfigXFrameOptions()
and not hasCodeXFrameOptions()
select webConfig, "Configuration file is missing the X-Frame-Options setting."