MCPcopy Create free account
hub / github.com/apache/impala / IsTrustedDomain

Function IsTrustedDomain

be/src/rpc/authentication-util.cc:190–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190bool IsTrustedDomain(const std::string& origin, const std::string& trusted_domain,
191 bool strict_localhost) {
192 if (trusted_domain.empty()) return false;
193 vector<string> split = Split(origin, delimiter::Limit(",", 1));
194 if (split.empty()) return false;
195 kudu::Sockaddr sock_addr = kudu::Sockaddr::Wildcard();
196 kudu::Status s = sock_addr.ParseString(split[0], 0);
197 string host_name;
198 if (!s.ok()) {
199 VLOG(2) << "Origin address did not parse as a valid IP address. Assuming it to be a "
200 "domain name. Reason: " << s.ToString();
201 // Remove port if its a part of the origin.
202 vector<string> host_n_port = Split(split[0], delimiter::Limit(":", 1));
203 host_name = host_n_port[0];
204 } else {
205 // If using strict localhost checks, only allow localhost to match 127.0.0.1
206 if (trusted_domain == "localhost" && strict_localhost) {
207 return sock_addr.host() == "127.0.0.1";
208 }
209 s = sock_addr.LookupHostname(&host_name);
210 if (!s.ok()) {
211 LOG(ERROR) << "DNS reverse-lookup failed for " << split[0]
212 << " Error: " << s.ToString();
213 return false;
214 }
215 }
216 return HasSuffixString(host_name, trusted_domain);
217}
218
219Status GetXFFOriginClientAddress(const std::string_view& xff_addresses,
220 std::string& origin) {

Callers 2

TrustedDomainCheckFunction · 0.85
TrustedDomainCheckMethod · 0.85

Calls 9

SplitFunction · 0.85
LimitFunction · 0.85
HasSuffixStringFunction · 0.85
hostMethod · 0.80
LookupHostnameMethod · 0.80
emptyMethod · 0.45
ParseStringMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected