Skip to content

Commit 7c97de6

Browse files
authored
Deals with external .cds files (#150)
- Update CodeQL version to v2.19.0 - Standardize query ids - Include `.cds` files in the DB - Implement `CdlObject` location in the `.cds` file - Modified `EntityExposedWithoutAuthn` error message to include the name of the exposed element - Modified `SensitiveExposure` error message to include the name of the exposed element
1 parent bd55222 commit 7c97de6

File tree

37 files changed

+188
-180
lines changed

37 files changed

+188
-180
lines changed

.github/workflows/code_scanning.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
env:
1414
LGTM_INDEX_XML_MODE: all
15-
LGTM_INDEX_FILETYPES: ".json:JSON"
15+
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"
1616

1717
jobs:
1818
analyze-javascript:
@@ -52,7 +52,8 @@ jobs:
5252
echo "I am compiling $cds_file"
5353
cds compile $cds_file \
5454
-2 json \
55-
-o "$cds_file.json"
55+
-o "$cds_file.json" \
56+
--locations
5657
done
5758
5859
- name: Extract CodeQL bundle version from qlt.conf.json
@@ -66,7 +67,7 @@ jobs:
6667
config-file: ./.github/codeql/codeql-config.yaml
6768
tools: https://github.com/github/codeql-action/releases/download/${{env.BUNDLE_VERSION}}/codeql-bundle-linux64.tar.gz
6869
debug: true
69-
70+
7071
- name: Perform CodeQL Analysis
7172
id: analyze
7273
uses: github/codeql-action/analyze@v3

.github/workflows/javascript.sarif.expected

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

.github/workflows/run-codeql-unit-tests-javascript.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ jobs:
9292
echo "I am compiling $cds_file"
9393
cds compile $cds_file \
9494
-2 json \
95-
-o "$cds_file.json"
95+
-o "$cds_file.json" \
96+
--locations
9697
done
9798
9899
- name: Run test suites

javascript/frameworks/cap/ext/qlpack.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ library: true
33
name: advanced-security/javascript-sap-cap-models
44
version: 0.3.0
55
extensionTargets:
6-
codeql/javascript-all: "^1.1.1"
7-
codeql/javascript-queries: "^1.1.0"
6+
codeql/javascript-all: "^2.0.0"

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/CDL.qll

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
import javascript
66
import advanced_security.javascript.frameworks.cap.CDS
77

8+
abstract class CdlObject extends JsonObject {
9+
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
10+
exists(Location loc, JsonValue locValue |
11+
loc = this.getLocation() and
12+
locValue = this.getPropValue("$location") and
13+
path =
14+
any(File f |
15+
f.getAbsolutePath()
16+
.matches("%" + locValue.getPropValue("file").getStringValue() + ".json")
17+
).getAbsolutePath().regexpReplaceAll("\\.json$", "") and
18+
sl = locValue.getPropValue("line").getIntValue() and
19+
sc = locValue.getPropValue("col").getIntValue() and
20+
el = sl + 1 and
21+
ec = 1
22+
)
23+
}
24+
}
25+
826
private newtype CdlKind =
927
CdlServiceKind(string value) { value = "service" } or
1028
CdlEntityKind(string value) { value = "entity" } or
@@ -15,15 +33,15 @@ private newtype CdlKind =
1533
/**
1634
* Any CDL element, including entities, event, actions, and more.
1735
*/
18-
class CdlDefinition extends JsonObject {
36+
class CdlDefinition extends CdlObject {
1937
CdlDefinition() { exists(JsonObject root | this = root.getPropValue("definitions")) }
2038

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

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

26-
abstract class CdlElement extends JsonObject {
44+
abstract class CdlElement extends CdlObject {
2745
CdlKind kind;
2846
string name;
2947

@@ -190,7 +208,7 @@ class CdlFunction extends CdlElement {
190208
}
191209
}
192210

193-
class CdlAttribute extends JsonObject {
211+
class CdlAttribute extends CdlObject {
194212
string name;
195213

196214
CdlAttribute() {
@@ -207,7 +225,7 @@ class CdlAttribute extends JsonObject {
207225
/**
208226
* a `CdlEntity` that is declared in a namespace
209227
*/
210-
class NamespacedEntity extends JsonObject instanceof CdlEntity {
228+
class NamespacedEntity extends CdlObject instanceof CdlEntity {
211229
string namespace;
212230

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

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

298-
class RestrictCondition extends JsonObject {
316+
class RestrictCondition extends CdlObject {
299317
RestrictCondition() { exists(RestrictAnnotation restrict | this = restrict.getElementValue(_)) }
300318

301319
predicate grants(string eventName) {

javascript/frameworks/cap/lib/codeql-pack.lock.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
lockVersion: 1.0.0
33
dependencies:
44
codeql/dataflow:
5-
version: 1.0.4
5+
version: 1.1.2
66
codeql/javascript-all:
7-
version: 1.1.1
7+
version: 2.0.0
88
codeql/mad:
9-
version: 1.0.4
9+
version: 1.0.8
1010
codeql/regex:
11-
version: 1.0.4
11+
version: 1.0.8
1212
codeql/ssa:
13-
version: 1.0.4
13+
version: 1.0.8
1414
codeql/tutorial:
15-
version: 1.0.4
15+
version: 1.0.8
1616
codeql/typetracking:
17-
version: 1.0.4
17+
version: 1.0.8
1818
codeql/util:
19-
version: 1.0.4
19+
version: 1.0.8
2020
codeql/xml:
21-
version: 1.0.4
21+
version: 1.0.8
2222
codeql/yaml:
23-
version: 1.0.4
23+
version: 1.0.8
2424
compiled: false

javascript/frameworks/cap/lib/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ version: 0.3.0
55
suites: codeql-suites
66
extractor: javascript
77
dependencies:
8-
codeql/javascript-all: "^1.1.1"
8+
codeql/javascript-all: "^2.0.0"
99
advanced-security/javascript-sap-cap-models: "^0.3.0"

javascript/frameworks/cap/src/bad-authn-authz/DefaultUserIsPrivileged/DefaultUserIsPrivileged.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @problem.severity error
66
* @security-severity 6
77
* @precision high
8-
* @id js/default-user-is-privileged
8+
* @id js/cap-default-user-is-privileged
99
* @tags security
1010
*/
1111

javascript/frameworks/cap/src/bad-authn-authz/EntityExposedWithoutAuthn/EntityExposedWithoutAuthn.ql

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@
66
* @problem.severity warning
77
* @security-severity 6
88
* @precision high
9-
* @id js/entity-exposed-without-authentication
9+
* @id js/cap-entity-exposed-without-authentication
1010
* @tags security
1111
*/
1212

1313
import advanced_security.javascript.frameworks.cap.CAPNoAuthzQuery
1414

15-
/*
16-
* TODO: Revamp this predicate after we start to natively support CDS.
17-
* string getClickableText(CdlElement cdlElement) {
18-
* cdlElement instanceof CdlService and result = "CDS service"
19-
* or
20-
* cdlElement instanceof CdlEntity and result = "CDS entity"
21-
* or
22-
* cdlElement instanceof CdlAction and result = "CDS action"
23-
* or
24-
* cdlElement instanceof CdlFunction and result = "CDS function"
25-
* }
26-
*/
15+
string getClickableText(CdlElement cdlElement) {
16+
cdlElement instanceof CdlService and result = "CDS service"
17+
or
18+
cdlElement instanceof CdlEntity and result = "CDS entity"
19+
or
20+
cdlElement instanceof CdlAction and result = "CDS action"
21+
or
22+
cdlElement instanceof CdlFunction and result = "CDS function"
23+
}
2724

2825
from CdlElement cdlElement
2926
where
3027
cdlElement instanceof CdlElementWithoutJsAuthn and
3128
cdlElement instanceof CdlElementWithoutCdsAuthn
32-
select cdlElement, "This CDS definition is exposed without any authentication."
29+
select cdlElement,
30+
"The " + getClickableText(cdlElement) + " `" + cdlElement.getName() +
31+
"` is exposed without any authentication."

javascript/frameworks/cap/src/bad-authn-authz/UnnecessarilyGrantedPrivilegedAccessRights/UnnecessarilyGrantedPrivilegedAccessRights.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @problem.severity error
66
* @security-severity 6
77
* @precision high
8-
* @id js/unnecessarily-granted-privileged-access-rights
8+
* @id js/cap-unnecessarily-granted-privileged-access-rights
99
* @tags security
1010
*/
1111

0 commit comments

Comments
 (0)