FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
bool URI::isLocalhost ( ) const

Returns true if the URI appears to be a localhost address

See Also
resetValidLocalhost
registerValidLocalhost
Since
1.4b1

Definition at line 191 of file URI.cpp.

191  {
192  // To avoid a security breach by DNS poisioning, we make sure that the allowed
193  // domain (either localhost or registered with registerValidLocalhost) actually
194  // is pointing at localhost / the correct IP.
195  StringStringMap tmp;
196  StringStringMap::const_iterator fnd(m_lhMap.find(domain));
197  if (fnd != m_lhMap.end()) {
198  if (fnd->first == boost::asio::ip::address_v4::loopback().to_string()) {
199  return true;
200  }
201  static boost::tribool lastResult(boost::indeterminate);
202  if (!boost::indeterminate(lastResult)) return lastResult;
203 
204  boost::asio::io_service io_service;
205  boost::asio::ip::tcp::resolver resolver(io_service);
206  // The resolver wants a service name, that's what the "80" is.
207  // The numeric_service flag tells it not to do anything with the service name anyway.
208  boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), domain, "80", boost::asio::ip::resolver_query_base::numeric_service);
209  boost::asio::ip::tcp::resolver::iterator it = resolver.resolve(query);
210  if (it == boost::asio::ip::tcp::resolver::iterator()) return false;
211  boost::asio::ip::tcp::endpoint ep = it->endpoint();
212 
213  lastResult = (bool) (ep.address() == boost::asio::ip::address_v4::loopback());
214  return lastResult;
215  }
216  return false;
217 }