Skip to content

Adds support for npm and xsjslib modules #143

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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b920fba
Adds support for npm and xsjslib
mbaluda Aug 26, 2024
2e6d302
Merge branch 'main' into mbaluda/xsjslib
mbaluda Aug 26, 2024
f31c6ee
Add support for XSS sanitizer lib
mbaluda Aug 28, 2024
f70a4e2
Reapply "Replace location in external file"
mbaluda Aug 28, 2024
3859a18
modify expected file
mbaluda Aug 28, 2024
44f7acf
Format cds files
mbaluda Aug 28, 2024
8b0b5ac
Fix url
mbaluda Aug 28, 2024
5aef039
changed query @id
mbaluda Aug 28, 2024
1530e1d
expected
mbaluda Aug 29, 2024
90ceb4c
update qlpack
mbaluda Aug 29, 2024
9845134
try using hasLocationInfo
mbaluda Aug 29, 2024
6d62c81
Merge branch 'main' into mbaluda/xsjslib
mbaluda Sep 3, 2024
6f25abd
Merge branch 'main' into mbaluda/external-cds
mbaluda Sep 6, 2024
aee5bd2
Update code_scanning.yml
mbaluda Sep 6, 2024
6d1b531
index cds files
mbaluda Sep 6, 2024
3b4c070
fix expected file
mbaluda Sep 6, 2024
fe09676
Correct location in tests and code scanning
mbaluda Sep 16, 2024
e298c08
Update expected SARIF file
mbaluda Sep 16, 2024
1672d5b
modify alert location
mbaluda Sep 16, 2024
f0b07bc
standardized query ids
mbaluda Sep 16, 2024
f524389
update expected file
mbaluda Sep 16, 2024
614695d
fix tests
mbaluda Sep 16, 2024
c035863
fix location
mbaluda Sep 16, 2024
d3810c4
Update expected files
mbaluda Sep 16, 2024
61bc15e
Merge branch 'mbaluda/external-cds' into mbaluda/xsjslib
mbaluda Sep 17, 2024
62c0d0a
Deals with external .cds files
mbaluda Sep 19, 2024
43b4427
Fix error message
mbaluda Sep 19, 2024
dce19fd
Error message updated based on SAP feedback
mbaluda Sep 19, 2024
c47778d
Address review
mbaluda Sep 20, 2024
a769f99
Update to CodeQL v2.19.0
mbaluda Sep 23, 2024
ce599be
Deals with external .cds files
mbaluda Sep 19, 2024
73ac321
Address review
mbaluda Sep 20, 2024
2ffb055
Update to CodeQL v2.19.0
mbaluda Sep 23, 2024
fe26838
Update code_scanning.yml
mbaluda Sep 6, 2024
ddbfcc9
index cds files
mbaluda Sep 6, 2024
18896cb
update expected file
mbaluda Sep 16, 2024
a310fd0
Xsjslib modules
mbaluda Sep 23, 2024
4ed1079
Merge branch 'mbaluda/cds' into mbaluda/xsjslib
mbaluda Sep 23, 2024
7f58632
Update expected file
mbaluda Sep 23, 2024
bbec0c7
xss-secure sanitizers
mbaluda Sep 24, 2024
cc8990d
XSJSLibModules
mbaluda Sep 26, 2024
21509a8
remove duplicated test
mbaluda Sep 26, 2024
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
7 changes: 4 additions & 3 deletions .github/workflows/code_scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

env:
LGTM_INDEX_XML_MODE: all
LGTM_INDEX_FILETYPES: ".json:JSON"
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"

jobs:
analyze-javascript:
Expand Down Expand Up @@ -52,7 +52,8 @@ jobs:
echo "I am compiling $cds_file"
cds compile $cds_file \
-2 json \
-o "$cds_file.json"
-o "$cds_file.json" \
--locations
done

- name: Extract CodeQL bundle version from qlt.conf.json
Expand All @@ -66,7 +67,7 @@ jobs:
config-file: ./.github/codeql/codeql-config.yaml
tools: https://github.com/github/codeql-action/releases/download/${{env.BUNDLE_VERSION}}/codeql-bundle-linux64.tar.gz
debug: true

- name: Perform CodeQL Analysis
id: analyze
uses: github/codeql-action/analyze@v3
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/javascript.sarif.expected

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .github/workflows/run-codeql-unit-tests-javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ jobs:
echo "I am compiling $cds_file"
cds compile $cds_file \
-2 json \
-o "$cds_file.json"
-o "$cds_file.json" \
--locations
done

- name: Run test suites
Expand Down
3 changes: 1 addition & 2 deletions javascript/frameworks/cap/ext/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ library: true
name: advanced-security/javascript-sap-cap-models
version: 0.3.0
extensionTargets:
codeql/javascript-all: "^1.1.1"
codeql/javascript-queries: "^1.1.0"
codeql/javascript-all: "^2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
import javascript
import advanced_security.javascript.frameworks.cap.CDS

abstract class CdlObject extends JsonObject {
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
exists(Location loc, JsonValue locValue |
loc = this.getLocation() and
locValue = this.getPropValue("$location") and
path =
any(File f |
f.getAbsolutePath()
.matches("%" + locValue.getPropValue("file").getStringValue() + ".json")
).getAbsolutePath().regexpReplaceAll("\\.json$", "") and
sl = locValue.getPropValue("line").getIntValue() and
sc = locValue.getPropValue("col").getIntValue() and
el = sl + 1 and
ec = 1
)
}
}

private newtype CdlKind =
CdlServiceKind(string value) { value = "service" } or
CdlEntityKind(string value) { value = "entity" } or
Expand All @@ -15,15 +33,15 @@ private newtype CdlKind =
/**
* Any CDL element, including entities, event, actions, and more.
*/
class CdlDefinition extends JsonObject {
class CdlDefinition extends CdlObject {
CdlDefinition() { exists(JsonObject root | this = root.getPropValue("definitions")) }

JsonObject getElement(string elementName) { result = this.getPropValue(elementName) }

JsonObject getAnElement() { result = this.getElement(_) }
}

abstract class CdlElement extends JsonObject {
abstract class CdlElement extends CdlObject {
CdlKind kind;
string name;

Expand Down Expand Up @@ -190,7 +208,7 @@ class CdlFunction extends CdlElement {
}
}

class CdlAttribute extends JsonObject {
class CdlAttribute extends CdlObject {
string name;

CdlAttribute() {
Expand All @@ -207,7 +225,7 @@ class CdlAttribute extends JsonObject {
/**
* a `CdlEntity` that is declared in a namespace
*/
class NamespacedEntity extends JsonObject instanceof CdlEntity {
class NamespacedEntity extends CdlObject instanceof CdlEntity {
string namespace;

NamespacedEntity() { this.getParent+().getPropValue("namespace").getStringValue() = namespace }
Expand All @@ -218,7 +236,7 @@ class NamespacedEntity extends JsonObject instanceof CdlEntity {
/**
* any `JsonValue` that has a `PersonalData` like annotation above it
*/
abstract class SensitiveAnnotatedElement extends JsonValue {
abstract class SensitiveAnnotatedElement extends CdlObject {
abstract string getName();
}

Expand Down Expand Up @@ -295,7 +313,7 @@ class RestrictAnnotation extends CdlAnnotation, JsonArray {
RestrictCondition getARestrictCondition() { result = this.getElementValue(_) }
}

class RestrictCondition extends JsonObject {
class RestrictCondition extends CdlObject {
RestrictCondition() { exists(RestrictAnnotation restrict | this = restrict.getElementValue(_)) }

predicate grants(string eventName) {
Expand Down
20 changes: 10 additions & 10 deletions javascript/frameworks/cap/lib/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
lockVersion: 1.0.0
dependencies:
codeql/dataflow:
version: 1.0.4
version: 1.1.2
codeql/javascript-all:
version: 1.1.1
version: 2.0.0
codeql/mad:
version: 1.0.4
version: 1.0.8
codeql/regex:
version: 1.0.4
version: 1.0.8
codeql/ssa:
version: 1.0.4
version: 1.0.8
codeql/tutorial:
version: 1.0.4
version: 1.0.8
codeql/typetracking:
version: 1.0.4
version: 1.0.8
codeql/util:
version: 1.0.4
version: 1.0.8
codeql/xml:
version: 1.0.4
version: 1.0.8
codeql/yaml:
version: 1.0.4
version: 1.0.8
compiled: false
2 changes: 1 addition & 1 deletion javascript/frameworks/cap/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ version: 0.3.0
suites: codeql-suites
extractor: javascript
dependencies:
codeql/javascript-all: "^1.1.1"
codeql/javascript-all: "^2.0.0"
advanced-security/javascript-sap-cap-models: "^0.3.0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @problem.severity error
* @security-severity 6
* @precision high
* @id js/default-user-is-privileged
* @id js/cap-default-user-is-privileged
* @tags security
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
* @problem.severity warning
* @security-severity 6
* @precision high
* @id js/entity-exposed-without-authentication
* @id js/cap-entity-exposed-without-authentication
* @tags security
*/

import advanced_security.javascript.frameworks.cap.CAPNoAuthzQuery

/*
* TODO: Revamp this predicate after we start to natively support CDS.
* string getClickableText(CdlElement cdlElement) {
* cdlElement instanceof CdlService and result = "CDS service"
* or
* cdlElement instanceof CdlEntity and result = "CDS entity"
* or
* cdlElement instanceof CdlAction and result = "CDS action"
* or
* cdlElement instanceof CdlFunction and result = "CDS function"
* }
*/
string getClickableText(CdlElement cdlElement) {
cdlElement instanceof CdlService and result = "CDS service"
or
cdlElement instanceof CdlEntity and result = "CDS entity"
or
cdlElement instanceof CdlAction and result = "CDS action"
or
cdlElement instanceof CdlFunction and result = "CDS function"
}

from CdlElement cdlElement
where
cdlElement instanceof CdlElementWithoutJsAuthn and
cdlElement instanceof CdlElementWithoutCdsAuthn
select cdlElement, "This CDS definition is exposed without any authentication."
select cdlElement,
"The " + getClickableText(cdlElement) + " `" + cdlElement.getName() +
"` is exposed without any authentication."
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @problem.severity error
* @security-severity 6
* @precision high
* @id js/unnecessarily-granted-privileged-access-rights
* @id js/cap-unnecessarily-granted-privileged-access-rights
* @tags security
*/

Expand Down
20 changes: 10 additions & 10 deletions javascript/frameworks/cap/src/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
lockVersion: 1.0.0
dependencies:
codeql/dataflow:
version: 1.0.4
version: 1.1.2
codeql/javascript-all:
version: 1.1.1
version: 2.0.0
codeql/mad:
version: 1.0.4
version: 1.0.8
codeql/regex:
version: 1.0.4
version: 1.0.8
codeql/ssa:
version: 1.0.4
version: 1.0.8
codeql/tutorial:
version: 1.0.4
version: 1.0.8
codeql/typetracking:
version: 1.0.4
version: 1.0.8
codeql/util:
version: 1.0.4
version: 1.0.8
codeql/xml:
version: 1.0.4
version: 1.0.8
codeql/yaml:
version: 1.0.4
version: 1.0.8
compiled: false
2 changes: 1 addition & 1 deletion javascript/frameworks/cap/src/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 0.3.0
suites: codeql-suites
extractor: javascript
dependencies:
codeql/javascript-all: "^1.1.1"
codeql/javascript-all: "^2.0.0"
advanced-security/javascript-sap-cap-models: "^0.3.0"
advanced-security/javascript-sap-cap-all: "^0.3.0"
default-suite-file: codeql-suites/javascript-code-scanning.qls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @problem.severity warning
* @security-severity 7.5
* @precision medium
* @id js/sensitive-log
* @id js/cap-sensitive-log
* @tags security
* external/cwe/cwe-532
*/
Expand Down Expand Up @@ -43,6 +43,8 @@ class SensitiveExposureFieldSource extends DataFlow::Node {
//and the namespace is the same (fully qualified id match)
entity.(NamespacedEntity).getNamespace() = namespace
}

SensitiveAnnotatedAttribute getCdsField() { result = cdsField }
}

class SensitiveLogExposureConfig extends TaintTracking::Configuration {
Expand All @@ -57,4 +59,7 @@ class SensitiveLogExposureConfig extends TaintTracking::Configuration {

from SensitiveLogExposureConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
select sink, source, sink, "Log entry depends on a potentially sensitive piece of information."
select sink, source, sink,
"Log entry depends on the $@ field which is annotated as potentially sensitive.",
source.getNode().(SensitiveExposureFieldSource).getCdsField(),
source.getNode().(SensitiveExposureFieldSource).getCdsField().getName()
26 changes: 10 additions & 16 deletions javascript/frameworks/cap/test/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
lockVersion: 1.0.0
dependencies:
codeql/dataflow:
version: 1.0.4
version: 1.1.2
codeql/javascript-all:
version: 1.1.1
codeql/javascript-queries:
version: 1.1.0
version: 2.0.0
codeql/mad:
version: 1.0.4
version: 1.0.8
codeql/regex:
version: 1.0.4
version: 1.0.8
codeql/ssa:
version: 1.0.4
codeql/suite-helpers:
version: 1.0.4
version: 1.0.8
codeql/tutorial:
version: 1.0.4
version: 1.0.8
codeql/typetracking:
version: 1.0.4
codeql/typos:
version: 1.0.4
version: 1.0.8
codeql/util:
version: 1.0.4
version: 1.0.8
codeql/xml:
version: 1.0.4
version: 1.0.8
codeql/yaml:
version: 1.0.4
version: 1.0.8
compiled: false
3 changes: 1 addition & 2 deletions javascript/frameworks/cap/test/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: advanced-security/javascript-sap-cap-queries-tests
version: 0.3.0
extractor: javascript
dependencies:
codeql/javascript-all: "^1.1.1"
codeql/javascript-queries: "^1.1.0"
codeql/javascript-all: "^2.0.0"
advanced-security/javascript-sap-cap-queries: "^0.3.0"
advanced-security/javascript-sap-cap-models: "^0.3.0"
advanced-security/javascript-sap-cap-all: "^0.3.0"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| srv/service1.cds.json:3:17:7:5 | {\\n ... "\\n } | This CDS definition is exposed without any authentication. |
| srv/service1.cds.json:8:32:26:5 | {\\n ... }\\n } | This CDS definition is exposed without any authentication. |
| srv/service1.cds.json:27:23:37:5 | {\\n ... }\\n } | This CDS definition is exposed without any authentication. |
| srv/service2.cds.json:3:17:7:5 | {\\n ... "\\n } | This CDS definition is exposed without any authentication. |
| srv/service2.cds.json:8:32:26:5 | {\\n ... }\\n } | This CDS definition is exposed without any authentication. |
| srv/service2.cds.json:27:23:37:5 | {\\n ... }\\n } | This CDS definition is exposed without any authentication. |
| srv/service1.cds:3:9:4:1 | {\\n ... }\\n } | The CDS service `Service1` is exposed without any authentication. |
| srv/service1.cds:5:10:6:1 | {\\n ... }\\n } | The CDS entity `Service1.Service1Entity` is exposed without any authentication. |
| srv/service1.cds:8:10:9:1 | {\\n ... }\\n } | The CDS action `Service1.send1` is exposed without any authentication. |
| srv/service2.cds:3:9:4:1 | {\\n ... }\\n } | The CDS service `Service2` is exposed without any authentication. |
| srv/service2.cds:5:10:6:1 | {\\n ... }\\n } | The CDS entity `Service2.Service2Entity` is exposed without any authentication. |
| srv/service2.cds:8:10:9:1 | {\\n ... }\\n } | The CDS action `Service2.send2` is exposed without any authentication. |
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

(cd $CODEQL_EXTRACTOR_JAVASCRIPT_WIP_DATABASE && pwd && for cds_file in $(find . -type f \( -iname '*.cds' \) -print ); do cds compile $cds_file -2 json -o "$(dirname $cds_file)/$(basename $cds_file .cds).json"; done)
(cd $CODEQL_EXTRACTOR_JAVASCRIPT_WIP_DATABASE && pwd && for cds_file in $(find . -type f \( -iname '*.cds' \) -print ); do cds compile $cds_file -2 json -o "$(dirname $cds_file)/$(basename $cds_file .cds).json" --locations; done)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
nodes
| sensitive-exposure.js:10:32:10:42 | Sample.name |
| sensitive-exposure.js:10:32:10:42 | Sample.name |
| sensitive-exposure.js:10:32:10:42 | Sample.name |
| sensitive-exposure.js:9:32:9:42 | Sample.name |
| sensitive-exposure.js:9:32:9:42 | Sample.name |
| sensitive-exposure.js:9:32:9:42 | Sample.name |
edges
| sensitive-exposure.js:10:32:10:42 | Sample.name | sensitive-exposure.js:10:32:10:42 | Sample.name |
| sensitive-exposure.js:9:32:9:42 | Sample.name | sensitive-exposure.js:9:32:9:42 | Sample.name |
#select
| sensitive-exposure.js:10:32:10:42 | Sample.name | sensitive-exposure.js:10:32:10:42 | Sample.name | sensitive-exposure.js:10:32:10:42 | Sample.name | Log entry depends on a potentially sensitive piece of information. |
| sensitive-exposure.js:9:32:9:42 | Sample.name | sensitive-exposure.js:9:32:9:42 | Sample.name | sensitive-exposure.js:9:32:9:42 | Sample.name | Log entry depends on the $@ field which is annotated as potentially sensitive. | sensitive-exposure.cds:4:5:5:1 | {\\n ... } | name |
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const { Sample } = cds.entities('advanced_security.log_exposure.sample_entities'

class SampleVulnService extends cds.ApplicationService {
init() {
/* A sensitive info log sink. */

/* A sensitive info log sink. */
LOG.info("Received: ", Sample.name); // CAP log exposure alert
}

Expand Down
2 changes: 1 addition & 1 deletion javascript/frameworks/ui5/ext/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ library: true
name: advanced-security/javascript-sap-ui5-models
version: 0.6.0
extensionTargets:
codeql/javascript-all: "^1.1.1"
codeql/javascript-all: "^2.0.0"
dataExtensions:
- "*.model.yml"
Loading
Loading