Skip to content

Commit 90bc8a5

Browse files
committed
run the explicit-this patch on javascript/
1 parent b398f96 commit 90bc8a5

File tree

7 files changed

+59
-53
lines changed

7 files changed

+59
-53
lines changed

javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class FunctionNode extends DataFlow::ValueNode, DataFlow::SourceNode {
474474

475475
/** Gets the parameter named `name` of this function, if any. */
476476
DataFlow::ParameterNode getParameterByName(string name) {
477-
result = getAParameter() and
477+
result = this.getAParameter() and
478478
result.getName() = name
479479
}
480480

javascript/ql/lib/semmle/javascript/frameworks/AngularJS/ServiceDefinitions.qll

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private newtype TServiceReference =
2727
*/
2828
abstract class ServiceReference extends TServiceReference {
2929
/** Gets a textual representation of this element. */
30-
string toString() { result = getName() }
30+
string toString() { result = this.getName() }
3131

3232
/**
3333
* Gets the name of this reference.
@@ -51,21 +51,21 @@ abstract class ServiceReference extends TServiceReference {
5151
/**
5252
* Gets a call that invokes the referenced service.
5353
*/
54-
DataFlow::CallNode getACall() { result.getCalleeNode() = getAnAccess() }
54+
DataFlow::CallNode getACall() { result.getCalleeNode() = this.getAnAccess() }
5555

5656
/**
5757
* Gets a method call that invokes method `methodName` on the referenced service.
5858
*/
5959
DataFlow::MethodCallNode getAMethodCall(string methodName) {
60-
result.getReceiver() = getAnAccess() and
60+
result.getReceiver() = this.getAnAccess() and
6161
result.getMethodName() = methodName
6262
}
6363

6464
/**
6565
* Gets an access to property `propertyName` on the referenced service.
6666
*/
6767
DataFlow::PropRef getAPropertyAccess(string propertyName) {
68-
result.getBase() = getAnAccess() and
68+
result.getBase() = this.getAnAccess() and
6969
result.getPropertyName() = propertyName
7070
}
7171

@@ -244,17 +244,17 @@ abstract class RecipeDefinition extends DataFlow::CallNode, CustomServiceDefinit
244244
this = moduleRef(_).getAMethodCall(methodName) or
245245
this = builtinServiceRef("$provide").getAMethodCall(methodName)
246246
) and
247-
getArgument(0).mayHaveStringValue(name)
247+
this.getArgument(0).mayHaveStringValue(name)
248248
}
249249

250250
override string getName() { result = name }
251251

252-
override DataFlow::SourceNode getAFactoryFunction() { result.flowsTo(getArgument(1)) }
252+
override DataFlow::SourceNode getAFactoryFunction() { result.flowsTo(this.getArgument(1)) }
253253

254254
override DataFlow::Node getAnInjectableFunction() {
255255
methodName != "value" and
256256
methodName != "constant" and
257-
result = getAFactoryFunction()
257+
result = this.getAFactoryFunction()
258258
}
259259
}
260260

@@ -269,7 +269,7 @@ abstract class RecipeDefinition extends DataFlow::CallNode, CustomServiceDefinit
269269
*/
270270
abstract private class CustomSpecialServiceDefinition extends CustomServiceDefinition,
271271
DependencyInjection {
272-
override DataFlow::Node getAnInjectableFunction() { result = getAFactoryFunction() }
272+
override DataFlow::Node getAnInjectableFunction() { result = this.getAFactoryFunction() }
273273
}
274274

275275
/**
@@ -498,7 +498,9 @@ class InjectableFunctionServiceRequest extends ServiceRequestNode {
498498
/**
499499
* Gets a name of a requested service.
500500
*/
501-
string getAServiceName() { exists(getAnInjectedFunction().getADependencyDeclaration(result)) }
501+
string getAServiceName() {
502+
exists(this.getAnInjectedFunction().getADependencyDeclaration(result))
503+
}
502504

503505
/**
504506
* Gets a service with the specified name, relative to this request.
@@ -576,7 +578,7 @@ class ServiceRecipeDefinition extends RecipeDefinition {
576578
*/
577579

578580
exists(InjectableFunction f |
579-
f = getAFactoryFunction() and
581+
f = this.getAFactoryFunction() and
580582
result = f.asFunction()
581583
)
582584
}
@@ -589,7 +591,7 @@ class ServiceRecipeDefinition extends RecipeDefinition {
589591
class ValueRecipeDefinition extends RecipeDefinition {
590592
ValueRecipeDefinition() { methodName = "value" }
591593

592-
override DataFlow::SourceNode getAService() { result = getAFactoryFunction() }
594+
override DataFlow::SourceNode getAService() { result = this.getAFactoryFunction() }
593595
}
594596

595597
/**
@@ -599,7 +601,7 @@ class ValueRecipeDefinition extends RecipeDefinition {
599601
class ConstantRecipeDefinition extends RecipeDefinition {
600602
ConstantRecipeDefinition() { methodName = "constant" }
601603

602-
override DataFlow::SourceNode getAService() { result = getAFactoryFunction() }
604+
override DataFlow::SourceNode getAService() { result = this.getAFactoryFunction() }
603605
}
604606

605607
/**
@@ -622,7 +624,7 @@ class ProviderRecipeDefinition extends RecipeDefinition {
622624
*/
623625

624626
exists(DataFlow::ThisNode thiz, InjectableFunction f |
625-
f = getAFactoryFunction() and
627+
f = this.getAFactoryFunction() and
626628
thiz.getBinder() = f.asFunction() and
627629
result = thiz.getAPropertySource("$get")
628630
)
@@ -647,7 +649,9 @@ class ConfigMethodDefinition extends ModuleApiCall {
647649
/**
648650
* Gets a provided configuration method.
649651
*/
650-
InjectableFunction getConfigMethod() { result.(DataFlow::SourceNode).flowsTo(getArgument(0)) }
652+
InjectableFunction getConfigMethod() {
653+
result.(DataFlow::SourceNode).flowsTo(this.getArgument(0))
654+
}
651655
}
652656

653657
/**
@@ -660,12 +664,12 @@ class RunMethodDefinition extends ModuleApiCall {
660664
/**
661665
* Gets a provided run method.
662666
*/
663-
InjectableFunction getRunMethod() { result.(DataFlow::SourceNode).flowsTo(getArgument(0)) }
667+
InjectableFunction getRunMethod() { result.(DataFlow::SourceNode).flowsTo(this.getArgument(0)) }
664668
}
665669

666670
/**
667671
* The `$scope` or `$rootScope` service.
668672
*/
669673
class ScopeServiceReference extends BuiltinServiceReference {
670-
ScopeServiceReference() { getName() = "$scope" or getName() = "$rootScope" }
674+
ScopeServiceReference() { this.getName() = "$scope" or this.getName() = "$rootScope" }
671675
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ module Express {
158158
* This differs from `getARouteHandler` in that the argument expression is
159159
* returned, not its dataflow source.
160160
*/
161-
deprecated Expr getRouteHandlerExpr(int index) { result = getRouteHandlerNode(index).asExpr() }
161+
deprecated Expr getRouteHandlerExpr(int index) {
162+
result = this.getRouteHandlerNode(index).asExpr()
163+
}
162164

163165
/**
164166
* Gets the `n`th handler registered by this setup, with 0 being the first.

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ module Firebase {
114114
class QueryListenCall extends DataFlow::MethodCallNode {
115115
QueryListenCall() {
116116
this = query().getAMethodCall() and
117-
(getMethodName() = "on" or getMethodName() = "once")
117+
(this.getMethodName() = "on" or this.getMethodName() = "once")
118118
}
119119

120120
/**
121121
* Gets the argument in which the callback is passed.
122122
*/
123-
DataFlow::Node getCallbackNode() { result = getArgument(1) }
123+
DataFlow::Node getCallbackNode() { result = this.getArgument(1) }
124124
}
125125

126126
/**
@@ -183,13 +183,13 @@ module Firebase {
183183
class RefBuilderListenCall extends DataFlow::MethodCallNode {
184184
RefBuilderListenCall() {
185185
this = ref().getAMethodCall() and
186-
getMethodName() = "on" + any(string s)
186+
this.getMethodName() = "on" + any(string s)
187187
}
188188

189189
/**
190190
* Gets the data flow node holding the listener callback.
191191
*/
192-
DataFlow::Node getCallbackNode() { result = getArgument(0) }
192+
DataFlow::Node getCallbackNode() { result = this.getArgument(0) }
193193
}
194194

195195
/**
@@ -199,14 +199,14 @@ module Firebase {
199199
RouteSetup() { this = namespace().getAPropertyRead("https").getAMemberCall("onRequest") }
200200

201201
override DataFlow::SourceNode getARouteHandler() {
202-
result = getARouteHandler(DataFlow::TypeBackTracker::end())
202+
result = this.getARouteHandler(DataFlow::TypeBackTracker::end())
203203
}
204204

205205
private DataFlow::SourceNode getARouteHandler(DataFlow::TypeBackTracker t) {
206206
t.start() and
207-
result = getArgument(0).getALocalSource()
207+
result = this.getArgument(0).getALocalSource()
208208
or
209-
exists(DataFlow::TypeBackTracker t2 | result = getARouteHandler(t2).backtrack(t2, t))
209+
exists(DataFlow::TypeBackTracker t2 | result = this.getARouteHandler(t2).backtrack(t2, t))
210210
}
211211

212212
override DataFlow::Node getServer() { none() }

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ module Hapi {
2525
/**
2626
* Gets the parameter of the route handler that contains the request object.
2727
*/
28-
DataFlow::ParameterNode getRequestParameter() { result = getParameter(0) }
28+
DataFlow::ParameterNode getRequestParameter() { result = this.getParameter(0) }
2929

3030
/**
3131
* Gets the parameter of the route handler that contains the "request toolkit",
3232
* usually named `h`.
3333
*/
34-
DataFlow::ParameterNode getRequestToolkitParameter() { result = getParameter(1) }
34+
DataFlow::ParameterNode getRequestToolkitParameter() { result = this.getParameter(1) }
3535

3636
/**
3737
* Gets a source node referring to the request toolkit parameter, usually named `h`.
3838
*/
39-
DataFlow::SourceNode getRequestToolkit() { result = getRequestToolkitParameter() }
39+
DataFlow::SourceNode getRequestToolkit() { result = this.getRequestToolkitParameter() }
4040
}
4141

4242
/**
@@ -203,24 +203,24 @@ module Hapi {
203203
server.ref().getAMethodCall() = this and
204204
(
205205
// server.route({ handler: fun })
206-
getMethodName() = "route" and
207-
getOptionArgument(0, "handler") = handler
206+
this.getMethodName() = "route" and
207+
this.getOptionArgument(0, "handler") = handler
208208
or
209209
// server.ext('/', fun)
210-
getMethodName() = "ext" and
211-
handler = getArgument(1)
210+
this.getMethodName() = "ext" and
211+
handler = this.getArgument(1)
212212
)
213213
}
214214

215215
override DataFlow::SourceNode getARouteHandler() {
216-
result = getARouteHandler(DataFlow::TypeBackTracker::end())
216+
result = this.getARouteHandler(DataFlow::TypeBackTracker::end())
217217
}
218218

219219
private DataFlow::SourceNode getARouteHandler(DataFlow::TypeBackTracker t) {
220220
t.start() and
221-
result = getRouteHandler().getALocalSource()
221+
result = this.getRouteHandler().getALocalSource()
222222
or
223-
exists(DataFlow::TypeBackTracker t2 | result = getARouteHandler(t2).backtrack(t2, t))
223+
exists(DataFlow::TypeBackTracker t2 | result = this.getARouteHandler(t2).backtrack(t2, t))
224224
}
225225

226226
pragma[noinline]
@@ -268,9 +268,9 @@ module Hapi {
268268

269269
override DataFlow::SourceNode getOutput() { none() }
270270

271-
override DataFlow::Node getTemplateFileNode() { result = getArgument(0) }
271+
override DataFlow::Node getTemplateFileNode() { result = this.getArgument(0) }
272272

273-
override DataFlow::Node getTemplateParamsNode() { result = getArgument(1) }
273+
override DataFlow::Node getTemplateParamsNode() { result = this.getArgument(1) }
274274
}
275275

276276
/**

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module NestJS {
5656
*/
5757
predicate isReturnValueReflected() {
5858
getAFunctionDecorator(this) = nestjs().getMember(["Get", "Post"]).getACall() and
59-
not hasRedirectDecorator() and
59+
not this.hasRedirectDecorator() and
6060
not getAFunctionDecorator(this) = nestjs().getMember("Render").getACall()
6161
}
6262

@@ -93,7 +93,7 @@ module NestJS {
9393
NestJSRequestInput() {
9494
decoratorName =
9595
["Query", "Param", "Headers", "Body", "HostParam", "UploadedFile", "UploadedFiles"] and
96-
decorator = getADecorator() and
96+
decorator = this.getADecorator() and
9797
decorator = nestjs().getMember(decoratorName).getACall()
9898
}
9999

@@ -105,7 +105,7 @@ module NestJS {
105105

106106
/** Gets a pipe applied to this parameter, not including global pipes. */
107107
DataFlow::Node getAPipe() {
108-
result = getNestRouteHandler().getAPipe()
108+
result = this.getNestRouteHandler().getAPipe()
109109
or
110110
result = decorator.getArgument(1)
111111
or
@@ -132,7 +132,7 @@ module NestJS {
132132
hasSanitizingPipe(this, false)
133133
or
134134
hasSanitizingPipe(this, true) and
135-
isSanitizingType(getParameter().getType().unfold())
135+
isSanitizingType(this.getParameter().getType().unfold())
136136
}
137137
}
138138

@@ -240,14 +240,14 @@ module NestJS {
240240
)
241241
}
242242

243-
DataFlow::FunctionNode getTransformFunction() { result = getInstanceMethod("transform") }
243+
DataFlow::FunctionNode getTransformFunction() { result = this.getInstanceMethod("transform") }
244244

245-
DataFlow::ParameterNode getInputData() { result = getTransformFunction().getParameter(0) }
245+
DataFlow::ParameterNode getInputData() { result = this.getTransformFunction().getParameter(0) }
246246

247-
DataFlow::Node getOutputData() { result = getTransformFunction().getReturnNode() }
247+
DataFlow::Node getOutputData() { result = this.getTransformFunction().getReturnNode() }
248248

249249
NestJSRequestInput getAnAffectedParameter() {
250-
[getAnInstanceReference(), getAClassReference()].flowsTo(result.getAPipe())
250+
[this.getAnInstanceReference(), this.getAClassReference()].flowsTo(result.getAPipe())
251251
}
252252
}
253253

@@ -297,16 +297,16 @@ module NestJS {
297297
private class NestJSRequestInputAsRequestInputAccess extends NestJSRequestInput,
298298
HTTP::RequestInputAccess {
299299
NestJSRequestInputAsRequestInputAccess() {
300-
not isSanitizedByPipe() and
300+
not this.isSanitizedByPipe() and
301301
not this = any(CustomPipeClass cls).getAnAffectedParameter()
302302
}
303303

304-
override HTTP::RouteHandler getRouteHandler() { result = getNestRouteHandler() }
304+
override HTTP::RouteHandler getRouteHandler() { result = this.getNestRouteHandler() }
305305

306-
override string getKind() { result = getInputKind() }
306+
override string getKind() { result = this.getInputKind() }
307307

308308
override predicate isUserControlledObject() {
309-
not exists(getAPipe()) and // value is not transformed by a pipe
309+
not exists(this.getAPipe()) and // value is not transformed by a pipe
310310
(
311311
decorator.getNumArgument() = 0
312312
or
@@ -389,15 +389,15 @@ module NestJS {
389389
CustomParameterDecorator() { this = nestjs().getMember("createParamDecorator").getACall() }
390390

391391
/** Gets the `context` parameter. */
392-
API::Node getExecutionContext() { result = getParameter(0).getParameter(1) }
392+
API::Node getExecutionContext() { result = this.getParameter(0).getParameter(1) }
393393

394394
/** Gets a parameter with this decorator applied. */
395395
DataFlow::ParameterNode getADecoratedParameter() {
396-
result.getADecorator() = getReturn().getReturn().getAValueReachableFromSource()
396+
result.getADecorator() = this.getReturn().getReturn().getAValueReachableFromSource()
397397
}
398398

399399
/** Gets a value returned by the decorator's callback, which becomes the value of the decorated parameter. */
400-
DataFlow::Node getResult() { result = getParameter(0).getReturn().asSink() }
400+
DataFlow::Node getResult() { result = this.getParameter(0).getReturn().asSink() }
401401
}
402402

403403
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module Restify {
162162
server.ref().getAMethodCall(any(HTTP::RequestMethodName m).toLowerCase()) = this
163163
}
164164

165-
override DataFlow::SourceNode getARouteHandler() { result.flowsTo(getArgument(1)) }
165+
override DataFlow::SourceNode getARouteHandler() { result.flowsTo(this.getArgument(1)) }
166166

167167
override DataFlow::Node getServer() { result = server }
168168
}

0 commit comments

Comments
 (0)