Skip to content

Commit 6d548c0

Browse files
Merge pull request #113 from advanced-security/jeongsoolee09/auth-queries
Implement queries for authentication / authorization related issues
2 parents 0b78c55 + 1a4f8b6 commit 6d548c0

File tree

87 files changed

+4000
-410
lines changed

Some content is hidden

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

87 files changed

+4000
-410
lines changed

.github/workflows/javascript.sarif.expected

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import advanced_security.javascript.frameworks.cap.CDS
2+
import advanced_security.javascript.frameworks.cap.CDL
3+
import advanced_security.javascript.frameworks.cap.Conditionals
4+
5+
abstract class CdlElementWithoutAuthn instanceof CdlElement {
6+
string toString() { result = super.toString() }
7+
8+
Location getLocation() { result = super.getLocation() }
9+
}
10+
11+
abstract class CdlElementWithoutCdsAuthn extends CdlElementWithoutAuthn instanceof CdlElement {
12+
CdlElementWithoutCdsAuthn() { this.hasNoCdsAccessControl() }
13+
}
14+
15+
class CdlServiceWithoutCdsAuthn extends CdlElementWithoutCdsAuthn instanceof CdlService { }
16+
17+
class CdlEntityWithoutCdsAuthn extends CdlElementWithoutCdsAuthn instanceof CdlEntity {
18+
CdlEntityWithoutCdsAuthn() {
19+
this.belongsToServiceWithNoAuthn()
20+
or
21+
exists(CdlEntityWithoutCdsAuthn otherCdlEntityWithoutCdsAuthn |
22+
this.inherits(otherCdlEntityWithoutCdsAuthn)
23+
)
24+
}
25+
}
26+
27+
class CdlActionWithoutCdsAuthn extends CdlElementWithoutCdsAuthn instanceof CdlAction {
28+
CdlActionWithoutCdsAuthn() { this.belongsToServiceWithNoAuthn() }
29+
}
30+
31+
class CdlFunctionWithoutCdsAuthn extends CdlElementWithoutCdsAuthn instanceof CdlAction {
32+
CdlFunctionWithoutCdsAuthn() { this.belongsToServiceWithNoAuthn() }
33+
}
34+
35+
class CdlElementProtectionWithHandlerRegistration instanceof HandlerRegistration {
36+
string toString() { result = super.toString() }
37+
38+
predicate hasLocationInfo(
39+
string filepath, int startline, int startcolumn, int endline, int endcolumn
40+
) {
41+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
42+
}
43+
44+
CdlElementProtectionWithHandlerRegistration() {
45+
(
46+
this.isBefore()
47+
or
48+
this.isOn()
49+
) and
50+
exists(Handler handler, ConditionalExprOrStatement exprOrStmt |
51+
handler = this.getHandler() and
52+
(
53+
exprOrStmt = handler.getFunction().getBody() or
54+
exprOrStmt = handler.getFunction().getABodyStmt()
55+
)
56+
|
57+
exprOrStmt.getConditionExpr().getAChildExpr*().flow() instanceof RequestUserIs and
58+
exists(CdsRequest req |
59+
exprOrStmt.getPolarity() = true and
60+
exprOrStmt.getAnElseBranchExpr() = req.getARejectCall().asExpr()
61+
or
62+
exprOrStmt.getPolarity() = false and
63+
exprOrStmt.getAThenBranchExpr() = req.getARejectCall().asExpr()
64+
)
65+
)
66+
}
67+
68+
string getEntityName() { result = super.getEntityName() }
69+
70+
string getAnEventName() { result = super.getAnEventName() }
71+
}
72+
73+
abstract class CdlElementWithJsAuthn instanceof CdlElement {
74+
string toString() { result = super.toString() }
75+
76+
Location getLocation() { result = super.getLocation() }
77+
}
78+
79+
class CdlServiceWithJsAuthn extends CdlElementWithJsAuthn instanceof CdlService {
80+
CdlServiceWithJsAuthn() {
81+
exists(CdlElementProtectionWithHandlerRegistration beforeOrOn |
82+
this.getImplementation().getAHandlerRegistration() = beforeOrOn or
83+
this.getCdsServeCall().getWithCall().getAHandlerRegistration() = beforeOrOn
84+
|
85+
beforeOrOn.getAnEventName() = "*"
86+
)
87+
}
88+
}
89+
90+
class CdlEntityWithJsAuthn extends CdlElementWithJsAuthn instanceof CdlEntity {
91+
CdlEntityWithJsAuthn() {
92+
exists(CdlService service, CdlElementProtectionWithHandlerRegistration beforeOrOn |
93+
this = service.getAnEntity() and
94+
(
95+
service.getImplementation().getAHandlerRegistration() = beforeOrOn or
96+
service.getCdsServeCall().getWithCall().getAHandlerRegistration() = beforeOrOn
97+
) and
98+
beforeOrOn.getEntityName() = this.getUnqualifiedName()
99+
)
100+
}
101+
}
102+
103+
class CdlActionWithJsAuthn extends CdlElementWithJsAuthn instanceof CdlAction {
104+
CdlActionWithJsAuthn() {
105+
exists(CdlService service, CdlElementProtectionWithHandlerRegistration beforeOrOn |
106+
this = service.getAnAction() and
107+
(
108+
service.getImplementation().getAHandlerRegistration() = beforeOrOn or
109+
service.getCdsServeCall().getWithCall().getAHandlerRegistration() = beforeOrOn
110+
) and
111+
beforeOrOn.getAnEventName() = this.getUnqualifiedName()
112+
)
113+
}
114+
}
115+
116+
class CdlFunctionWithJsAuthn extends CdlElementWithJsAuthn instanceof CdlFunction {
117+
CdlFunctionWithJsAuthn() {
118+
exists(CdlService service, CdlElementProtectionWithHandlerRegistration beforeOrOn |
119+
this = service.getAFunction() and
120+
(
121+
service.getImplementation().getAHandlerRegistration() = beforeOrOn or
122+
service.getCdsServeCall().getWithCall().getAHandlerRegistration() = beforeOrOn
123+
) and
124+
beforeOrOn.getAnEventName() = this.getUnqualifiedName()
125+
)
126+
}
127+
}
128+
129+
abstract class CdlElementWithoutJsAuthn extends CdlElementWithoutAuthn instanceof CdlElement { }
130+
131+
class CdlServiceWithoutJsAuthn extends CdlElementWithoutJsAuthn instanceof CdlService {
132+
CdlServiceWithoutJsAuthn() { not this instanceof CdlServiceWithJsAuthn }
133+
}
134+
135+
class CdlEntityWithoutJsAuthn extends CdlElementWithoutJsAuthn instanceof CdlEntity {
136+
CdlEntityWithoutJsAuthn() { not this instanceof CdlEntityWithJsAuthn }
137+
}
138+
139+
class CdlActionWithoutJsAuthn extends CdlElementWithoutJsAuthn instanceof CdlAction {
140+
CdlActionWithoutJsAuthn() { not this instanceof CdlActionWithJsAuthn }
141+
}
142+
143+
class CdlFunctionWithoutJsAuthn extends CdlElementWithoutJsAuthn instanceof CdlFunction {
144+
CdlFunctionWithoutJsAuthn() { not this instanceof CdlFunctionWithJsAuthn }
145+
}
146+
147+
/**
148+
* The access to property `user` of a handler's request.
149+
*/
150+
class RequestUser extends SourceNode instanceof PropRef {
151+
RequestUser() {
152+
exists(Handler handler |
153+
this.getBase().getALocalSource() = handler.getRequest() and
154+
this.getPropertyName() = "user"
155+
)
156+
}
157+
}
158+
159+
class RequestUserIs instanceof MethodCallNode {
160+
string userRole;
161+
162+
RequestUserIs() {
163+
exists(RequestUser requestUser |
164+
this = requestUser.getAMethodCall("is") and
165+
userRole = this.getArgument(0).getStringValue()
166+
)
167+
}
168+
169+
string toString() { result = super.toString() }
170+
}

0 commit comments

Comments
 (0)