File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 3
3
namespace Kiwicom \Loopbind \Config ;
4
4
5
5
use JsonSerializable ;
6
+ use Kiwicom \Loopbind \Helpers \IPHelpers ;
6
7
use function array_map ;
7
8
use function filter_var ;
8
9
use function is_array ;
@@ -37,10 +38,10 @@ public function __construct(
37
38
array_map (fn (string $ host ): bool => filter_var ($ host , FILTER_VALIDATE_DOMAIN , FILTER_FLAG_HOSTNAME ) === false ?
38
39
throw new \Kiwicom \Loopbind \Exceptions \InvalidHostnameException ("Value ` {$ host }` is not valid hostname. " ) : true , $ hostname );
39
40
40
- array_map (fn (string $ hostname ): bool => $ hostname === ' localhost ' ?
41
+ array_map (fn (string $ hostname ): bool => IPHelpers:: isForbiddenDomain ( $ hostname) ?
41
42
throw new \Kiwicom \Loopbind \Exceptions \InvalidHostnameException ("Hostname ` {$ hostname }` is forbidden by this tool. " ) : true , $ hostname );
42
43
}
43
- if ($ hostname === ' localhost ' ) {
44
+ if (is_string ( $ hostname) && IPHelpers:: isForbiddenDomain ( $ hostname ) ) {
44
45
throw new \Kiwicom \Loopbind \Exceptions \InvalidHostnameException ("Hostname ` {$ hostname }` is forbidden by this tool. " );
45
46
}
46
47
Original file line number Diff line number Diff line change @@ -34,4 +34,31 @@ public static function findRandomFreeLocalIP(): string
34
34
}
35
35
throw new UnableToFindUnreferencedIPAddressException ();
36
36
}
37
+
38
+ /**
39
+ * Returns true iff the given URL is a forbidden domain
40
+ * @param string $url
41
+ * @return bool
42
+ */
43
+ public static function isForbiddenDomain (string $ url ): bool
44
+ {
45
+ $ url = mb_strtolower ($ url );
46
+ $ forbidden = [
47
+ 'localhost ' ,
48
+ 'localhost4 ' ,
49
+ 'localhost6 ' ,
50
+ 'localhost.localdomain ' ,
51
+ 'localhost4.localdomain4 ' ,
52
+ 'localhost6.localdomain6 ' ,
53
+ 'ip6-localhost ' ,
54
+ 'ip6-loopback ' ,
55
+ 'ip6-localnet ' ,
56
+ 'ip6-mcastprefix ' ,
57
+ 'ip6-allnodes ' ,
58
+ 'ip6-allrouters ' ,
59
+ 'ip6-allhosts ' ,
60
+ 'broadcasthost '
61
+ ];
62
+ return in_array ($ url , $ forbidden , true );
63
+ }
37
64
}
You can’t perform that action at this time.
0 commit comments