diff --git a/dbms/src/Common/RemoteHostFilter.cpp b/dbms/src/Common/RemoteHostFilter.cpp index c6e9495230f..2b0b2245c6d 100644 --- a/dbms/src/Common/RemoteHostFilter.cpp +++ b/dbms/src/Common/RemoteHostFilter.cpp @@ -14,14 +14,14 @@ namespace ErrorCodes extern const int UNACCEPTABLE_URL; } -void RemoteHostFilter::checkURL(const Poco::URI & uri) +void RemoteHostFilter::checkURL(const Poco::URI & uri) const { 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 RemoteHostFilter::checkHostAndPort(const std::string & host, const std::string & port) +void RemoteHostFilter::checkHostAndPort(const std::string & host, const std::string & port) const { if (!checkString(host) && !checkString(host + ":" + port)) @@ -44,7 +44,7 @@ void RemoteHostFilter::setValuesFromConfig(const Poco::Util::AbstractConfigurati } } -bool RemoteHostFilter::checkString(const std::string &host) +bool RemoteHostFilter::checkString(const std::string &host) const { if (!primary_hosts.empty() || !regexp_hosts.empty()) { diff --git a/dbms/src/Common/RemoteHostFilter.h b/dbms/src/Common/RemoteHostFilter.h index be9b55dc888..859b92a2985 100644 --- a/dbms/src/Common/RemoteHostFilter.h +++ b/dbms/src/Common/RemoteHostFilter.h @@ -11,16 +11,18 @@ namespace DB class RemoteHostFilter { public: - void checkURL(const Poco::URI &uri); /// If URL not allowed in config.xml throw UNACCEPTABLE_URL Exception + void checkURL(const Poco::URI &uri) const; /// If URL not allowed in config.xml throw UNACCEPTABLE_URL Exception void setValuesFromConfig(const Poco::Util::AbstractConfiguration &config); - void checkHostAndPort(const std::string & host, const std::string & port); + void checkHostAndPort(const std::string & host, const std::string & port) const; + + RemoteHostFilter() {} private: std::unordered_set primary_hosts; /// Allowed primary () URL from config.xml std::vector regexp_hosts; /// Allowed regexp () URL from config.xml - bool checkString(const std::string &host); + bool checkString(const std::string &host) const; }; } diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index 0159b90ceed..b6f35c80252 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -1562,7 +1562,7 @@ void Context::setRemoteHostFilter(const Poco::Util::AbstractConfiguration & conf shared->remote_host_filter.setValuesFromConfig(config); } -RemoteHostFilter & Context::getRemoteHostFilter() const +const RemoteHostFilter & Context::getRemoteHostFilter() const { return shared->remote_host_filter; } diff --git a/dbms/src/Interpreters/Context.h b/dbms/src/Interpreters/Context.h index ebfe8a77f80..9bd1f564f6c 100644 --- a/dbms/src/Interpreters/Context.h +++ b/dbms/src/Interpreters/Context.h @@ -350,7 +350,7 @@ public: /// Storage of allowed hosts from config.xml void setRemoteHostFilter(const Poco::Util::AbstractConfiguration & config); - RemoteHostFilter & getRemoteHostFilter() const; + const RemoteHostFilter & getRemoteHostFilter() const; /// The port that the server listens for executing SQL queries. UInt16 getTCPPort() const; diff --git a/dbms/src/Storages/StorageURL.cpp b/dbms/src/Storages/StorageURL.cpp index cc409230373..3fbf8d7fb63 100644 --- a/dbms/src/Storages/StorageURL.cpp +++ b/dbms/src/Storages/StorageURL.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -57,7 +57,7 @@ namespace : name(name_) { context.getRemoteHostFilter().checkURL(uri); - read_buf = std::make_unique(uri, method, callback, timeouts, context.getSettingsRef().max_http_get_redirects); + read_buf = std::make_unique(uri, method, callback, timeouts, context.getSettingsRef().max_http_get_redirects, context.getRemoteHostFilter()); reader = FormatFactory::instance().getInput(format, *read_buf, sample_block, context, max_block_size); } @@ -88,7 +88,7 @@ namespace private: String name; - std::unique_ptr read_buf; + std::unique_ptr read_buf; BlockInputStreamPtr reader; }; diff --git a/dbms/src/Storages/StorageURL.h b/dbms/src/Storages/StorageURL.h index 43964e91273..cdd78c7b60f 100644 --- a/dbms/src/Storages/StorageURL.h +++ b/dbms/src/Storages/StorageURL.h @@ -66,9 +66,6 @@ private: size_t max_block_size) const; virtual Block getHeaderBlock(const Names & column_names) const = 0; - - /// Return true if host allowed - bool checkHost(const std::string & host); };