Skip to content

Commit 05e9a0b

Browse files
committed
Checkpoint
1. Minor comment formatting 2. Unify the TypeTrackers into one (hasDependency) 3. Some more modeling
1 parent 39b8171 commit 05e9a0b

2 files changed

Lines changed: 80 additions & 70 deletions

File tree

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

Lines changed: 39 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ abstract class UserModule extends CallExpr {
155155
class SapDefineModule extends AmdModuleDefinition::Range, MethodCallExpr, UserModule {
156156
SapDefineModule() {
157157
/*
158-
* NOTE: This only matches a call to the dot expression `sap.ui.define`, and does not consider a flow among `sap`, `ui`, and `define`.
158+
* NOTE: This only matches a call to the dot expression `sap.ui.define`, and does not
159+
* consider a flow among `sap`, `ui`, and `define`.
159160
*/
160161

161162
exists(GlobalVarAccess sap, DotExpr sapUi, DotExpr sapUiDefine |
@@ -220,50 +221,11 @@ class JQueryDefineModule extends UserModule, MethodCallExpr {
220221
}
221222
}
222223

223-
private SourceNode sapControl(TypeTracker t) {
224-
t.start() and
225-
exists(UserModule d, string dependencyType |
226-
dependencyType = ["sap/ui/core/Control", "sap.ui.core.Control"]
227-
|
228-
d.getADependency() = dependencyType and
229-
result = d.getRequiredObject(dependencyType).asSourceNode()
230-
)
231-
or
232-
exists(TypeTracker t2 | result = sapControl(t2).track(t2, t))
233-
}
234-
235-
private SourceNode sapControl() { result = sapControl(TypeTracker::end()) }
236-
237-
private SourceNode sapController(TypeTracker t) {
238-
t.start() and
239-
exists(UserModule d, string dependencyType |
240-
dependencyType = ["sap/ui/core/mvc/Controller", "sap.ui.core.mvc.Controller"]
241-
|
242-
d.getADependency() = dependencyType and
243-
result = d.getRequiredObject(dependencyType).asSourceNode()
244-
)
245-
or
246-
exists(TypeTracker t2 | result = sapController(t2).track(t2, t))
247-
}
248-
249-
private SourceNode sapController() { result = sapController(TypeTracker::end()) }
250-
251-
private SourceNode sapRenderer(TypeTracker t) {
252-
t.start() and
253-
exists(UserModule d, string dependencyType |
254-
dependencyType = ["sap/ui/core/Renderer", "sap.ui.core.Renderer"]
255-
|
256-
d.getADependency() = dependencyType and
257-
result = d.getRequiredObject(dependencyType).asSourceNode()
258-
)
259-
or
260-
exists(TypeTracker t2 | result = sapController(t2).track(t2, t))
261-
}
262-
263-
private SourceNode sapRenderer() { result = sapRenderer(TypeTracker::end()) }
264-
265-
private class Renderer extends SapExtendCall {
266-
Renderer() { this.getReceiver().getALocalSource() = sapRenderer() }
224+
class Renderer extends SapExtendCall {
225+
Renderer() {
226+
this.getReceiver().getALocalSource() =
227+
TypeTrackers::hasDependency(["sap/ui/core/Renderer", "sap.ui.core.Renderer"])
228+
}
267229

268230
FunctionNode getRenderer() {
269231
/* 1. Old API */
@@ -276,7 +238,8 @@ private class Renderer extends SapExtendCall {
276238

277239
class CustomControl extends SapExtendCall {
278240
CustomControl() {
279-
this.getReceiver().getALocalSource() = sapControl() or
241+
this.getReceiver().getALocalSource() =
242+
TypeTrackers::hasDependency(["sap/ui/core/mvc/Controller", "sap.ui.core.mvc.Controller"]) or
280243
exists(SapDefineModule sapModule | this.getDefine() = sapModule.getExtendingModule())
281244
}
282245

@@ -450,7 +413,8 @@ class CustomController extends SapExtendCall {
450413
string name;
451414

452415
CustomController() {
453-
this.getReceiver().getALocalSource() = sapController() and
416+
this.getReceiver().getALocalSource() =
417+
TypeTrackers::hasDependency(["sap/ui/core/mvc/Controller", "sap.ui.core.mvc.Controller"]) and
454418
name = this.getFile().getBaseName().regexpCapture("([a-zA-Z0-9]+).[cC]ontroller.js", 1)
455419
}
456420

@@ -772,35 +736,24 @@ abstract class UI5InternalModel extends UI5Model, NewNode {
772736
abstract string getPathString(Property property);
773737
}
774738

775-
/**
776-
* Represents models that are loaded from an external source, e.g. OData service.
777-
* It is the value flowing to a `setModel` call in a handler of a `CustomController` (which is represented by `ControllerHandler`), since it is the closest we can get to the actual model itself.
778-
*/
779-
private SourceNode sapComponent(TypeTracker t) {
780-
t.start() and
781-
exists(UserModule d, string dependencyType |
782-
dependencyType =
783-
[
784-
"sap/ui/core/mvc/Component", "sap.ui.core.mvc.Component", "sap/ui/core/UIComponent",
785-
"sap.ui.core.UIComponent"
786-
]
787-
|
788-
d.getADependency() = dependencyType and
789-
result = d.getRequiredObject(dependencyType).asSourceNode()
790-
)
791-
or
792-
exists(TypeTracker t2 | result = sapComponent(t2).track(t2, t))
793-
}
794-
795-
private SourceNode sapComponent() { result = sapComponent(TypeTracker::end()) }
796-
797739
import ManifestJson
798740

799741
/**
800742
* A UI5 Component that may contain other controllers or controls.
801743
*/
802744
class Component extends SapExtendCall {
803-
Component() { this.getReceiver().getALocalSource() = sapComponent() }
745+
Component() {
746+
this.getReceiver().getALocalSource() =
747+
/*
748+
* Represents models that are loaded from an external source, e.g. OData service.
749+
* It is the value flowing to a `setModel` call in a handler of a `CustomController` (which is represented by `ControllerHandler`), since it is the closest we can get to the actual model itself.
750+
*/
751+
752+
TypeTrackers::hasDependency([
753+
"sap/ui/core/mvc/Component", "sap.ui.core.mvc.Component", "sap/ui/core/UIComponent",
754+
"sap.ui.core.UIComponent"
755+
])
756+
}
804757

805758
string getId() { result = this.getName().regexpCapture("([a-zA-Z0-9.]+).Component", 1) }
806759

@@ -1490,3 +1443,19 @@ class PropertyMetadata extends ObjectLiteralNode {
14901443
inSameWebApp(this.getFile(), result.getFile())
14911444
}
14921445
}
1446+
1447+
module TypeTrackers {
1448+
private SourceNode hasDependency(TypeTracker t, string dependencyPath) {
1449+
t.start() and
1450+
exists(UserModule d |
1451+
d.getADependency() = dependencyPath and
1452+
result = d.getRequiredObject(dependencyPath).asSourceNode()
1453+
)
1454+
or
1455+
exists(TypeTracker t2 | result = hasDependency(t2, dependencyPath).track(t2, t))
1456+
}
1457+
1458+
SourceNode hasDependency(string dependencyPath) {
1459+
result = hasDependency(TypeTracker::end(), dependencyPath)
1460+
}
1461+
}

javascript/frameworks/ui5/src/UI5LogInjection/UI5LogsToHttp.ql

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,47 @@ class UI5LogInjectionConfiguration extends LogInjection::LogInjectionConfigurati
2727
}
2828
}
2929

30+
class UI5Logger extends RequiredObject {
31+
UI5Logger() { this.getDependency() = "sap/base/Log" }
32+
33+
DataFlow::Node getALogListener() {
34+
exists(MethodCallNode addLogListenerCall |
35+
addLogListenerCall.getCalleeName() = "addLogListener" and
36+
result = addLogListenerCall.getArgument(0)
37+
)
38+
}
39+
40+
MethodCallNode getLogEntriesCall() {
41+
result.getReceiver().getALocalSource() = this.asSourceNode() and
42+
result.getMethodName() = "getLogEntries"
43+
}
44+
}
45+
46+
private predicate test(MethodCallNode call, Node receiver, SourceNode receiverSource) {
47+
call.getMethodName() = "getLogEntries" and
48+
receiver = call.getReceiver() and
49+
receiverSource = receiver.getALocalSource()
50+
}
51+
52+
SourceNode isLogListener(TypeBackTracker t) {
53+
t.start() and
54+
exists(UI5Logger log | result = log.getALogListener())
55+
or
56+
exists(DataFlow::TypeBackTracker t2 | result = isLogListener(t2).backtrack(t2, t))
57+
}
58+
59+
SourceNode isLogListener() { result = isLogListener(TypeBackTracker::end()) }
60+
61+
class LogListener extends DataFlow::Node {
62+
LogListener() { this = isLogListener() }
63+
64+
FunctionNode getOnLogEntryMethod() {
65+
exists(DataFlow::PropWrite propWrite | propWrite.getPropertyName() = "onLogEntry" |
66+
result = propWrite.getRhs()
67+
)
68+
}
69+
}
70+
3071
from
3172
UI5LogInjectionConfiguration cfg, UI5PathNode source, UI5PathNode sink, UI5PathNode primarySource
3273
where

0 commit comments

Comments
 (0)