Skip to content

Commit e554ce7

Browse files
J12934Weltraumschaf
authored andcommitted
Make the hostname parsing more stable for urls
Signed-off-by: Jannik Hollenbach <[email protected]>
1 parent 128e1e2 commit e554ce7

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

scanners/nuclei/parser/parser.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ function parseHostname(host) {
9797
if (!host) {
9898
return null;
9999
}
100+
// If the host doesn't have a proper protocol, add one to make URL parsing work
101+
const hasValidProtocol = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(host);
102+
103+
if (!hasValidProtocol) {
104+
return host;
105+
}
100106

101107
try {
102-
// If the host doesn't have a protocol, add one to make URL parsing work
103-
const urlString = host.includes("://") ? host : `http://${host}`;
104-
const url = new URL(urlString);
108+
const url = new URL(host);
105109
return url.hostname;
106110
} catch (err) {
107111
// If URL parsing fails, check if the host is already a hostname (no protocol, no path)

0 commit comments

Comments
 (0)