@@ -8,6 +8,7 @@ import { Wrapper } from "../agent/Wrapper";
88import { getPortFromURL } from "../helpers/getPortFromURL" ;
99import { tryParseURL } from "../helpers/tryParseURL" ;
1010import { checkContextForSSRF } from "../vulnerabilities/ssrf/checkContextForSSRF" ;
11+ import { Hostname } from "../vulnerabilities/ssrf/Hostname" ;
1112import { inspectDNSLookupCalls } from "../vulnerabilities/ssrf/inspectDNSLookupCalls" ;
1213import { wrapDispatch } from "./undici/wrapDispatch" ;
1314
@@ -16,13 +17,13 @@ export class Fetch implements Wrapper {
1617
1718 private inspectHostname (
1819 agent : Agent ,
19- hostname : string ,
20+ hostname : URL ,
2021 port : number | undefined
2122 ) : InterceptorResult {
2223 // Let the agent know that we are connecting to this hostname
2324 // This is to build a list of all hostnames that the application is connecting to
2425 if ( typeof port === "number" && port > 0 ) {
25- agent . onConnectHostname ( hostname , port ) ;
26+ agent . onConnectHostname ( hostname . hostname , port ) ;
2627 }
2728 const context = getContext ( ) ;
2829
@@ -31,7 +32,7 @@ export class Fetch implements Wrapper {
3132 }
3233
3334 return checkContextForSSRF ( {
34- hostname : hostname ,
35+ hostname : Hostname . fromURL ( hostname ) ,
3536 operation : "fetch" ,
3637 context : context ,
3738 port : port ,
@@ -44,11 +45,7 @@ export class Fetch implements Wrapper {
4445 if ( typeof args [ 0 ] === "string" && args [ 0 ] . length > 0 ) {
4546 const url = tryParseURL ( args [ 0 ] ) ;
4647 if ( url ) {
47- const attack = this . inspectHostname (
48- agent ,
49- url . hostname ,
50- getPortFromURL ( url )
51- ) ;
48+ const attack = this . inspectHostname ( agent , url , getPortFromURL ( url ) ) ;
5249 if ( attack ) {
5350 return attack ;
5451 }
@@ -62,11 +59,7 @@ export class Fetch implements Wrapper {
6259 if ( Array . isArray ( args [ 0 ] ) ) {
6360 const url = tryParseURL ( args [ 0 ] . toString ( ) ) ;
6461 if ( url ) {
65- const attack = this . inspectHostname (
66- agent ,
67- url . hostname ,
68- getPortFromURL ( url )
69- ) ;
62+ const attack = this . inspectHostname ( agent , url , getPortFromURL ( url ) ) ;
7063 if ( attack ) {
7164 return attack ;
7265 }
@@ -77,7 +70,7 @@ export class Fetch implements Wrapper {
7770 if ( args [ 0 ] instanceof URL && args [ 0 ] . hostname . length > 0 ) {
7871 const attack = this . inspectHostname (
7972 agent ,
80- args [ 0 ] . hostname ,
73+ args [ 0 ] ,
8174 getPortFromURL ( args [ 0 ] )
8275 ) ;
8376 if ( attack ) {
@@ -89,11 +82,7 @@ export class Fetch implements Wrapper {
8982 if ( args [ 0 ] instanceof Request ) {
9083 const url = tryParseURL ( args [ 0 ] . url ) ;
9184 if ( url ) {
92- const attack = this . inspectHostname (
93- agent ,
94- url . hostname ,
95- getPortFromURL ( url )
96- ) ;
85+ const attack = this . inspectHostname ( agent , url , getPortFromURL ( url ) ) ;
9786 if ( attack ) {
9887 return attack ;
9988 }
0 commit comments