| 188 | } |
| 189 | |
| 190 | bool 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 | |
| 219 | Status GetXFFOriginClientAddress(const std::string_view& xff_addresses, |
| 220 | std::string& origin) { |
no test coverage detected