mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
add a model for the ClientRequest new require("net").Socket()
This commit is contained in:
@@ -389,6 +389,53 @@ module ClientRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instantiation `socket` of `require("net").Socket` type tracked using `t`.
|
||||
*/
|
||||
private DataFlow::SourceNode netSocketInstantiation(
|
||||
DataFlow::TypeTracker t, DataFlow::NewNode socket
|
||||
) {
|
||||
t.start() and
|
||||
socket = DataFlow::moduleMember("net", "Socket").getAnInstantiation() and
|
||||
result = socket
|
||||
or
|
||||
exists(DataFlow::TypeTracker t2 | result = netSocketInstantiation(t2, socket).track(t2, t))
|
||||
}
|
||||
|
||||
/**
|
||||
* A model of a request made using `(new require("net").Socket()).connect(args);`.
|
||||
*/
|
||||
class NetSocketRequest extends ClientRequest::Range {
|
||||
DataFlow::NewNode socket;
|
||||
|
||||
NetSocketRequest() {
|
||||
this = netSocketInstantiation(DataFlow::TypeTracker::end(), socket).getAMethodCall("connect")
|
||||
}
|
||||
|
||||
override DataFlow::Node getUrl() {
|
||||
result = getArgument([0, 1]) // there are multiple overrides of `connect`, and the URL can be in the first or second argument.
|
||||
}
|
||||
|
||||
override DataFlow::Node getHost() { result = getOptionArgument(0, "host") }
|
||||
|
||||
override DataFlow::Node getAResponseDataNode(string responseType, boolean promise) {
|
||||
responseType = "text" and
|
||||
promise = false and
|
||||
exists(DataFlow::CallNode call |
|
||||
call = netSocketInstantiation(DataFlow::TypeTracker::end(), socket).getAMemberCall("on") and
|
||||
call.getArgument(0).mayHaveStringValue("data") and
|
||||
result = call.getABoundCallbackParameter(1, 0)
|
||||
)
|
||||
}
|
||||
|
||||
override DataFlow::Node getADataNode() {
|
||||
exists(DataFlow::CallNode call |
|
||||
call = netSocketInstantiation(DataFlow::TypeTracker::end(), socket).getAMemberCall("write") and
|
||||
result = call.getArgument(0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A model of a URL request made using the `superagent` library.
|
||||
*/
|
||||
|
||||
@@ -66,6 +66,7 @@ test_ClientRequest
|
||||
| tst.js:200:2:200:21 | $.get("example.php") |
|
||||
| tst.js:202:5:208:7 | $.ajax( ... }}) |
|
||||
| tst.js:210:2:210:21 | $.get("example.php") |
|
||||
| tst.js:219:5:219:41 | data.so ... Host"}) |
|
||||
test_getADataNode
|
||||
| tst.js:53:5:53:23 | axios({data: data}) | tst.js:53:18:53:21 | data |
|
||||
| tst.js:57:5:57:39 | axios.p ... data2}) | tst.js:57:19:57:23 | data1 |
|
||||
@@ -95,11 +96,13 @@ test_getADataNode
|
||||
| tst.js:179:2:179:60 | $.getJS ... a ) {}) | tst.js:179:31:179:38 | "MyData" |
|
||||
| tst.js:183:2:183:60 | $.post( ... ) { }) | tst.js:183:28:183:37 | "PostData" |
|
||||
| tst.js:187:2:193:3 | $.ajax( ... on"\\n\\t}) | tst.js:190:11:190:20 | "AjaxData" |
|
||||
| tst.js:219:5:219:41 | data.so ... Host"}) | tst.js:223:23:223:30 | "foobar" |
|
||||
test_getHost
|
||||
| tst.js:87:5:87:39 | http.ge ... host}) | tst.js:87:34:87:37 | host |
|
||||
| tst.js:89:5:89:23 | axios({host: host}) | tst.js:89:18:89:21 | host |
|
||||
| tst.js:91:5:91:34 | got(rel ... host}) | tst.js:91:29:91:32 | host |
|
||||
| tst.js:93:5:93:35 | net.req ... host }) | tst.js:93:29:93:32 | host |
|
||||
| tst.js:219:5:219:41 | data.so ... Host"}) | tst.js:219:32:219:39 | "myHost" |
|
||||
test_getUrl
|
||||
| tst.js:11:5:11:16 | request(url) | tst.js:11:13:11:15 | url |
|
||||
| tst.js:13:5:13:20 | request.get(url) | tst.js:13:17:13:19 | url |
|
||||
@@ -173,6 +176,7 @@ test_getUrl
|
||||
| tst.js:200:2:200:21 | $.get("example.php") | tst.js:200:8:200:20 | "example.php" |
|
||||
| tst.js:202:5:208:7 | $.ajax( ... }}) | tst.js:203:10:203:22 | "example.php" |
|
||||
| tst.js:210:2:210:21 | $.get("example.php") | tst.js:210:8:210:20 | "example.php" |
|
||||
| tst.js:219:5:219:41 | data.so ... Host"}) | tst.js:219:25:219:40 | {host: "myHost"} |
|
||||
test_getAResponseDataNode
|
||||
| tst.js:19:5:19:23 | requestPromise(url) | tst.js:19:5:19:23 | requestPromise(url) | text | true |
|
||||
| tst.js:21:5:21:23 | superagent.get(url) | tst.js:21:5:21:23 | superagent.get(url) | stream | true |
|
||||
@@ -233,3 +237,4 @@ test_getAResponseDataNode
|
||||
| tst.js:200:2:200:21 | $.get("example.php") | tst.js:200:37:200:44 | response | | false |
|
||||
| tst.js:202:5:208:7 | $.ajax( ... }}) | tst.js:207:21:207:36 | err.responseText | json | false |
|
||||
| tst.js:210:2:210:21 | $.get("example.php") | tst.js:210:55:210:70 | xhr.responseText | | false |
|
||||
| tst.js:219:5:219:41 | data.so ... Host"}) | tst.js:221:29:221:32 | data | text | false |
|
||||
|
||||
@@ -209,3 +209,16 @@ import {ClientRequest, net} from 'electron';
|
||||
|
||||
$.get("example.php").fail(function(xhr) {console.log(xhr.responseText)});
|
||||
});
|
||||
|
||||
const net = require("net");
|
||||
(function () {
|
||||
var data = {
|
||||
socket: new net.Socket()
|
||||
}
|
||||
|
||||
data.socket.connect({host: "myHost"});
|
||||
|
||||
data.socket.on("data", (data) => {});
|
||||
|
||||
data.socket.write("foobar");
|
||||
})();
|
||||
Reference in New Issue
Block a user