Skip to content

Commit

Permalink
fix: proxy now rejects forward connections that contain the 0.0.0.0
Browse files Browse the repository at this point in the history
… wildcard

#369
  • Loading branch information
tegefaulkes committed Apr 6, 2022
1 parent 437be7f commit 97cae6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/network/Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ class Proxy {
timer,
);
} catch (e) {
if (e instanceof networkErrors.ErrorProxyConnectInvalidUrl) {
if (!clientSocket.destroyed) {
await clientSocketEnd('HTTP/1.1 400 Bad Request\r\n' + '\r\n');
clientSocket.destroy(e);
}
return;
}
if (e instanceof networkErrors.ErrorConnectionStartTimeout) {
if (!clientSocket.destroyed) {
await clientSocketEnd('HTTP/1.1 504 Gateway Timeout\r\n' + '\r\n');
Expand Down Expand Up @@ -519,6 +526,9 @@ class Proxy {
proxyPort: Port,
timer?: Timer,
): Promise<ConnectionForward> {
if (proxyHost === '0.0.0.0') {

This comment has been minimized.

Copy link
@CMCDragonkai

CMCDragonkai Apr 6, 2022

Member

I thought it would be better to use the https://github.com/ip-num/ip-num library. We already use it in network/utils.ts. And we have some functions there.

Note that I tried isValidIPv4String and it does return true for 0.0.0.0. Same for isValidIPv6String and it returns true for ::.

So you want to have a separate utility function called isHostWildcard, and check specifically for 0.0.0.0 and ::.

throw new networkErrors.ErrorProxyConnectInvalidUrl();
}
const proxyAddress = networkUtils.buildAddress(proxyHost, proxyPort);
let conn: ConnectionForward | undefined;
conn = this.connectionsForward.proxy.get(proxyAddress);
Expand Down
9 changes: 9 additions & 0 deletions tests/network/Proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ describe(Proxy.name, () => {
`127.0.0.1:80?nodeId=${encodeURIComponent(nodeIdSomeEncoded)}`,
),
).rejects.toThrow('407');
// Wildcard as host
await expect(() =>
httpConnect(
proxy.getForwardHost(),
proxy.getForwardPort(),
authToken,
`0.0.0.0:80?nodeId=${encodeURIComponent(nodeIdSomeEncoded)}`,
),
).rejects.toThrow('400');
// No node id
await expect(() =>
httpConnect(
Expand Down

0 comments on commit 97cae6f

Please sign in to comment.