@@ -181,9 +181,14 @@ module SocketIO {
181181 /** Gets the event name associated with the data, if it can be determined. */
182182 string getEventName ( ) { getArgument ( 0 ) .mayHaveStringValue ( result ) }
183183
184+ /** Gets the callback that handles data received from a client. */
185+ private DataFlow:: FunctionNode getListener ( ) {
186+ result = getCallback ( 1 )
187+ }
188+
184189 /** Gets the `i`th parameter through which data is received from a client. */
185190 DataFlow:: SourceNode getReceivedItem ( int i ) {
186- exists ( DataFlow:: FunctionNode cb | cb = getCallback ( 1 ) and result = cb .getParameter ( i ) |
191+ exists ( DataFlow:: FunctionNode cb | cb = getListener ( ) and result = cb .getParameter ( i ) |
187192 // exclude last parameter if it looks like a callback
188193 result != cb .getLastParameter ( ) or not exists ( result .getAnInvocation ( ) )
189194 )
@@ -194,7 +199,7 @@ module SocketIO {
194199
195200 /** Gets the acknowledgment callback, if any. */
196201 DataFlow:: SourceNode getAck ( ) {
197- result = getCallback ( 1 ) .getLastParameter ( ) and
202+ result = getListener ( ) .getLastParameter ( ) and
198203 exists ( result .getAnInvocation ( ) )
199204 }
200205
@@ -391,7 +396,14 @@ module SocketIOClient {
391396 result = "/"
392397 }
393398
394- /** Gets a server this socket may be communicating with. */
399+ /**
400+ * Gets a server this socket may be communicating with.
401+ *
402+ * To avoid matching sockets with unrelated servers, we restrict the search to
403+ * servers defined in the same npm package. Furthermore, the server is required
404+ * to have a namespace with the same path as the namespace of this socket, if
405+ * it can be determined.
406+ */
395407 SocketIO:: ServerObject getATargetServer ( ) {
396408 exists ( NPMPackage pkg |
397409 result .getOrigin ( ) .getFile ( ) = pkg .getAFile ( ) and
@@ -429,9 +441,14 @@ module SocketIOClient {
429441 /** Gets the event name associated with the data, if it can be determined. */
430442 string getEventName ( ) { getArgument ( 0 ) .mayHaveStringValue ( result ) }
431443
444+ /** Gets the callback that handles data received from the server. */
445+ private DataFlow:: FunctionNode getListener ( ) {
446+ result = getCallback ( 1 )
447+ }
448+
432449 /** Gets the `i`th parameter through which data is received from the server. */
433450 DataFlow:: SourceNode getReceivedItem ( int i ) {
434- exists ( DataFlow:: FunctionNode cb | cb = getCallback ( 1 ) and result = cb .getParameter ( i ) |
451+ exists ( DataFlow:: FunctionNode cb | cb = getListener ( ) and result = cb .getParameter ( i ) |
435452 // exclude the last parameter if it looks like a callback
436453 result != cb .getLastParameter ( ) or not exists ( result .getAnInvocation ( ) )
437454 )
@@ -442,7 +459,7 @@ module SocketIOClient {
442459
443460 /** Gets the acknowledgment callback, if any. */
444461 DataFlow:: SourceNode getAck ( ) {
445- result = getCallback ( 1 ) .getLastParameter ( ) and
462+ result = getListener ( ) .getLastParameter ( ) and
446463 exists ( result .getAnInvocation ( ) )
447464 }
448465
0 commit comments