Skip to content

Commit 6668a7a

Browse files
committed
JS: Add backwards-compatible predicates to SocketIO
1 parent 9f18a15 commit 6668a7a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ module SocketIO {
8282
}
8383

8484
override DataFlow::SourceNode ref() { result = server(DataFlow::TypeTracker::end()) }
85+
86+
/**
87+
* DEPRECATED. Always returns `this` as a `ServerObject` now represents the origin of a server.
88+
*
89+
* Instead of `getOrigin()` to get a server origin from a reference, use `ServerObject.ref()` to get references to a given server.
90+
*/
91+
deprecated DataFlow::SourceNode getOrigin() { result = this }
8592
}
8693

8794
/** A data flow node that may produce (that is, create or return) a socket.io server. */
@@ -270,6 +277,21 @@ module SocketIO {
270277
}
271278

272279
override string getChannel() { this.getArgument(0).mayHaveStringValue(result) }
280+
281+
/** Gets a parameter through which data is received from a client. */
282+
DataFlow::SourceNode getAReceivedItem() { result = getReceivedItem(_) }
283+
284+
/** Gets a client-side node that may be sending the data received here. */
285+
SendNode getASender() { result.getAReceiver() = this }
286+
287+
/** Gets the acknowledgment callback, if any. */
288+
DataFlow::FunctionNode getAck() {
289+
result = getListener().getLastParameter() and
290+
exists(result.getAnInvocation())
291+
}
292+
293+
/** DEPRECATED. Use `getChannel()` instead. */
294+
deprecated string getEventName() { result = getChannel() }
273295
}
274296

275297
/** An acknowledgment callback when receiving a message. */
@@ -350,6 +372,16 @@ module SocketIO {
350372
override SocketIOClient::ReceiveNode getAReceiver() {
351373
result.getSocket().getATargetNamespace() = getNamespace()
352374
}
375+
376+
/** Gets the acknowledgment callback, if any. */
377+
DataFlow::FunctionNode getAck() {
378+
// acknowledgments are only available when sending through a socket
379+
exists(getSocket()) and
380+
result = getLastArgument().getALocalSource()
381+
}
382+
383+
/** DEPRECATED. Use `getChannel()` instead. */
384+
deprecated string getEventName() { result = getChannel() }
353385
}
354386

355387
/** A socket.io namespace, identified by its server and its path. */
@@ -538,6 +570,21 @@ module SocketIOClient {
538570
result != cb.getLastParameter() or not exists(result.getAnInvocation())
539571
)
540572
}
573+
574+
/** Gets a data flow node representing data received from the server. */
575+
DataFlow::SourceNode getAReceivedItem() { result = getReceivedItem(_) }
576+
577+
/** Gets the acknowledgment callback, if any. */
578+
DataFlow::FunctionNode getAck() {
579+
result = getListener().getLastParameter() and
580+
exists(result.getAnInvocation())
581+
}
582+
583+
/** Gets a server-side node that may be sending the data received here. */
584+
SocketIO::SendNode getASender() {
585+
result.getNamespace() = getSocket().getATargetNamespace() and
586+
not result.getChannel() != getChannel()
587+
}
541588
}
542589

543590
/** An acknowledgment callback from a receive node. */
@@ -607,10 +654,23 @@ module SocketIOClient {
607654
)
608655
}
609656

657+
/** Gets a data flow node representing data sent to the client. */
658+
DataFlow::Node getASentItem() { result = getSentItem(_) }
659+
610660
/** Gets a server-side node that may be receiving the data sent here. */
611661
override SocketIO::ReceiveNode getAReceiver() {
612662
result.getSocket().getNamespace() = getSocket().getATargetNamespace()
613663
}
664+
665+
/** Gets the acknowledgment callback, if any. */
666+
DataFlow::FunctionNode getAck() {
667+
// acknowledgments are only available when sending through a socket
668+
exists(getSocket()) and
669+
result = getLastArgument().getALocalSource()
670+
}
671+
672+
/** DEPRECATED. Use `getChannel()` instead. */
673+
deprecated string getEventName() { result = getChannel() }
614674
}
615675

616676
/**

0 commit comments

Comments
 (0)