Skip to content

Restructured to have unit tests working #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
library: true
name: sap-js/ui5-data-extension-pack
name: sap-js/ui5-data-extensions-pack
version: 0.0.1
extensionTargets:
codeql/javascript-all: "*"
codeql/javascript-queries: "*"
dataExtensions:
- ui5-data-extension.yaml
- ui5-data-extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ extensions:
pack: codeql/javascript-all
extensible: sourceModel
data:
# sap.ui.commons.TextField.value
# sap.ui.commons.TextField.value sap.ui.commons.TextField#getValue
- ["sap/ui/commons/TextField", "Instance.Member[value]", "remote"]
# sap.m.InputBase.value
- ["sap/ui/commons/TextField", "Instance.Member[getValue].ReturnValue", "remote"]
# sap.m.InputBase.value sap.m.InputBase#getValue
- ["sap/m/InputBase", "Instance.Member[value]", "remote"]
# sap.m.Input.value
- ["sap/m/InputBase", "Instance.Member[getValue]", "remote"]
# sap.m.SearchField.value sap.m.InputBase#getValue
- ["sap/m/SearchField", "Instance.Member[value]", "remote"]
- ["sap/m/SearchField", "Instance.Member[getValue]", "remote"]
# sap.m.Input.value sap.m.Input#getValue()
- ["sap/m/Input", "Instance.Member[value]", "remote"]
# sap.m.Input#getValue()
- ["sap/m/Input", "Instance.Member[getValue].ReturnValue", "remote"]
# jQuery.sap.getUriParameters() return
- ["global", "Member[jQuery].Member[sap].Member[getUriParameters].ReturnValue.Member[get]", "remote"]
Expand All @@ -36,8 +40,7 @@ extensions:
- ["global", "Member[jQuery].Member[sap].Member[syncPost].ReturnValue", "remote"]
# jQuery.sap.syncPostText() return
- ["global", "Member[jQuery].Member[sap].Member[syncPostText].ReturnValue", "remote"]
# UriParameters#get
# UriParameters#getAll
# UriParameters#get UriParameters#getAll
- ["sap/base/util/UriParameters", "Member[fromQuery].ReturnValue.Member[get].ReturnValue", "remote"]
- ["sap/base/util/UriParameters", "Member[fromQuery].ReturnValue.Member[getAll].ReturnValue", "remote"]
- addsTo:
Expand Down
77 changes: 0 additions & 77 deletions .github/workflows/codeql.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/codeql_queries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "CodeQL Queries"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '39 12 * * 2'

jobs:
analyze:
name: Analyze
runs-on: 'ubuntu-latest'
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,./src

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
1 change: 0 additions & 1 deletion codeql-workspace.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
provide:
- "**/qlpack.yml"
- "**/codeql-workspace.yml"
27 changes: 0 additions & 27 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,3 @@ Not fully working, meaning you cannot run `ui5 serve` and play with the app, tes
Anyways, here is the app's structure pertaining to the XSS vulnerability:

![Diagram of current app](./xss-example/diagram.svg "Diagram")

## xss-custom-control-api1
- custom Control
- classic string-based API
- `renderer` property is set to a render function

## xss-custom-control-api2
- custom Control
- DOM-like API
- `renderer` property is set to an object literal

## xss-custom-control-jquery
- custom Control declared using JQuery

## xss-html-control
- `sap.ui.core.HTML` Control

## xss-json-view
- `sap.ui.core.mvc.JSONView` View

## xss-separate-renderer
- `renderer` property is set to a class name (a string)
- Renderer implemented in it's own module

## xss-separate-renderer-byname
- `renderer` property is unassigned
- Renderer implemented in its own module with naming convention `<CustomControl>Renderer`
3 changes: 0 additions & 3 deletions integration-tests/codeql-workspace.yml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion ui5-models/qlpack.yml → src/qlpack.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
library: true
name: sap-js/ui5-models
name: sap-js/ui5
version: 0.0.1
extractor: javascript
dependencies:
codeql/javascript-all: "*"
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/**
* @id xss-custom-control
* @name XSS with custom control
* @kind problem
*/

import javascript
import UI5::UI5
import models.UI5::UI5
import semmle.javascript.security.dataflow.DomBasedXssQuery

class XssWithCustomControl extends Configuration {
Expand Down Expand Up @@ -41,4 +47,4 @@ class XssWithCustomControl extends Configuration {

from XssWithCustomControl xss, UnsafeHtmlXssSource source, UnsafeHtmlXssSink sink
where xss.hasFlow(source, sink)
select source, sink
select source, source.toString(), sink, sink.toString()
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions test/models/sink/sinkTest.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| sink.js:12:31:12:34 | code | code |
| sink.js:15:52:15:55 | code | code |
| sink.js:17:24:17:27 | code | code |
| sink.js:19:25:19:28 | code | code |
| sink.js:23:22:23:25 | code | code |
| sink.js:27:18:27:21 | code | code |
| sink.js:29:27:29:30 | code | code |
| sink.js:31:34:31:37 | code | code |
| sink.js:33:21:33:24 | code | code |
| sink.js:35:21:35:24 | code | code |
| sink.js:37:23:37:26 | code | code |
13 changes: 13 additions & 0 deletions test/models/sink/sinkTest.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @id xss-sinks
* @name XSS sinks
* @kind problem
*/

import javascript
import semmle.javascript.security.dataflow.DomBasedXssQuery
import models.UI5AMDModule

from DataFlow::Configuration cfg, DataFlow::Node sink
where cfg.isSink(sink, _)
select sink, sink.toString()
49 changes: 49 additions & 0 deletions test/models/source/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
sap.ui.require(["sap/m/SearchField", "sap/ui/commons/TextField", "sap/m/InputBase", "sap/m/Input", "sap/base/util/UriParameters"],
function (SearchField, TextField, InputBase, Input, UriParameters) {

////////
// Sources of user-controlled data
////////
// sap.ui.commons.SearchField.value
var f = new SearchField();
var remoteInput = f.value;
var remoteInput = f.getValue();

// sap.ui.commons.TextField.value
var f = new TextField();
var remoteInput = f.value;

// sap.m.InputBase.value
var ib = new InputBase();
remoteInput = ib.value;

// sap.m.Input.value
// sap.m.Input#setValue()
var input = new Input();
remoteInput = input.value;
remoteInput = input.getValue();

// jQuery.sap.getUriParameters() return
var value = jQuery.sap.getUriParameters().get("foo");

// jQuery.sap.syncHead return
var value = jQuery.sap.syncHead("url", "param")

// jQuery.sap.syncGet return
var value = jQuery.sap.syncGet("url", "param")

// jQuery.sap.syncGetText return
var value = jQuery.sap.syncGetText("url", "param")

// jQuery.sap.syncPost return
var value = jQuery.sap.syncPost("url", "param")

// jQuery.sap.syncPostText return
var value = jQuery.sap.syncPostText("url", "param")

// UriParameters#get
// UriParameters#getAll
var uri = UriParameters.fromQuery(window.location.search)
var sValue = uri.get("foo")
var sValue = uri.getAll("foo")
});
16 changes: 16 additions & 0 deletions test/models/source/sourceTest.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
| source.js:9:27:9:33 | f.value | f.value |
| source.js:10:27:10:36 | f.getValue | f.getValue |
| source.js:14:27:14:33 | f.value | f.value |
| source.js:18:23:18:30 | ib.value | ib.value |
| source.js:23:23:23:33 | input.value | input.value |
| source.js:24:23:24:38 | input.getValue() | input.getValue() |
| source.js:27:21:27:53 | jQuery. ... s().get | jQuery. ... s().get |
| source.js:30:21:30:55 | jQuery. ... param") | jQuery. ... param") |
| source.js:33:21:33:54 | jQuery. ... param") | jQuery. ... param") |
| source.js:36:21:36:58 | jQuery. ... param") | jQuery. ... param") |
| source.js:39:21:39:55 | jQuery. ... param") | jQuery. ... param") |
| source.js:42:21:42:59 | jQuery. ... param") | jQuery. ... param") |
| source.js:46:43:46:57 | window.location | window.location |
| source.js:46:43:46:64 | window. ... .search | window. ... .search |
| source.js:47:22:47:35 | uri.get("foo") | uri.get("foo") |
| source.js:48:22:48:38 | uri.getAll("foo") | uri.getAll("foo") |
10 changes: 8 additions & 2 deletions test/source/sourceTest.ql → test/models/source/sourceTest.ql
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* @id xss-sources
* @name XSS sources
* @kind problem
*/

import javascript
import semmle.javascript.security.dataflow.DomBasedXssQuery
import UI5AMDModule
import models.UI5AMDModule

from DataFlow::Configuration cfg, DataFlow::Node source
where cfg.isSource(source, _)
select source
select source, source.toString()
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions test/qlpack.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
library: false
name: sap-js/ui5-models-test
library: true
name: sap-js/ui5-test
version: 0.0.1
dependencies:
sap-js/ui5-models: "*"
extractor: javascript
dependencies:
sap-js/ui5: "*"
codeql/javascript-all: "*"
sap-js/ui5-data-extensions-pack: "*"
30 changes: 30 additions & 0 deletions test/queries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Queries unit tests

All XSS examples run locally using the [UI5 tooling](https://sap.github.io/ui5-tooling/stable/)

## xss-custom-control-api1
- custom Control
- classic string-based API
- `renderer` property is set to a render function

## xss-custom-control-api2
- custom Control
- DOM-like API
- `renderer` property is set to an object literal

## xss-custom-control-jquery
- custom Control declared using JQuery

## xss-html-control
- `sap.ui.core.HTML` Control

## xss-json-view
- `sap.ui.core.mvc.JSONView` View

## xss-separate-renderer
- `renderer` property is set to a class name (a string)
- Renderer implemented in it's own module

## xss-separate-renderer-byname
- `renderer` property is unassigned
- Renderer implemented in its own module with naming convention `<CustomControl>Renderer`
1 change: 1 addition & 0 deletions test/queries/XssWithCustomControl.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
queries/XssWithCustomControl.ql
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Input placeholder="Enter Payload"
description="Try: &lt;img src=x onerror=alert(&quot;XSS&quot;)&gt;"
value="{/input}" /> <!--User input source sap.m.Input.value -->
<core:HTML content="{/input}"/>
<core:HTML content="{/input}"/> <!--XSS sink sap.ui.core.HTML.content -->
</mvc:View>
Empty file removed test/sink/sinkTest.expected
Empty file.
Loading