Skip to content

Commit e163801

Browse files
committed
Checkpoint
1 parent 4931118 commit e163801

File tree

1 file changed

+79
-28
lines changed
  • javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5

1 file changed

+79
-28
lines changed

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

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import javascript
22
import DataFlow
33
import advanced_security.javascript.frameworks.ui5.JsonParser
4+
import advanced_security.javascript.frameworks.ui5.dataflow.TypeTrackers
45
import semmle.javascript.security.dataflow.DomBasedXssCustomizations
56
import advanced_security.javascript.frameworks.ui5.UI5View
67
import advanced_security.javascript.frameworks.ui5.UI5HTML
@@ -468,23 +469,17 @@ class CustomController extends SapExtendCall {
468469
}
469470

470471
Component getOwnerComponent() {
471-
exists(ManifestJson manifestJson, JsonObject rootObj | manifestJson = result.getManifestJson() |
472-
rootObj
473-
.getPropValue("targets")
474-
.(JsonObject)
475-
// The individual targets
476-
.getPropValue(_)
477-
.(JsonObject)
478-
// The target's "viewName" property
479-
.getPropValue("viewName")
480-
.(JsonString)
481-
.getValue() = name
482-
)
472+
this = result.getParentManifestJson().getARoutingTarget().getView().getController()
483473
}
484474

485475
MethodCallNode getOwnerComponentRef() {
486476
this.getAThisNode() = result.getReceiver() and
487477
result.getMethodName() = "getOwnerComponent"
478+
or
479+
exists(CustomController baseController |
480+
baseController.getDefine() = this.getDefine().getSuperModule(_) and
481+
result = baseController.getOwnerComponentRef()
482+
)
488483
}
489484

490485
/**
@@ -811,7 +806,7 @@ class Component extends SapExtendCall {
811806

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

814-
ManifestJson getManifestJson() {
809+
ManifestJson getParentManifestJson() {
815810
this.getMetadata().getAPropertySource("manifest").asExpr().(StringLiteral).getValue() = "json" and
816811
result.getId() = this.getId()
817812
}
@@ -833,7 +828,7 @@ class Component extends SapExtendCall {
833828
}
834829

835830
ExternalModelManifest getExternalModelDef(string modelName) {
836-
result.getFile() = this.getManifestJson() and result.getName() = modelName
831+
result.getFile() = this.getParentManifestJson() and result.getName() = modelName
837832
}
838833

839834
ExternalModelManifest getAnExternalModelDef() { result = this.getExternalModelDef(_) }
@@ -862,11 +857,50 @@ module ManifestJson {
862857

863858
string getName() { result = dataSourceName }
864859

865-
ManifestJson getManifestJson() { result = manifestJson }
860+
ManifestJson getParentManifestJson() { result = manifestJson }
866861

867862
string getType() { result = this.getPropValue("type").(JsonString).getValue() }
868863
}
869864

865+
class RoutingTargetManifest extends JsonObject {
866+
/** Note: This is NOT its `viewName` property! */
867+
string targetName;
868+
ManifestJson manifestJson;
869+
870+
RoutingTargetManifest() {
871+
exists(JsonObject rootObj |
872+
this.getJsonFile() = manifestJson and
873+
rootObj.getJsonFile() = manifestJson and
874+
this =
875+
rootObj
876+
.getPropValue("sap.ui5")
877+
.(JsonObject)
878+
.getPropValue("routing")
879+
.(JsonObject)
880+
.getPropValue("targets")
881+
.(JsonObject)
882+
.getPropValue(targetName)
883+
)
884+
}
885+
886+
/**
887+
* Gets the value of the `viewName` property of this target.
888+
*/
889+
string getViewName() { result = this.getPropStringValue("viewName") }
890+
891+
/**
892+
* Gets the view this target is associated with.
893+
*/
894+
UI5View getView() {
895+
result.getName() = getSubstringAfterLastOccurrenceOfCharacter(this.getViewName(), "/")
896+
}
897+
898+
/**
899+
* Gets the `manifest.json` file that this routing target is a part of.
900+
*/
901+
ManifestJson getParentManifestJson() { result = manifestJson }
902+
}
903+
870904
class ODataDataSourceManifest extends DataSourceManifest {
871905
ODataDataSourceManifest() { this.getType() = "OData" }
872906
}
@@ -995,7 +1029,19 @@ module ManifestJson {
9951029
this.getBaseName() = "manifest.json"
9961030
}
9971031

998-
DataSourceManifest getDataSource() { this = result.getManifestJson() }
1032+
DataSourceManifest getADataSource() { result = this.getDataSource(_) }
1033+
1034+
DataSourceManifest getDataSource(string name) {
1035+
this = result.getParentManifestJson() and
1036+
result.getName() = name
1037+
}
1038+
1039+
RoutingTargetManifest getARoutingTarget() { result = this.getRoutingTarget(_) }
1040+
1041+
RoutingTargetManifest getRoutingTarget(string viewName) {
1042+
result.getViewName() = viewName and
1043+
result.getParentManifestJson() = this
1044+
}
9991045
}
10001046
}
10011047

@@ -1316,6 +1362,10 @@ class SapExtendCall extends InvokeNode, MethodCallNode {
13161362

13171363
string getName() { result = this.getArgument(0).asExpr().(StringLiteral).getValue() }
13181364

1365+
string getModuleName() {
1366+
result = getSubstringAfterLastOccurrenceOfCharacter(this.getName(), ".")
1367+
}
1368+
13191369
ObjectLiteralNode getContent() { result = this.getArgument(1) }
13201370

13211371
Metadata getMetadata() {
@@ -1510,18 +1560,19 @@ class PropertyMetadata extends ObjectLiteralNode {
15101560
}
15111561
}
15121562

1513-
module TypeTrackers {
1514-
private SourceNode hasDependency(TypeTracker t, string dependencyPath) {
1515-
t.start() and
1516-
exists(UserModule d |
1517-
d.getADependency() = dependencyPath and
1518-
result = d.getRequiredObject(dependencyPath).asSourceNode()
1519-
)
1520-
or
1521-
exists(TypeTracker t2 | result = hasDependency(t2, dependencyPath).track(t2, t))
1522-
}
1563+
bindingset[input, character]
1564+
private int countCharacterInString(string input, string character) {
1565+
result = count(int index | character = input.charAt(index) | index)
1566+
}
1567+
1568+
bindingset[input, character]
1569+
private string getSubstringAfterLastOccurrenceOfCharacter(string input, string character) {
1570+
result = input.splitAt(character, countCharacterInString(input, character))
1571+
}
15231572

1524-
SourceNode hasDependency(string dependencyPath) {
1525-
result = hasDependency(TypeTracker::end(), dependencyPath)
1573+
private module Notebook {
1574+
MethodCallNode test1(CustomController controller) {
1575+
controller.getModuleName() = "EffortDriver" and
1576+
result = controller.getOwnerComponentRef()
15261577
}
15271578
}

0 commit comments

Comments
 (0)