Skip to content

Commit 7bfd74f

Browse files
committed
Revert change to onConnectHostname
1 parent 2f41e4b commit 7bfd74f

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

library/agent/Agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ export class Agent {
565565
}
566566
}
567567

568-
onConnectHostname(url: URL, port: number) {
569-
this.hostnames.add(url.hostname, port);
568+
onConnectHostname(hostname: string, port: number) {
569+
this.hostnames.add(hostname, port);
570570
}
571571

572572
onConnectHTTP(url: URL, port: number, method: string) {

library/sinks/Fetch.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class Fetch implements Wrapper {
2323
// Let the agent know that we are connecting to this hostname
2424
// This is to build a list of all hostnames that the application is connecting to
2525
if (typeof port === "number" && port > 0) {
26-
agent.onConnectHostname(url, port);
26+
agent.onConnectHostname(url.hostname, port);
2727
agent.onConnectHTTP(url, port, method);
2828
}
2929
const context = getContext();
@@ -57,7 +57,12 @@ export class Fetch implements Wrapper {
5757
if (typeof args[0] === "string" && args[0].length > 0) {
5858
const url = tryParseURL(args[0]);
5959
if (url) {
60-
const attack = this.inspectHostname(agent, url, getPortFromURL(url), method);
60+
const attack = this.inspectHostname(
61+
agent,
62+
url,
63+
getPortFromURL(url),
64+
method
65+
);
6166
if (attack) {
6267
return attack;
6368
}
@@ -71,7 +76,12 @@ export class Fetch implements Wrapper {
7176
if (Array.isArray(args[0])) {
7277
const url = tryParseURL(args[0].toString());
7378
if (url) {
74-
const attack = this.inspectHostname(agent, url, getPortFromURL(url), method);
79+
const attack = this.inspectHostname(
80+
agent,
81+
url,
82+
getPortFromURL(url),
83+
method
84+
);
7585
if (attack) {
7686
return attack;
7787
}
@@ -95,7 +105,12 @@ export class Fetch implements Wrapper {
95105
if (args[0] instanceof Request) {
96106
const url = tryParseURL(args[0].url);
97107
if (url) {
98-
const attack = this.inspectHostname(agent, url, getPortFromURL(url), method);
108+
const attack = this.inspectHostname(
109+
agent,
110+
url,
111+
getPortFromURL(url),
112+
method
113+
);
99114
if (attack) {
100115
return attack;
101116
}

library/sinks/HTTPRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class HTTPRequest implements Wrapper {
2525
// Let the agent know that we are connecting to this hostname
2626
// This is to build a list of all hostnames that the application is connecting to
2727
if (typeof port === "number" && port > 0) {
28-
agent.onConnectHostname(url, port);
28+
agent.onConnectHostname(url.hostname, port);
2929
agent.onConnectHTTP(url, port, method);
3030
}
3131
const context = getContext();

library/sinks/Undici.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ const methods = [
2626
export class Undici implements Wrapper {
2727
private inspectHostname(
2828
agent: Agent,
29-
url: URL,
29+
hostname: string,
3030
port: number | undefined,
3131
method: string
3232
): InterceptorResult {
3333
// Let the agent know that we are connecting to this hostname
3434
// This is to build a list of all hostnames that the application is connecting to
3535
if (typeof port === "number" && port > 0) {
36-
agent.onConnectHostname(url, port);
36+
agent.onConnectHostname(hostname, port);
3737
}
3838
const context = getContext();
3939

@@ -42,7 +42,7 @@ export class Undici implements Wrapper {
4242
}
4343

4444
return checkContextForSSRF({
45-
hostname: url.hostname,
45+
hostname: hostname,
4646
operation: `undici.${method}`,
4747
context,
4848
port,

0 commit comments

Comments
 (0)