#include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int UNACCEPTABLE_URL; } void StorageOfAllowedURL::checkURL(const Poco::URI & uri) { if (!checkString(uri.getHost()) && !checkString(uri.getHost() + ":" + toString(uri.getPort()))) throw Exception("URL \"" + uri.toString() + "\" is not allowed in config.xml", ErrorCodes::UNACCEPTABLE_URL); } void StorageOfAllowedURL::checkHostAndPort(const std::string & host, const std::string & port) { if (!checkString(host) && !checkString(host + ":" + port)) throw Exception("URL \"" + host + ":" + port + "\" is not allowed in config.xml", ErrorCodes::UNACCEPTABLE_URL); } void StorageOfAllowedURL::setValuesFromConfig(const Poco::Util::AbstractConfiguration & config) { if (config.has("remote_url_allow_hosts")) { std::vector keys; config.keys("remote_url_allow_hosts", keys); for (auto key : keys) { if (startsWith(key, "host_regexp")) regexp_hosts.push_back(config.getString("remote_url_allow_hosts." + key)); else if (startsWith(key, "host")) primary_hosts.insert(config.getString("remote_url_allow_hosts." + key)); } } } bool StorageOfAllowedURL::checkString(const std::string &host) { if (!primary_hosts.empty() || !regexp_hosts.empty()) { if (primary_hosts.find(host) == primary_hosts.end()) { for (size_t i = 0; i < regexp_hosts.size(); ++i) if (re2::RE2::FullMatch(host, regexp_hosts[i])) return true; return false; } return true; } return true; } }