Skip to content

Commit 9fae953

Browse files
authored
Merge pull request github#3262 from asger-semmle/js/api-deprecation-and-renaming
Approved by erik-krogh
2 parents 4259904 + 997b449 commit 9fae953

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ 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+
deprecated DataFlow::SourceNode getOrigin() { result = this }
8590
}
8691

8792
/** A data flow node that may produce (that is, create or return) a socket.io server. */
@@ -270,6 +275,18 @@ module SocketIO {
270275
}
271276

272277
override string getChannel() { this.getArgument(0).mayHaveStringValue(result) }
278+
279+
/** Gets a parameter through which data is received from a client. */
280+
DataFlow::SourceNode getAReceivedItem() { result = getReceivedItem(_) }
281+
282+
/** Gets a client-side node that may be sending the data received here. */
283+
SendNode getASender() { result.getAReceiver() = this }
284+
285+
/** Gets the acknowledgment callback, if any. */
286+
ReceiveCallback getAck() { result.getReceiveNode() = this }
287+
288+
/** DEPRECATED. Use `getChannel()` instead. */
289+
deprecated string getEventName() { result = getChannel() }
273290
}
274291

275292
/** An acknowledgment callback when receiving a message. */
@@ -289,6 +306,9 @@ module SocketIO {
289306
override SocketIOClient::SendCallback getAReceiver() {
290307
result.getSendNode().getAReceiver() = rcv
291308
}
309+
310+
/** Gets the API call to which this is a callback. */
311+
ReceiveNode getReceiveNode() { result = rcv }
292312
}
293313

294314
/**
@@ -350,6 +370,12 @@ module SocketIO {
350370
override SocketIOClient::ReceiveNode getAReceiver() {
351371
result.getSocket().getATargetNamespace() = getNamespace()
352372
}
373+
374+
/** Gets the acknowledgment callback, if any. */
375+
SendCallback getAck() { result.getSendNode() = this }
376+
377+
/** DEPRECATED. Use `getChannel()` instead. */
378+
deprecated string getEventName() { result = getChannel() }
353379
}
354380

355381
/** A socket.io namespace, identified by its server and its path. */
@@ -538,14 +564,26 @@ module SocketIOClient {
538564
result != cb.getLastParameter() or not exists(result.getAnInvocation())
539565
)
540566
}
567+
568+
/** Gets a data flow node representing data received from the server. */
569+
DataFlow::SourceNode getAReceivedItem() { result = getReceivedItem(_) }
570+
571+
/** Gets the acknowledgment callback, if any. */
572+
DataFlow::SourceNode getAck() { result.(ReceiveCallback).getReceiveNode() = this }
573+
574+
/** Gets a server-side node that may be sending the data received here. */
575+
SocketIO::SendNode getASender() {
576+
result.getNamespace() = getSocket().getATargetNamespace() and
577+
not result.getChannel() != getChannel()
578+
}
541579
}
542580

543581
/** An acknowledgment callback from a receive node. */
544-
class RecieveCallback extends EventDispatch::Range, DataFlow::SourceNode {
582+
class ReceiveCallback extends EventDispatch::Range, DataFlow::SourceNode {
545583
override SocketObject emitter;
546584
ReceiveNode rcv;
547585

548-
RecieveCallback() {
586+
ReceiveCallback() {
549587
this = rcv.getListener().getLastParameter() and
550588
exists(this.getAnInvocation()) and
551589
emitter = rcv.getEmitter()
@@ -607,10 +645,19 @@ module SocketIOClient {
607645
)
608646
}
609647

648+
/** Gets a data flow node representing data sent to the client. */
649+
DataFlow::Node getASentItem() { result = getSentItem(_) }
650+
610651
/** Gets a server-side node that may be receiving the data sent here. */
611652
override SocketIO::ReceiveNode getAReceiver() {
612653
result.getSocket().getNamespace() = getSocket().getATargetNamespace()
613654
}
655+
656+
/** Gets the acknowledgment callback, if any. */
657+
DataFlow::FunctionNode getAck() { result.(SendCallback).getSendNode() = this }
658+
659+
/** DEPRECATED. Use `getChannel()` instead. */
660+
deprecated string getEventName() { result = getChannel() }
614661
}
615662

616663
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import javascript
22

33
query predicate test_ClientReceiveNode_getAck(
4-
SocketIOClient::ReceiveNode rn, SocketIOClient::RecieveCallback res
4+
SocketIOClient::ReceiveNode rn, SocketIOClient::ReceiveCallback res
55
) {
66
res.getReceiveNode() = rn
77
}

0 commit comments

Comments
 (0)