Skip to content

Commit 2c9e1b8

Browse files
committed
Add unit test cases to test DangerouslySetElementValueOfInstantiatedHTMLControlPlacedAtDom
1 parent 4f6bdde commit 2c9e1b8

File tree

10 files changed

+116
-0
lines changed

10 files changed

+116
-0
lines changed

javascript/frameworks/ui5/test/models/dangerous_write_to_html_content/dangerousWriteToHtmlContent.expected

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import javascript
2+
import advanced_security.javascript.frameworks.ui5.UI5
3+
import advanced_security.javascript.frameworks.ui5.UI5View
4+
5+
select "TODO", "TODO"

javascript/frameworks/ui5/test/models/dangerous_write_to_html_content/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "sap-ui5-xss",
3+
"version": "1.0.0",
4+
"main": "index.js"
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
specVersion: '3.0'
2+
metadata:
3+
name: sap-ui5-xss
4+
type: application
5+
framework:
6+
name: SAPUI5
7+
version: "1.115.0"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
sap.ui.define(
2+
[
3+
"sap/ui/core/mvc/Controller",
4+
"sap/m/Input",
5+
"sap/m/Button",
6+
"sap/m/VBox",
7+
"sap/ui/core/HTML",
8+
],
9+
function (Controller, Input, Button, VBox, HTML) {
10+
"use strict";
11+
return Controller.extend("codeql-sap-js.controller.app", {
12+
onInit: function () {
13+
let inputReference = this.getView().byId("unit-test-target1");
14+
let htmlControl = this.getView().byId("htmlControl");
15+
16+
/* ========== 1. Input value piped into static HTML, via a reference ========== */
17+
/* 1-1. Value directly set to `HTML.content` */
18+
htmlControl.content = inputReference.getValue();
19+
20+
/* 1-2. Value set by `HTML.setContent(content)` */
21+
htmlControl.setContent(inputReference.getValue());
22+
},
23+
24+
doSomething: function () {
25+
let inputReference = this.getView().byId("unit-test-target1");
26+
27+
/* ========== 2. Input value piped into dynamic HTML, instantiated and placed on-demand ========== */
28+
/* 2-1. Value passed to the argument of the constructor call */
29+
let htmlControl1 = new HTML({
30+
content: `<div>${inputReference.getValue()}</div>`,
31+
});
32+
htmlControl1.placeAt("HTMLPlaceholder");
33+
34+
/* 2-2. Value directly set to `HTML.content` */
35+
let htmlControl2 = new HTML();
36+
htmlControl2.content = inputReference.getValue();
37+
htmlControl2.placeAt("HTMLPlaceholder");
38+
39+
/* 2-3. Value set by `HTML.setContent(content)` */
40+
let htmlControl3 = new HTML();
41+
htmlControl3.setContent(inputReference.getValue());
42+
htmlControl3.placeAt("HTMLPlaceholder");
43+
},
44+
});
45+
}
46+
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>SAPUI5 XSS</title>
6+
<script
7+
src="https://sdk.openui5.org/resources/sap-ui-core.js"
8+
data-sap-ui-libs="sap.m"
9+
data-sap-ui-onInit="module:codeql-sap-js/index"
10+
data-sap-ui-resourceroots='{
11+
"codeql-sap-js": "./"
12+
}'
13+
></script>
14+
</head>
15+
16+
<body class="sapUiBody" id="content"></body>
17+
<div id="HTMLPlaceholder" />
18+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sap.ui.define([
2+
"sap/ui/core/mvc/XMLView"
3+
], function (XMLView) {
4+
"use strict";
5+
XMLView.create({
6+
viewName: "codeql-sap-js.view.app"
7+
}).then(function (oView) {
8+
oView.placeAt("content");
9+
});
10+
11+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sap.app": {
3+
"id": "sap-ui5-xss"
4+
}
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<mvc:View controllerName="codeql-sap-js.controller.app"
2+
xmlns="sap.m"
3+
xmlns:mvc="sap.ui.core.mvc">
4+
<Input id="unit-test-target1" />
5+
<Button id="button" press=".doSomething" />
6+
<HTML id="htmlControl" />
7+
</mvc:View>

0 commit comments

Comments
 (0)