Skip to content

Commit 67b71a3

Browse files
Implement UnnecessarilyGrantedPrivilegedAccessRights (#139)
- Add UnnecessarilyGrantedPrivilegedAccessRights.ql query. - Fix wrong assumptions on cds.requires in test cases: previously cds.requires had service-1 and service-2.
1 parent 4b2580a commit 67b71a3

File tree

50 files changed

+458
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+458
-297
lines changed

.github/workflows/javascript.sarif.expected

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import javascript
2+
import advanced_security.javascript.frameworks.cap.CDS
3+
4+
/**
5+
* A reference to an entity that is defined in this application.
6+
*/
7+
class LocalEntityReference instanceof EntityReference {
8+
LocalEntityReference() { not this instanceof RemoteEntityReference }
9+
10+
string toString() { result = super.toString() }
11+
12+
Location getLocation() { result = super.getLocation() }
13+
14+
predicate hasRestrictedAccessControl() {
15+
exists(RestrictCondition restrict |
16+
restrict =
17+
this.(EntityReference).getCqlDefinition().getRestrictAnnotation().getARestrictCondition()
18+
|
19+
not restrict.grantsToAnyone(_)
20+
)
21+
}
22+
}
23+
24+
/**
25+
* A reference to an entity that is not defined in this application and
26+
* read from a service instance that is looked up with the name defined in
27+
* package.json.
28+
*/
29+
class RemoteEntityReference instanceof EntityReference {
30+
RemoteEntityReference() { not exists(this.getCqlDefinition()) }
31+
32+
string toString() { result = super.toString() }
33+
34+
Location getLocation() { result = super.getLocation() }
35+
}
36+
37+
abstract class PrivilegedUserInstance extends DataFlow::NewNode { }
38+
39+
class CdsUserPrivilegedProperty extends PrivilegedUserInstance {
40+
CdsUserPrivilegedProperty() {
41+
exists(CdsUser cdsUser |
42+
this =
43+
cdsUser.getInducingNode().(PropRead).getAPropertyRead("Privileged").getAnInstantiation()
44+
)
45+
}
46+
}
47+
48+
class CustomPrivilegedUser extends ClassNode {
49+
CustomPrivilegedUser() {
50+
exists(CdsUser cdsUser | this.getASuperClassNode() = cdsUser.asSource()) and
51+
exists(FunctionNode init |
52+
init = this.getInstanceMethod("is") and
53+
forall(Expr expr | expr = init.asExpr().(Function).getAReturnedExpr() |
54+
expr.mayHaveBooleanValue(true)
55+
)
56+
)
57+
}
58+
}
59+
60+
class CustomPrivilegedUserInstance extends PrivilegedUserInstance, NewNode {
61+
CustomPrivilegedUserInstance() {
62+
exists(CustomPrivilegedUser customPrivilegedUserClass |
63+
this = customPrivilegedUserClass.getAnInstantiation()
64+
)
65+
}
66+
}

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ abstract class CdlElement extends JsonObject {
3434
*/
3535
string getName() { result = name }
3636

37+
/**
38+
* Gets the unqualified name of this CDL element without the leading namespace.
39+
*/
40+
string getUnqualifiedName() {
41+
exists(string qualifiedName | qualifiedName = this.getName() |
42+
result = qualifiedName.splitAt(".", count(qualifiedName.indexOf(".")))
43+
)
44+
}
45+
3746
/**
3847
* Gets the kind of this CDL element.
3948
*/
@@ -128,12 +137,6 @@ class CdlService extends CdlElement {
128137
class CdlEntity extends CdlElement {
129138
CdlEntity() { kind = CdlEntityKind(this.getPropStringValue("kind")) }
130139

131-
string getUnqualifiedName() {
132-
exists(string qualifiedName | qualifiedName = this.getName() |
133-
result = qualifiedName.splitAt(".", count(qualifiedName.indexOf(".")))
134-
)
135-
}
136-
137140
predicate isSelectFrom(CdlEntity otherEntity) {
138141
otherEntity.getName() =
139142
this.getPropValue("query")
@@ -166,24 +169,12 @@ class CdlEntity extends CdlElement {
166169
class CdlEvent extends CdlElement {
167170
CdlEvent() { kind = CdlEventKind(this.getPropStringValue("kind")) }
168171

169-
string getUnqualifiedName() {
170-
exists(string qualifiedName | qualifiedName = this.getName() |
171-
result = qualifiedName.splitAt(".", count(qualifiedName.indexOf(".")))
172-
)
173-
}
174-
175172
string getBasename() { result = name.splitAt(".", count(name.indexOf("."))) }
176173
}
177174

178175
class CdlAction extends CdlElement {
179176
CdlAction() { kind = CdlActionKind(this.getPropStringValue("kind")) }
180177

181-
string getUnqualifiedName() {
182-
exists(string qualifiedName | qualifiedName = this.getName() |
183-
result = qualifiedName.splitAt(".", count(qualifiedName.indexOf(".")))
184-
)
185-
}
186-
187178
predicate belongsToServiceWithNoAuthn() {
188179
exists(CdlService service | service.hasNoCdsAccessControl() | this = service.getAnAction())
189180
}
@@ -194,12 +185,6 @@ class CdlFunction extends CdlElement {
194185

195186
JsonObject getReturns() { result = this.getPropValue("returns") }
196187

197-
string getUnqualifiedName() {
198-
exists(string qualifiedName | qualifiedName = this.getName() |
199-
result = qualifiedName.splitAt(".", count(qualifiedName.indexOf(".")))
200-
)
201-
}
202-
203188
predicate belongsToServiceWithNoAuthn() {
204189
exists(CdlService service | service.hasNoCdsAccessControl() | this = service.getAFunction())
205190
}

0 commit comments

Comments
 (0)