@@ -141,8 +141,6 @@ static void remove_from_beginning(std::vector<char>* buffer, size_t count) {
141
141
buffer->erase (buffer->begin (), buffer->begin () + count);
142
142
}
143
143
144
- // Cleanup
145
-
146
144
static const char CLOSE_FRAME[] = {' \x88 ' , ' \x00 ' };
147
145
148
146
enum ws_decode_result {
@@ -160,15 +158,6 @@ static void generate_accept_string(const std::string& client_key,
160
158
node::base64_encode (hash, sizeof (hash), *buffer, sizeof (*buffer));
161
159
}
162
160
163
- static bool IsOneOf (const std::string& host,
164
- const std::vector<std::string>& hosts) {
165
- for (const std::string& candidate : hosts) {
166
- if (node::StringEqualNoCase (host.data (), candidate.data ()))
167
- return true ;
168
- }
169
- return false ;
170
- }
171
-
172
161
static std::string TrimPort (const std::string& host) {
173
162
size_t last_colon_pos = host.rfind (" :" );
174
163
if (last_colon_pos == std::string::npos)
@@ -192,16 +181,6 @@ static bool IsIPAddress(const std::string& host) {
192
181
return quads == 3 ;
193
182
}
194
183
195
- // This is a value coming from the interface, it can only be IPv4 or IPv6
196
- // address string.
197
- static bool IsIPv4Localhost (const std::string& host) {
198
- std::string v6_tunnel_prefix = " ::ffff:" ;
199
- if (host.substr (0 , v6_tunnel_prefix.length ()) == v6_tunnel_prefix)
200
- return IsIPv4Localhost (host.substr (v6_tunnel_prefix.length ()));
201
- std::string localhost_net = " 127." ;
202
- return host.substr (0 , localhost_net.length ()) == localhost_net;
203
- }
204
-
205
184
// Constants for hybi-10 frame format.
206
185
207
186
typedef int OpCode;
@@ -600,17 +579,9 @@ class HttpHandler : public ProtocolHandler {
600
579
601
580
bool IsAllowedHost (const std::string& host_with_port) const {
602
581
std::string host = TrimPort (host_with_port);
603
- if (host.empty ())
604
- return false ;
605
- if (IsIPAddress (host))
606
- return true ;
607
- std::string socket_host = GetHost ();
608
- if (IsIPv4Localhost (socket_host)) {
609
- return IsOneOf (host, { " localhost" });
610
- } else if (socket_host == " ::1" ) {
611
- return IsOneOf (host, { " localhost" , " localhost6" });
612
- }
613
- return true ;
582
+ return host.empty () || IsIPAddress (host)
583
+ || node::StringEqualNoCase (host.data (), " localhost" )
584
+ || node::StringEqualNoCase (host.data (), " localhost6" );
614
585
}
615
586
616
587
bool parsing_value_;
0 commit comments