Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/bug-detectors/internal/ssrf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ describe("SSRF", () => {
expect(() =>
hookTCPSocket(undefined, [80, "localhost", "callback"], 0),
).not.toThrow();
// connect(port, host) without a listener
expect(() => hookTCPSocket(undefined, [8080, "local"], 0)).toThrow(
"Server Side Request Forgery",
);
expect(() =>
hookTCPSocket(undefined, [80, "localhost"], 0),
).not.toThrow();
});

test("Call TCP socket hook with ports as strings", () => {
Expand Down Expand Up @@ -194,6 +201,13 @@ describe("SSRF", () => {
expect(() =>
hookTCPSocket(undefined, ["80", "localhost", "callback"], 0),
).not.toThrow();
// connect(port, host) without a listener
expect(() => hookTCPSocket(undefined, ["81", "local"], 0)).toThrow(
"Server Side Request Forgery",
);
expect(() =>
hookTCPSocket(undefined, ["80", "localhost"], 0),
).not.toThrow();
});
});

Expand Down
5 changes: 4 additions & 1 deletion packages/bug-detectors/internal/ssrf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ export function hookTCPSocket(_thisPtr: unknown, args: unknown[], _id: number) {
detectSSRF(port, host, "Attempted connection via TCP");
}
} else if (args.length === 2) {
// connect(options: SocketConnectOpts, connectionListener?: () => void): this;
const firstArgument = args[0];
if (typeof firstArgument === "object" && firstArgument !== null) {
// connect(options: SocketConnectOpts, connectionListener?: () => void): this;
const options = firstArgument as TcpSocketConnectOpts;
detectSSRF(options.port, options.host, "Attempted connection via TCP");
} else if (typeof args[1] === "string") {
// connect(port: number, host: string): this;
detectSSRF(firstArgument, args[1], "Attempted connection via TCP");
}
} else if (args.length === 3) {
// connect(port: number, host: string, connectionListener?: () => void): this;
Expand Down