Skip to content

Commit 627a9f6

Browse files
Merge pull request #69 from advanced-security/rvermeulen/bindings
Extend bindings modeling
2 parents 36c0485 + 6d6eb47 commit 627a9f6

File tree

11 files changed

+1922
-0
lines changed

11 files changed

+1922
-0
lines changed

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

Lines changed: 1121 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 632 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| test.js:1:30:1:45 | {/foo/bar/baz} |
2+
| test.js:2:30:2:44 | {foo/bar/baz} |
3+
| test.js:4:41:4:62 | {model>/foo/bar/baz} |
4+
| test.js:5:41:5:61 | {model>foo/bar/baz} |
5+
| test.js:7:41:7:98 | {path : /foo/bar/baz, type : "sap.ui.model.type.String"} |
6+
| test.js:8:41:8:97 | {path : foo/bar/baz, type : "sap.ui.model.type.String"} |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import javascript
2+
import advanced_security.javascript.frameworks.ui5.Bindings
3+
import advanced_security.javascript.frameworks.ui5.BindingStringParser as Make
4+
5+
class BindingStringReader extends StringLiteral {
6+
BindingStringReader() {
7+
this.getValue().matches("{%}")
8+
}
9+
10+
string getBindingString() {
11+
result = this.getValue()
12+
}
13+
}
14+
15+
module BindingStringParser = Make::BindingStringParser<BindingStringReader>;
16+
17+
from BindingStringParser::Binding binding
18+
select binding
19+
20+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const simple_absolute_path = '{/foo/bar/baz}';
2+
const simple_relative_path = '{foo/bar/baz}';
3+
4+
const simple_absolute_path_with_model = '{model>/foo/bar/baz}';
5+
const simple_relative_path_with_model = '{model>foo/bar/baz}';
6+
7+
const simple_absolute_with_properties = "{path: '/foo/bar/baz', type: 'sap.ui.model.type.String'}";
8+
const simple_relative_with_properties = "{path: 'foo/bar/baz', type: 'sap.ui.model.type.String'}";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
| test.html:5:11:5:31 | XML property binding: data-value to {/input} |
2+
| test.html:8:11:8:33 | XML property binding: data-content to {/input} |
3+
| test.js:10:20:10:33 | Early JavaScript property binding: {\\n ... } to "{/root/name}" |
4+
| test.js:21:28:21:34 | JavaScript context binding: oInput to "/root" |
5+
| test.js:23:38:23:43 | Late JavaScript property binding: value to "name" |
6+
| test.js:26:60:34:9 | Early JavaScript property binding: {\\n ... } to {\\n ... } |
7+
| test.js:38:48:44:9 | Late JavaScript property binding: value to {\\n ... } |
8+
| test.js:48:19:48:42 | Early JavaScript property binding: {\\n ... } to "{/#foo ... label}" |
9+
| test.json:5:9:22:9 | JSON property binding: items to {/Base} |
10+
| test.json:11:17:16:17 | JSON property binding: value to {input} |
11+
| test.json:17:17:20:17 | JSON property binding: content to {path : /input, formatter : ".valueFormatter"} |
12+
| test.xml:2:5:2:28 | XML property binding: value to {foo} |
13+
| test.xml:3:5:3:29 | XML property binding: value to {/foo} |
14+
| test.xml:4:5:4:34 | XML property binding: value to {model>foo} |
15+
| test.xml:5:5:5:35 | XML property binding: value to {model>/foo} |
16+
| test.xml:6:5:8:29 | XML context binding: binding to {/root} |
17+
| test.xml:6:5:8:29 | XML property binding: value to {foo} |
18+
| test.xml:9:5:9:70 | XML property binding: value to {path : foo, type : "sap.ui.model.type.String"} |
19+
| test.xml:10:5:10:71 | XML property binding: value to {path : /foo, type : "sap.ui.model.type.String"} |
20+
| test.xml:11:5:11:77 | XML property binding: value to {path : model>/foo, type : "sap.ui.model.type.String"} |
21+
| test.xml:12:5:12:76 | XML property binding: value to {path : model>foo, type : "sap.ui.model.type.String"} |
22+
| test.xml:14:5:22:45 | XML property binding: value to {parts : [{path : foo}, {path : bar/baz}, {path : quux}], formatter : "some.formatter"} |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
import advanced_security.javascript.frameworks.ui5.Bindings
3+
4+
select any(Binding b)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template data-controller-name="codeql-sap-js.controller.app">
2+
<div data-sap-ui-type="sap.m.Input"
3+
data-placeholder="Enter Payload"
4+
data-description="Try: &lt;img src=x onerror=alert(&quot;XSS&quot;)&gt;"
5+
data-value="{/input}">
6+
</div>
7+
<div data-sap-ui-type="sap.ui.core.HTML"
8+
data-content="{/input}">
9+
</div>
10+
</template>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
sap.ui.define([
2+
"sap/ui/core/mvc/Controller"
3+
], function(Controller) {
4+
"use strict";
5+
6+
return Controller.extend("foo", {
7+
onInit: function() {
8+
// Early property binding
9+
var oInputWithEarlyPropertyBinding = new sap.m.Input({
10+
value: "{/root/name}"
11+
});
12+
13+
// Early dynamic property binding
14+
const model = "model";
15+
var oInputWithEarlyDynamicPropertyBinding = new sap.m.Input({
16+
value: "{" + model + "</root/name}"
17+
});
18+
19+
var oInputWithLateBinding = this.byId("foo");
20+
// Late context binding
21+
oInput.bindElement("/root");
22+
// Late property binding
23+
oInput.bindProperty("value", "name");
24+
25+
// Early composite binding
26+
var oInputWithEarlyContextBinding = new sap.m.Input({
27+
value: {
28+
parts: [
29+
{ path: "/foo", type: new sap.ui.model.type.String() },
30+
{ path: "/bar" },
31+
{ path: "baz>/quux", type: new sap.ui.model.type.Float() }
32+
]
33+
}
34+
});
35+
36+
// Late composite binding
37+
var oInputWithLateContextBinding = this.byId("foo");
38+
oInputWithLateContextBinding.bindValue({
39+
parts: [
40+
{ path: "/foo", type: new sap.ui.model.type.String() },
41+
{ path: "/bar" },
42+
{ path: "baz>/quux", type: new sap.ui.model.type.Float() }
43+
]
44+
});
45+
46+
// Early property metadata binding
47+
var oLabel = new sap.m.Label({
48+
text: "{/#foo/bar/@sap:label}"
49+
});
50+
}
51+
});
52+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"Type": "sap.ui.core.mvc.JSONView",
3+
"controllerName": "codeql-sap-js.controller.app",
4+
"content": [
5+
{
6+
"Type": "sap.ui.commons.Carousel",
7+
"width": "100%",
8+
"orientation": "horizontal",
9+
"items":"{/Base}",
10+
"content": [
11+
{
12+
"Type": "sap.m.Input",
13+
"placeholder": "Enter Payload",
14+
"description": "Try: <img src=x onerror=alert(\"XSS\")>",
15+
"value": "{input}"
16+
},
17+
{
18+
"Type": "sap.ui.core.HTML",
19+
"content": "{path:'/input', formatter: '.valueFormatter'}"
20+
}
21+
]
22+
}
23+
]
24+
}

0 commit comments

Comments
 (0)