|
| 1 | +/** Provides classes for working with WebSocket-related APIs. */ |
| 2 | + |
| 3 | +import go |
| 4 | + |
| 5 | +/** |
| 6 | + * A data-flow node that establishes a new WebSocket connection. |
| 7 | + * |
| 8 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 9 | + * extend `WebSocketRequestCall::Range` instead. |
| 10 | + */ |
| 11 | +class WebSocketRequestCall extends DataFlow::CallNode { |
| 12 | + WebSocketRequestCall::Range self; |
| 13 | + |
| 14 | + WebSocketRequestCall() { this = self } |
| 15 | + |
| 16 | + /** Gets the URL of the request. */ |
| 17 | + DataFlow::Node getRequestUrl() { result = self.getRequestUrl() } |
| 18 | +} |
| 19 | + |
| 20 | +/** Provides classes for working with WebSocket request functions. */ |
| 21 | +module WebSocketRequestCall { |
| 22 | + /** |
| 23 | + * A data-flow node that establishes a new WebSocket connection. |
| 24 | + * |
| 25 | + * Extend this class to model new APIs. If you want to refine existing |
| 26 | + * API models, extend `WebSocketRequestCall` instead. |
| 27 | + */ |
| 28 | + abstract class Range extends DataFlow::CallNode { |
| 29 | + /** Gets the URL of the request. */ |
| 30 | + abstract DataFlow::Node getRequestUrl(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * A WebSocket request expression string used in an API function of the |
| 35 | + * `golang.org/x/net/websocket` package. |
| 36 | + */ |
| 37 | + private class GolangXNetDialFunc extends Range { |
| 38 | + GolangXNetDialFunc() { |
| 39 | + // func Dial(url_, protocol, origin string) (ws *Conn, err error) |
| 40 | + this.getTarget().hasQualifiedName(package("golang.org/x/net", "websocket"), "Dial") |
| 41 | + } |
| 42 | + |
| 43 | + override DataFlow::Node getRequestUrl() { result = this.getArgument(0) } |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * A WebSocket DialConfig expression string used in an API function |
| 48 | + * of the `golang.org/x/net/websocket` package. |
| 49 | + */ |
| 50 | + private class GolangXNetDialConfigFunc extends Range { |
| 51 | + GolangXNetDialConfigFunc() { |
| 52 | + // func DialConfig(config *Config) (ws *Conn, err error) |
| 53 | + this.getTarget().hasQualifiedName(package("golang.org/x/net", "websocket"), "DialConfig") |
| 54 | + } |
| 55 | + |
| 56 | + override DataFlow::Node getRequestUrl() { |
| 57 | + exists(DataFlow::CallNode cn | |
| 58 | + // func NewConfig(server, origin string) (config *Config, err error) |
| 59 | + cn.getTarget().hasQualifiedName(package("golang.org/x/net", "websocket"), "NewConfig") and |
| 60 | + this.getArgument(0) = cn.getResult(0).getASuccessor*() and |
| 61 | + result = cn.getArgument(0) |
| 62 | + ) |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * A WebSocket request expression string used in an API function |
| 68 | + * of the `github.com/gorilla/websocket` package. |
| 69 | + */ |
| 70 | + private class GorillaWebsocketDialFunc extends Range { |
| 71 | + DataFlow::Node url; |
| 72 | + |
| 73 | + GorillaWebsocketDialFunc() { |
| 74 | + // func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) |
| 75 | + // func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) |
| 76 | + exists(string name, Method f | |
| 77 | + f = this.getTarget() and |
| 78 | + f.hasQualifiedName(package("github.com/gorilla", "websocket"), "Dialer", name) |
| 79 | + | |
| 80 | + name = "Dial" and this.getArgument(0) = url |
| 81 | + or |
| 82 | + name = "DialContext" and this.getArgument(1) = url |
| 83 | + ) |
| 84 | + } |
| 85 | + |
| 86 | + override DataFlow::Node getRequestUrl() { result = url } |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * A WebSocket request expression string used in an API function |
| 91 | + * of the `github.com/gobwas/ws` package. |
| 92 | + */ |
| 93 | + private class GobwasWsDialFunc extends Range { |
| 94 | + GobwasWsDialFunc() { |
| 95 | + // func (d Dialer) Dial(ctx context.Context, urlstr string) (conn net.Conn, br *bufio.Reader, hs Handshake, err error) |
| 96 | + exists(Method m | |
| 97 | + m.hasQualifiedName(package("github.com/gobwas", "ws"), "Dialer", "Dial") and |
| 98 | + m = this.getTarget() |
| 99 | + ) |
| 100 | + or |
| 101 | + // func Dial(ctx context.Context, urlstr string) (net.Conn, *bufio.Reader, Handshake, error) |
| 102 | + this.getTarget().hasQualifiedName(package("github.com/gobwas", "ws"), "Dial") |
| 103 | + } |
| 104 | + |
| 105 | + override DataFlow::Node getRequestUrl() { result = this.getArgument(1) } |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * A WebSocket request expression string used in an API function |
| 110 | + * of the `nhooyr.io/websocket` package. |
| 111 | + */ |
| 112 | + private class NhooyrWebsocketDialFunc extends Range { |
| 113 | + NhooyrWebsocketDialFunc() { |
| 114 | + // func Dial(ctx context.Context, u string, opts *DialOptions) (*Conn, *http.Response, error) |
| 115 | + this.getTarget().hasQualifiedName(package("nhooyr.io", "websocket"), "Dial") |
| 116 | + } |
| 117 | + |
| 118 | + override DataFlow::Node getRequestUrl() { result = this.getArgument(1) } |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * A WebSocket request expression string used in an API function |
| 123 | + * of the `github.com/sacOO7/gowebsocket` package. |
| 124 | + */ |
| 125 | + private class SacOO7DialFunc extends Range { |
| 126 | + SacOO7DialFunc() { |
| 127 | + // func BuildProxy(Url string) func(*http.Request) (*url.URL, error) |
| 128 | + // func New(url string) Socket |
| 129 | + this.getTarget().hasQualifiedName("github.com/sacOO7/gowebsocket", ["New", "BuildProxy"]) |
| 130 | + } |
| 131 | + |
| 132 | + override DataFlow::Node getRequestUrl() { result = this.getArgument(0) } |
| 133 | + } |
| 134 | +} |
0 commit comments