Skip to content

Commit 19a5db9

Browse files
committed
JS: Rename getARhs -> getASink
1 parent 4c61926 commit 19a5db9

32 files changed

Lines changed: 126 additions & 116 deletions

javascript/ql/lib/semmle/javascript/ApiGraphs.qll

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,26 +187,36 @@ module API {
187187
InvokeNode getAnInvocation() { result = this.getACall() or result = this.getAnInstantiation() }
188188

189189
/**
190-
* Gets a data-flow node corresponding to the right-hand side of a definition of the API
191-
* component represented by this node.
190+
* Get a data-flow node where this value leaves the current codebase and flows into an
191+
* external library (or in general, any external codebase).
192192
*
193-
* For example, in the assignment `exports.plusOne = (x) => x+1`, the function expression
194-
* `(x) => x+1` is the right-hand side of the definition of the member `plusOne` of
195-
* the enclosing module, and the expression `x+1` is the right-had side of the definition of
196-
* its result.
193+
* Concretely, this is either an argument passed to a call to external code,
194+
* or the right-hand side of a property write on an object flows into such a call.
197195
*
198-
* Note that for parameters, it is the arguments flowing into that parameter that count as
199-
* right-hand sides of the definition, not the declaration of the parameter itself.
200-
* Consequently, in `require('fs').readFileSync(file)`, `file` is the right-hand
201-
* side of a definition of the first parameter of `readFileSync` from the `fs` module.
196+
* For example:
197+
* ```js
198+
* // 'x' is matched by API::moduleImport("foo").getParameter(0).getASink()
199+
* require('foo')(x);
200+
*
201+
* // 'x' is matched by API::moduleImport("foo").getParameter(0).getMember("prop").getASink()
202+
* require('foo')({
203+
* prop: x
204+
* });
205+
* ```
202206
*/
203-
DataFlow::Node getARhs() { Impl::rhs(this, result) }
207+
DataFlow::Node getASink() { Impl::rhs(this, result) }
204208

205209
/**
206210
* Gets a data-flow node that may interprocedurally flow to the right-hand side of a definition
207211
* of the API component represented by this node.
208212
*/
209-
DataFlow::Node getAValueReachingRhs() { result = Impl::trackDefNode(this.getARhs()) }
213+
DataFlow::Node getAValueReachingSink() { result = Impl::trackDefNode(this.getASink()) }
214+
215+
/** DEPRECATED. This predicate has been renamed to `getASink`. */
216+
deprecated DataFlow::Node getARhs() { result = this.getASink() }
217+
218+
/** DEPRECATED. This predicate has been renamed to `getAValueReachingSink`. */
219+
deprecated DataFlow::Node getAValueReachingRhs() { result = this.getAValueReachingSink() }
210220

211221
/**
212222
* Gets a node representing member `m` of this API component.
@@ -441,7 +451,7 @@ module API {
441451
* In other words, the value of a use of `that` may flow into the right-hand side of a
442452
* definition of this node.
443453
*/
444-
predicate refersTo(Node that) { this.getARhs() = that.getAValueReachableFromSource() }
454+
predicate refersTo(Node that) { this.getASink() = that.getAValueReachableFromSource() }
445455

446456
/**
447457
* Gets the data-flow node that gives rise to this node, if any.
@@ -1301,7 +1311,7 @@ module API {
13011311
* Gets an API node where a RHS of the node is the `i`th argument to this call.
13021312
*/
13031313
pragma[noinline]
1304-
private Node getAParameterCandidate(int i) { result.getARhs() = this.getArgument(i) }
1314+
private Node getAParameterCandidate(int i) { result.getASink() = this.getArgument(i) }
13051315

13061316
/** Gets the API node for a parameter of this invocation. */
13071317
Node getAParameter() { result = this.getParameter(_) }

javascript/ql/lib/semmle/javascript/JsonSchema.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module JsonSchema {
134134
.ref()
135135
.getMember(["addSchema", "validate", "compile", "compileAsync"])
136136
.getParameter(0)
137-
.getARhs()
137+
.getASink()
138138
}
139139
}
140140
}

javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ module ClientRequest {
827827
class ApolloClientRequest extends ClientRequest::Range, API::InvokeNode {
828828
ApolloClientRequest() { this = apolloUriCallee().getAnInvocation() }
829829

830-
override DataFlow::Node getUrl() { result = this.getParameter(0).getMember("uri").getARhs() }
830+
override DataFlow::Node getUrl() { result = this.getParameter(0).getMember("uri").getASink() }
831831

832832
override DataFlow::Node getHost() { none() }
833833

@@ -848,10 +848,10 @@ module ClientRequest {
848848

849849
override DataFlow::Node getUrl() { result = this.getArgument(0) }
850850

851-
override DataFlow::Node getHost() { result = this.getParameter(0).getMember("host").getARhs() }
851+
override DataFlow::Node getHost() { result = this.getParameter(0).getMember("host").getASink() }
852852

853853
override DataFlow::Node getADataNode() {
854-
result = form.getMember("append").getACall().getParameter(1).getARhs()
854+
result = form.getMember("append").getACall().getParameter(1).getASink()
855855
}
856856
}
857857
}

javascript/ql/lib/semmle/javascript/frameworks/Credentials.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private class CredentialsFromModel extends CredentialsExpr {
2121
string kind;
2222

2323
CredentialsFromModel() {
24-
this = ModelOutput::getASinkNode("credentials[" + kind + "]").getARhs().asExpr()
24+
this = ModelOutput::getASinkNode("credentials[" + kind + "]").getASink().asExpr()
2525
}
2626

2727
override string getCredentialsKind() { result = kind }

javascript/ql/lib/semmle/javascript/frameworks/D3.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module D3 {
7171
D3XssSink() {
7272
exists(API::Node htmlArg |
7373
htmlArg = d3Selection().getMember("html").getParameter(0) and
74-
this = [htmlArg, htmlArg.getReturn()].getARhs()
74+
this = [htmlArg, htmlArg.getReturn()].getASink()
7575
)
7676
}
7777
}

javascript/ql/lib/semmle/javascript/frameworks/HttpProxy.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ private module HttpProxy {
1919
.getACall()
2020
}
2121

22-
override DataFlow::Node getUrl() { result = getParameter(0).getMember("target").getARhs() }
22+
override DataFlow::Node getUrl() { result = getParameter(0).getMember("target").getASink() }
2323

2424
override DataFlow::Node getHost() {
25-
result = getParameter(0).getMember("target").getMember("host").getARhs()
25+
result = getParameter(0).getMember("target").getMember("host").getASink()
2626
}
2727

2828
override DataFlow::Node getADataNode() { none() }
@@ -49,10 +49,10 @@ private module HttpProxy {
4949
)
5050
}
5151

52-
override DataFlow::Node getUrl() { result = getOptionsObject().getMember("target").getARhs() }
52+
override DataFlow::Node getUrl() { result = getOptionsObject().getMember("target").getASink() }
5353

5454
override DataFlow::Node getHost() {
55-
result = getOptionsObject().getMember("target").getMember("host").getARhs()
55+
result = getOptionsObject().getMember("target").getMember("host").getASink()
5656
}
5757

5858
override DataFlow::Node getADataNode() { none() }
@@ -78,8 +78,8 @@ private module HttpProxy {
7878
ProxyListenerCallback() {
7979
exists(API::CallNode call |
8080
call = any(CreateServerCall server).getReturn().getMember(["on", "once"]).getACall() and
81-
call.getParameter(0).getARhs().mayHaveStringValue(event) and
82-
this = call.getParameter(1).getARhs().getAFunctionValue()
81+
call.getParameter(0).getASink().mayHaveStringValue(event) and
82+
this = call.getParameter(1).getASink().getAFunctionValue()
8383
)
8484
}
8585

javascript/ql/lib/semmle/javascript/frameworks/LdapJS.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ module LdapJS {
6161

6262
SearchFilter() {
6363
options = ldapClient().getMember("search").getACall().getParameter(1) and
64-
this = options.getARhs()
64+
this = options.getASink()
6565
}
6666

67-
override DataFlow::Node getInput() { result = options.getMember("filter").getARhs() }
67+
override DataFlow::Node getInput() { result = options.getMember("filter").getASink() }
6868

6969
override DataFlow::Node getOutput() { result = this }
7070
}

javascript/ql/lib/semmle/javascript/frameworks/LiveServer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private module LiveServer {
4141

4242
override DataFlow::SourceNode getARouteHandler() {
4343
exists(DataFlow::SourceNode middleware |
44-
middleware = call.getParameter(0).getMember("middleware").getAValueReachingRhs()
44+
middleware = call.getParameter(0).getMember("middleware").getAValueReachingSink()
4545
|
4646
result = middleware.getAMemberCall(["push", "unshift"]).getArgument(0).getAFunctionValue()
4747
or

javascript/ql/lib/semmle/javascript/frameworks/Markdown.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ module Markdown {
163163
or
164164
call = API::moduleImport("markdown-it").getMember("Markdown").getAnInvocation()
165165
|
166-
call.getParameter(0).getMember("html").getARhs().mayHaveBooleanValue(true) and
166+
call.getParameter(0).getMember("html").getASink().mayHaveBooleanValue(true) and
167167
result = call.getReturn()
168168
)
169169
or
170170
exists(API::CallNode call |
171171
call = markdownIt().getMember(["use", "set", "configure", "enable", "disable"]).getACall() and
172172
result = call.getReturn() and
173-
not call.getParameter(0).getAValueReachingRhs() =
173+
not call.getParameter(0).getAValueReachingSink() =
174174
DataFlow::moduleImport("markdown-it-sanitizer")
175175
)
176176
}

javascript/ql/lib/semmle/javascript/frameworks/Nest.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ module NestJS {
193193
.getAMember()
194194
.getMember("useFactory")
195195
.getReturn()
196-
.getARhs() = validationPipe().getInstance().getAValueReachableFromSource() and
196+
.getASink() = validationPipe().getInstance().getAValueReachableFromSource() and
197197
folder = decorator.getFile().getParentContainer()
198198
)
199199
or
@@ -399,7 +399,7 @@ module NestJS {
399399
}
400400

401401
/** Gets a value returned by the decorator's callback, which becomes the value of the decorated parameter. */
402-
DataFlow::Node getResult() { result = getParameter(0).getReturn().getARhs() }
402+
DataFlow::Node getResult() { result = getParameter(0).getReturn().getASink() }
403403
}
404404

405405
/**

0 commit comments

Comments
 (0)