Chromium Code Reviews| Index: net/base/sdch_manager.cc |
| diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc |
| index 59589fb544723d386fa37019dd30a574cd8432d0..32f09da6c85f9b2712b5be437ace1ff0809987d3 100644 |
| --- a/net/base/sdch_manager.cc |
| +++ b/net/base/sdch_manager.cc |
| @@ -13,6 +13,40 @@ |
| #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| #include "net/url_request/url_request_http_job.h" |
| +namespace { |
| + |
| +// Spec collision warning: URLs may have domain names which have a |
| +// trailing "." (e.g. "http://this.is.a.domain.com./file.txt"). The |
| +// SDCH spec was written to parallel RFC 2965 (an old version of the |
| +// cookie spec, which didn't precisely address the issue of trailing "."s. |
| +// The newest version of the cookie spec, RFC 6265, specifically prohibits |
| +// trailing "."s from cookie domains. So we prohibit trailing "."s in |
| +// dictionary domains, and strip any trailing "." from URL domains. |
| +bool StripTrailingDot(std::string* host) { |
| + if (host->size() == 0) |
|
Ryan Sleevi
2014/09/22 20:30:37
host->empty()
(a nit I hold on to from the days o
Randy Smith (Not in Mondays)
2014/09/23 19:52:58
Done.
|
| + return false; |
| + |
| + if ((*host)[host->size() - 1] != '.') |
|
Ryan Sleevi
2014/09/22 20:30:36
if (*host->rbegin() != '.')
return false;
Lazin
Randy Smith (Not in Mondays)
2014/09/23 19:52:58
Agreed :-}. Done.
|
| + return false; |
| + |
| + host->resize(host->size() - 1); |
| + return true; |
| +} |
| + |
| +void StripTrailingDotURL(GURL* gurl) { |
|
Ryan Sleevi
2014/09/22 20:30:36
naming wise, this felt a little weird, although I
Randy Smith (Not in Mondays)
2014/09/23 19:52:58
I don't want "NormalizeToDictionary" because to me
|
| + std::string host(gurl->host()); |
| + |
| + if (!StripTrailingDot(&host)) |
| + return; |
|
Ryan Sleevi
2014/09/22 20:30:36
Just inline this? You never use "StripTrailingDot"
Randy Smith (Not in Mondays)
2014/09/23 19:52:58
Done.
|
| + |
| + GURL::Replacements replacements; |
| + replacements.SetHostStr(host); |
| + *gurl = gurl->ReplaceComponents(replacements); |
| + return; |
| +} |
| + |
| +} // namespace |
| + |
| namespace net { |
| //------------------------------------------------------------------------------ |
| @@ -405,15 +439,19 @@ void SdchManager::GetVcdiffDictionary( |
| const GURL& referring_url, |
| scoped_refptr<Dictionary>* dictionary) { |
| DCHECK(CalledOnValidThread()); |
| + |
| + GURL referring_url_hdn(referring_url); |
| + StripTrailingDotURL(&referring_url_hdn); |
| + |
| *dictionary = NULL; |
| DictionaryMap::iterator it = dictionaries_.find(server_hash); |
| if (it == dictionaries_.end()) { |
| return; |
| } |
| scoped_refptr<Dictionary> matching_dictionary = it->second; |
| - if (!IsInSupportedDomain(referring_url)) |
| + if (!IsInSupportedDomain(referring_url_hdn)) |
| return; |
| - if (!matching_dictionary->CanUse(referring_url)) |
| + if (!matching_dictionary->CanUse(referring_url_hdn)) |
|
Ryan Sleevi
2014/09/22 20:30:37
OK, I'm fairly confused now why it's necessary to
Randy Smith (Not in Mondays)
2014/09/22 20:43:51
This isn't necessary; it's the checks in AddSdchDi
|
| return; |
| *dictionary = matching_dictionary; |
| } |
| @@ -424,12 +462,16 @@ void SdchManager::GetVcdiffDictionary( |
| void SdchManager::GetAvailDictionaryList(const GURL& target_url, |
| std::string* list) { |
| DCHECK(CalledOnValidThread()); |
| + |
| + GURL target_url_hdn(target_url); |
| + StripTrailingDotURL(&target_url_hdn); |
| + |
| int count = 0; |
| for (DictionaryMap::iterator it = dictionaries_.begin(); |
| it != dictionaries_.end(); ++it) { |
| - if (!IsInSupportedDomain(target_url)) |
| + if (!IsInSupportedDomain(target_url_hdn)) |
| continue; |
| - if (!it->second->CanAdvertise(target_url)) |
| + if (!it->second->CanAdvertise(target_url_hdn)) |
| continue; |
| ++count; |
| if (!list->empty()) |
| @@ -479,7 +521,7 @@ void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) { |
| } |
| void SdchManager::AddSdchDictionary(const std::string& dictionary_text, |
|
Ryan Sleevi
2014/09/22 20:55:26
style nits: Perhaps for a future CL, but this shou
|
| - const GURL& dictionary_url) { |
| + const GURL& dictionary_url_const) { |
|
Ryan Sleevi
2014/09/22 20:55:26
pedantry naming: dictionary_url here, and normaliz
Randy Smith (Not in Mondays)
2014/09/23 19:52:58
Done.
|
| DCHECK(CalledOnValidThread()); |
| std::string client_hash; |
| std::string server_hash; |
| @@ -550,6 +592,19 @@ void SdchManager::AddSdchDictionary(const std::string& dictionary_text, |
| line_start = line_end + 1; |
|
Ryan Sleevi
2014/09/22 20:55:27
if line_end == npos, this will wrap around to 0 (s
|
| } |
| + // Forbid dictionary with trailing dots; the SDCH spec is explicitly |
| + // patterned after an old cookie spec (RFC 2695) which is silent on |
| + // the issue of trailing dots, and the newer cookie spec (RFC 6265) |
| + // explicitly forbids them. |
| + if (domain.size() != 0 && domain[domain.size() - 1] == '.') { |
| + SdchErrorRecovery(DICTIONARY_DOMAIN_HAS_TRAILING_PERIOD); |
| + return; |
|
Ryan Sleevi
2014/09/22 20:55:27
From your reply, it _seems_ that this is the ONLY
Randy Smith (Not in Mondays)
2014/09/22 21:09:56
I don't believe so; I think the stripping of the d
Ryan Sleevi
2014/09/22 22:49:42
I tried to work through why this is. That is, I'm
|
| + } |
| + |
| + // Strip trailing dot from the dictionary url before comparison. |
| + GURL dictionary_url(dictionary_url_const); |
| + StripTrailingDotURL(&dictionary_url); |
|
Randy Smith (Not in Mondays)
2014/09/23 17:36:43
>> I believe this is the only change required to s
|
| + |
| if (!IsInSupportedDomain(dictionary_url)) |
| return; |