Skip to content

Commit 3edb117

Browse files
committed
Address incorrect association between frame options and web app
1 parent 9311c30 commit 3edb117

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/UI5.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ private import DataFlow
33
private import advanced_security.javascript.frameworks.ui5.JsonParser
44
private import semmle.javascript.security.dataflow.DomBasedXssCustomizations
55
private import advanced_security.javascript.frameworks.ui5.UI5View
6+
private import advanced_security.javascript.frameworks.ui5.UI5HTML
67

78
module UI5 {
89
bindingset[this]
@@ -126,6 +127,18 @@ module UI5 {
126127
result.getAbsolutePath() = resolvedModulePath + ".js"
127128
)
128129
}
130+
131+
FrameOptions getFrameOptions() {
132+
exists(HTML::DocumentElement doc | doc.getFile() = this |
133+
result.asHtmlFrameOptions() = coreScript.getAnAttribute()
134+
)
135+
or
136+
result.asJsFrameOptions().getFile() = this
137+
}
138+
139+
HTML::DocumentElement getDocument() {
140+
result.getFile() = this
141+
}
129142
}
130143

131144
/**

javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/UI5HTML.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ class FrameOptions extends TFrameOptions {
8585
}
8686

8787
/**
88-
* Holds if the frame options are left untouched as the default value `trusted`.
88+
* Holds if the specified frame options do not prevent click jacking.
8989
*/
90-
predicate thereIsNoFrameOptionSet(UI5::WebApp webapp) {
91-
not exists(FrameOptions frameOptions | webapp.getAResource() = frameOptions.getLocation().getFile() |
90+
predicate isMissingFrameOptionsToPreventClickjacking(UI5::WebApp webapp) {
91+
not exists(FrameOptions frameOptions | webapp.getFrameOptions() = frameOptions |
9292
frameOptions.allowsSharedOriginEmbedding() or
9393
frameOptions.deniesEmbedding() or
9494
frameOptions.allowsAllOriginEmbedding()

javascript/frameworks/ui5/src/UI5Clickjacking/UI5Clickjacking.ql

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,46 @@ import advanced_security.javascript.frameworks.ui5.UI5HTML
1515
import semmle.javascript.RestrictedLocations
1616
private import advanced_security.javascript.frameworks.ui5.UI5
1717

18-
class FirstLineOfMainHtml extends HTML::DocumentElement, FirstLineOf {
19-
FirstLineOfMainHtml() {
20-
exists(UI5::WebApp app | this.getFile().(FirstLineOf).getFile() = app)
18+
class FirstLineOfDocumentElementWebApp extends HTML::DocumentElement, FirstLineOf {
19+
FirstLineOfDocumentElementWebApp() {
20+
exists(UI5::WebApp app | app.getDocument() = this)
2121
}
2222
}
2323

2424
newtype TAlertLocation =
2525
TFrameOptions(FrameOptions frameOptions) or
26-
TFirstLineOfMainHtml(FirstLineOfMainHtml htmlStartTag)
26+
TFirstLineOfDocumentElementWebApp(FirstLineOfDocumentElementWebApp htmlStartTag)
2727

2828
class AlertLocation extends TAlertLocation {
2929
FrameOptions asFrameOptions() { this = TFrameOptions(result) }
3030

31-
FirstLineOfMainHtml asFirstLineOfMainHtml() { this = TFirstLineOfMainHtml(result) }
31+
FirstLineOfDocumentElementWebApp asFirstLineOfDocumentElementWebApp() { this = TFirstLineOfDocumentElementWebApp(result) }
3232

3333
string toString() {
3434
result = this.asFrameOptions().toString() or
35-
result = this.asFirstLineOfMainHtml().toString()
35+
result = this.asFirstLineOfDocumentElementWebApp().toString()
3636
}
3737

3838
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
3939
this.asFrameOptions().getLocation().hasLocationInfo(path, sl, sc, el, ec)
4040
or
41-
this.asFirstLineOfMainHtml().hasLocationInfo(path, sl, sc, el, ec)
41+
this.asFirstLineOfDocumentElementWebApp().hasLocationInfo(path, sl, sc, el, ec)
4242
}
4343
}
4444

45-
from AlertLocation alert, string message
45+
from AlertLocation alertLocation, string message
4646
where
47-
exists(FrameOptions frameOptions | frameOptions.allowsAllOriginEmbedding() |
48-
alert.asFrameOptions() = frameOptions and
49-
message =
50-
"Possible clickjacking vulnerability due to " + frameOptions.toString() +
51-
" being set to `allow`."
52-
)
53-
or
54-
exists(UI5::WebApp app | thereIsNoFrameOptionSet(app) |
55-
alert.asFirstLineOfMainHtml().getFile() = app and
47+
exists(UI5::WebApp app |
48+
exists(FrameOptions frameOptions | app.getFrameOptions() = frameOptions |
49+
frameOptions.allowsAllOriginEmbedding() and
50+
alertLocation.asFrameOptions() = frameOptions and
51+
message =
52+
"Possible clickjacking vulnerability due to " + frameOptions.toString() +
53+
" being set to `allow`."
54+
)
55+
or
56+
isMissingFrameOptionsToPreventClickjacking(app) and
57+
alertLocation.asFirstLineOfDocumentElementWebApp() = app.getDocument() and
5658
message = "Possible clickjacking vulnerability due to missing frame options."
5759
)
58-
select alert, message
60+
select alertLocation, message

0 commit comments

Comments
 (0)