@@ -27,13 +27,19 @@ private module LibraryNames {
27
27
string websocket ( ) { result = "WebSocket" }
28
28
29
29
string ws ( ) { result = "ws" }
30
+
31
+ class LibraryName extends string {
32
+ LibraryName ( ) {
33
+ this = sockjs ( ) or this = websocket ( ) or this = ws ( )
34
+ }
35
+ }
30
36
}
31
37
32
38
/**
33
39
* Holds if the websocket library named `client` can send a message to the library named `server`.
34
40
* Both `client` and `server` are library names defined in `LibraryNames`.
35
41
*/
36
- private predicate areLibrariesCompatible ( string client , string server ) {
42
+ private predicate areLibrariesCompatible ( LibraryNames :: LibraryName client , LibraryNames :: LibraryName server ) {
37
43
// sockjs is a WebSocket emulating library, but not actually an implementation of WebSockets.
38
44
client = LibraryNames:: sockjs ( ) and server = LibraryNames:: sockjs ( )
39
45
or
@@ -51,7 +57,7 @@ module ClientWebSocket {
51
57
* A class that can be used to instantiate a WebSocket instance.
52
58
*/
53
59
class SocketClass extends DataFlow:: SourceNode {
54
- string library ; // the name of the WebSocket library. Can be one of the libraries defined in `LibraryNames`.
60
+ LibraryName library ; // the name of the WebSocket library. Can be one of the libraries defined in `LibraryNames`.
55
61
56
62
SocketClass ( ) {
57
63
this = DataFlow:: globalVarRef ( "WebSocket" ) and library = websocket ( )
@@ -69,7 +75,7 @@ module ClientWebSocket {
69
75
/**
70
76
* Gets the WebSocket library name.
71
77
*/
72
- string getLibrary ( ) { result = library }
78
+ LibraryName getLibrary ( ) { result = library }
73
79
}
74
80
75
81
/**
@@ -83,7 +89,7 @@ module ClientWebSocket {
83
89
/**
84
90
* Gets the WebSocket library name.
85
91
*/
86
- string getLibrary ( ) { result = socketClass .getLibrary ( ) }
92
+ LibraryName getLibrary ( ) { result = socketClass .getLibrary ( ) }
87
93
}
88
94
89
95
/**
@@ -166,7 +172,7 @@ module ServerWebSocket {
166
172
/**
167
173
* Gets a server created by a library named `library`.
168
174
*/
169
- DataFlow:: SourceNode getAServer ( string library ) {
175
+ DataFlow:: SourceNode getAServer ( LibraryName library ) {
170
176
library = ws ( ) and
171
177
result = DataFlow:: moduleImport ( "ws" ) .getAConstructorInvocation ( "Server" )
172
178
or
@@ -178,7 +184,7 @@ module ServerWebSocket {
178
184
* A server WebSocket instance.
179
185
*/
180
186
class ServerSocket extends EventEmitter:: Range , DataFlow:: SourceNode {
181
- string library ;
187
+ LibraryName library ;
182
188
183
189
ServerSocket ( ) {
184
190
exists ( DataFlow:: CallNode onCall |
@@ -192,7 +198,7 @@ module ServerWebSocket {
192
198
/**
193
199
* Gets the name of the library that created this server socket.
194
200
*/
195
- string getLibrary ( ) { result = library }
201
+ LibraryName getLibrary ( ) { result = library }
196
202
}
197
203
198
204
/**
0 commit comments