MCPcopy
hub / github.com/Doorman11991/smallcode / hostVariants

Function hostVariants

src/compiled/providers/ssrf_guard.js:35–53  ·  view source on GitHub ↗
(host)

Source from the content-addressed store, hash-verified

33// like `[::ffff:169.254.169.254]` slips a dotted-quad regex but resolves
34// directly to 169.254.169.254 at connect time.
35function hostVariants(host) {
36 const out = new Set();
37 const lower = host.toLowerCase();
38 out.add(lower);
39 let h = lower;
40 if (h.startsWith("[") && h.endsWith("]")) {
41 h = h.slice(1, -1);
42 out.add(h);
43 }
44 const dotted = h.match(/^(?:::ffff:|::)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
45 if (dotted)
46 out.add(dotted[1]);
47 const hex = h.match(/^(?:::ffff:|::)([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
48 if (hex) {
49 const a = parseInt(hex[1], 16), b = parseInt(hex[2], 16);
50 out.add(`${(a >> 8) & 0xff}.${a & 0xff}.${(b >> 8) & 0xff}.${b & 0xff}`);
51 }
52 return [...out];
53}
54function isLoopbackOne(h) {
55 if (h === "localhost" || h === "::1" || h === "::")
56 return true;

Callers 3

isLoopbackFunction · 0.70
isRfc1918Function · 0.70
isAlwaysBlockedFunction · 0.70

Calls 1

addMethod · 0.80

Tested by

no test coverage detected