Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02fba48

Browse files
committed
JS: Bugfixes
1 parent 0950b4d commit 02fba48

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module ClientRequest {
143143
override DataFlow::Node getHost() { none() }
144144

145145
string getResponseFormat() {
146-
if getOptionArgument(0, "json").mayHaveBooleanValue(true) then
146+
if getOptionArgument(1, "json").mayHaveBooleanValue(true) then
147147
result = "json"
148148
else
149149
result = "text"
@@ -163,6 +163,11 @@ module ClientRequest {
163163
or
164164
result = getCallback([1..2]).getParameter(1).getAPropertyRead("body")
165165
)
166+
or
167+
responseType = "error" and
168+
promise = false and
169+
pr = false and
170+
result = getCallback([1..2]).getParameter(0)
166171
}
167172

168173
override DataFlow::Node getADataNode() { result = getArgument(1) }
@@ -353,7 +358,7 @@ module ClientRequest {
353358
}
354359

355360
override DataFlow::Node getAResponseDataNode(string responseType, boolean promise) {
356-
responseType = "text" and
361+
responseType = "stream" and
357362
promise = true and
358363
result = this
359364
or
@@ -363,7 +368,7 @@ module ClientRequest {
363368
(
364369
responseType = "error" and result = callback.getParameter(0)
365370
or
366-
responseType = "text" and result = callback.getParameter(1)
371+
responseType = "stream" and result = callback.getParameter(1)
367372
)
368373
)
369374
}
@@ -386,13 +391,14 @@ module ClientRequest {
386391

387392
override DataFlow::Node getADataNode() { result = getAMethodCall("send").getArgument(0) }
388393

394+
private string getExplicitResponseType() {
395+
getAPropertyWrite("responseType").getRhs().mayHaveStringValue(result)
396+
}
397+
389398
private string getAssignedResponseType() {
390-
getAPropertyWrite("responseType").mayHaveStringValue(result)
391-
or
392-
getAPropertyWrite("responseType").mayHaveStringValue("") and
393-
result = "text"
399+
result = getExplicitResponseType()
394400
or
395-
not exists(getAPropertyWrite("responseType")) and
401+
not exists(getExplicitResponseType()) and
396402
result = "text"
397403
}
398404

@@ -435,15 +441,18 @@ module ClientRequest {
435441
* A model of a URL request made using the `XhrIo` class from the closure library.
436442
*/
437443
class ClosureXhrIoRequest extends ClientRequest::Range {
438-
DataFlow::SourceNode xhrIo;
444+
DataFlow::SourceNode base;
439445
boolean static;
440446

441447
ClosureXhrIoRequest() {
442-
xhrIo = Closure::moduleImport("goog.net.XhrIo") and
443-
(
444-
this = xhrIo.getAMethodCall("send") and static = true
448+
exists (DataFlow::SourceNode xhrIo | xhrIo = Closure::moduleImport("goog.net.XhrIo") |
449+
static = true and
450+
base = xhrIo and
451+
this = xhrIo.getAMethodCall("send")
445452
or
446-
this = xhrIo.getAnInstantiation().getAMethodCall("send") and static = false
453+
static = false and
454+
base = xhrIo.getAnInstantiation() and
455+
this = base.getAMethodCall("send")
447456
)
448457
}
449458

@@ -458,20 +467,21 @@ module ClientRequest {
458467

459468
/** Gets an event listener with `this` bound to this object. */
460469
DataFlow::FunctionNode getAnEventListener() {
470+
static = true and
461471
result = getAnArgument().getAFunctionValue()
462472
or
463473
static = false and
464474
exists(DataFlow::MethodCallNode listen, string name |
465-
listen = getAMethodCall(name) and
475+
listen = base.getAMethodCall(name) and
466476
(name = "listen" or name = "listenOnce") and
467-
xhrIo.flowsTo(listen.getArgument(3)) and
477+
base.flowsTo(listen.getArgument(3)) and
468478
result = listen
469479
)
470480
}
471481

472482
DataFlow::SourceNode getAnAlias() {
473483
static = false and
474-
result = xhrIo
484+
result = base
475485
or
476486
result = getAnEventListener().getReceiver()
477487
}

0 commit comments

Comments
 (0)