refactor: revert url::DomainIs() for cookie domains (#44153)
build: revert DomainIs refactor
This commit is contained in:
parent
ebeae6f301
commit
08d315da14
3 changed files with 21 additions and 57 deletions
|
@ -30,7 +30,6 @@
|
|||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/gin_helper/object_template_builder.h"
|
||||
#include "shell/common/gin_helper/promise.h"
|
||||
#include "url/url_util.h"
|
||||
|
||||
namespace gin {
|
||||
|
||||
|
@ -101,12 +100,25 @@ namespace electron::api {
|
|||
|
||||
namespace {
|
||||
|
||||
bool DomainIs(std::string_view host, const std::string_view domain) {
|
||||
// Strip any leading '.' character from the input cookie domain.
|
||||
if (host.starts_with('.'))
|
||||
host.remove_prefix(1);
|
||||
// Returns whether |domain| matches |filter|.
|
||||
bool MatchesDomain(std::string filter, const std::string& domain) {
|
||||
// Add a leading '.' character to the filter domain if it doesn't exist.
|
||||
if (net::cookie_util::DomainIsHostOnly(filter))
|
||||
filter.insert(0, ".");
|
||||
|
||||
return url::DomainIs(host, domain);
|
||||
std::string sub_domain(domain);
|
||||
// Strip any leading '.' character from the input cookie domain.
|
||||
if (!net::cookie_util::DomainIsHostOnly(sub_domain))
|
||||
sub_domain = sub_domain.substr(1);
|
||||
|
||||
// Now check whether the domain argument is a subdomain of the filter domain.
|
||||
for (sub_domain.insert(0, "."); sub_domain.length() >= filter.length();) {
|
||||
if (sub_domain == filter)
|
||||
return true;
|
||||
const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
|
||||
sub_domain.erase(0, next_dot);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns whether |cookie| matches |filter|.
|
||||
|
@ -117,7 +129,8 @@ bool MatchesCookie(const base::Value::Dict& filter,
|
|||
return false;
|
||||
if ((str = filter.FindString("path")) && *str != cookie.Path())
|
||||
return false;
|
||||
if ((str = filter.FindString("domain")) && !DomainIs(cookie.Domain(), *str))
|
||||
if ((str = filter.FindString("domain")) &&
|
||||
!MatchesDomain(*str, cookie.Domain()))
|
||||
return false;
|
||||
std::optional<bool> secure_filter = filter.FindBool("secure");
|
||||
if (secure_filter && *secure_filter != cookie.SecureAttribute())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue