Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: net/http/http_network_transaction.cc

Issue 164504: Unescape username/passwords obtained from URLs before using them for HTTP aut... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/field_trial.h" 9 #include "base/field_trial.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 DCHECK(auth_handler_[target]); 1660 DCHECK(auth_handler_[target]);
1661 DCHECK(auth_identity_[target].invalid); 1661 DCHECK(auth_identity_[target].invalid);
1662 1662
1663 // Try to use the username/password encoded into the URL first. 1663 // Try to use the username/password encoded into the URL first.
1664 // (By checking source == IDENT_SRC_NONE, we make sure that this 1664 // (By checking source == IDENT_SRC_NONE, we make sure that this
1665 // is only done once for the transaction.) 1665 // is only done once for the transaction.)
1666 if (target == HttpAuth::AUTH_SERVER && request_->url.has_username() && 1666 if (target == HttpAuth::AUTH_SERVER && request_->url.has_username() &&
1667 auth_identity_[target].source == HttpAuth::IDENT_SRC_NONE) { 1667 auth_identity_[target].source == HttpAuth::IDENT_SRC_NONE) {
1668 auth_identity_[target].source = HttpAuth::IDENT_SRC_URL; 1668 auth_identity_[target].source = HttpAuth::IDENT_SRC_URL;
1669 auth_identity_[target].invalid = false; 1669 auth_identity_[target].invalid = false;
1670 // TODO(wtc) It may be necessary to unescape the username and password 1670 // Extract the username:password from the URL.
wtc 2009/08/13 21:37:36 I wrote this TODO(wtc) based on what Darin told me
1671 // after extracting them from the URL. We should be careful about 1671 GetIdentifyFromUrl(request_->url,
1672 // embedded nulls in that case. 1672 &auth_identity_[target].username,
1673 auth_identity_[target].username = ASCIIToWide(request_->url.username()); 1673 &auth_identity_[target].password);
1674 auth_identity_[target].password = ASCIIToWide(request_->url.password());
1675 // TODO(eroman): If the password is blank, should we also try combining 1674 // TODO(eroman): If the password is blank, should we also try combining
1676 // with a password from the cache? 1675 // with a password from the cache?
1677 return true; 1676 return true;
1678 } 1677 }
1679 1678
1680 // Check the auth cache for a realm entry. 1679 // Check the auth cache for a realm entry.
1681 HttpAuthCache::Entry* entry = session_->auth_cache()->LookupByRealm( 1680 HttpAuthCache::Entry* entry = session_->auth_cache()->LookupByRealm(
1682 AuthOrigin(target), auth_handler_[target]->realm()); 1681 AuthOrigin(target), auth_handler_[target]->realm());
1683 1682
1684 if (entry) { 1683 if (entry) {
(...skipping 16 matching lines...) Expand all
1701 1700
1702 auth_identity_[target].source = HttpAuth::IDENT_SRC_REALM_LOOKUP; 1701 auth_identity_[target].source = HttpAuth::IDENT_SRC_REALM_LOOKUP;
1703 auth_identity_[target].invalid = false; 1702 auth_identity_[target].invalid = false;
1704 auth_identity_[target].username = entry->username(); 1703 auth_identity_[target].username = entry->username();
1705 auth_identity_[target].password = entry->password(); 1704 auth_identity_[target].password = entry->password();
1706 return true; 1705 return true;
1707 } 1706 }
1708 return false; 1707 return false;
1709 } 1708 }
1710 1709
1710 // static
1711 void HttpNetworkTransaction::GetIdentifyFromUrl(const GURL& url,
1712 std::wstring* username,
1713 std::wstring* password) {
1714 UnescapeRule::Type flags = UnescapeRule::SPACES;
1715 *username = UnescapeAndDecodeUTF8URLComponent(url.username(), flags);
brettw 2009/08/13 20:03:34 Just making sure you're sure you know what you wan
eroman 2009/08/13 20:35:36 right, this should be kosher. username/password a
1716 *password = UnescapeAndDecodeUTF8URLComponent(url.password(), flags);
1717 }
1718
1711 std::string HttpNetworkTransaction::AuthChallengeLogMessage() const { 1719 std::string HttpNetworkTransaction::AuthChallengeLogMessage() const {
1712 std::string msg; 1720 std::string msg;
1713 std::string header_val; 1721 std::string header_val;
1714 void* iter = NULL; 1722 void* iter = NULL;
1715 while (response_.headers->EnumerateHeader(&iter, "proxy-authenticate", 1723 while (response_.headers->EnumerateHeader(&iter, "proxy-authenticate",
1716 &header_val)) { 1724 &header_val)) {
1717 msg.append("\n Has header Proxy-Authenticate: "); 1725 msg.append("\n Has header Proxy-Authenticate: ");
1718 msg.append(header_val); 1726 msg.append(header_val);
1719 } 1727 }
1720 1728
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 host_and_port = proxy_info_.proxy_server().host_and_port(); 1835 host_and_port = proxy_info_.proxy_server().host_and_port();
1828 } else { 1836 } else {
1829 DCHECK(target == HttpAuth::AUTH_SERVER); 1837 DCHECK(target == HttpAuth::AUTH_SERVER);
1830 host_and_port = GetHostAndPort(request_->url); 1838 host_and_port = GetHostAndPort(request_->url);
1831 } 1839 }
1832 auth_info->host_and_port = ASCIIToWide(host_and_port); 1840 auth_info->host_and_port = ASCIIToWide(host_and_port);
1833 response_.auth_challenge = auth_info; 1841 response_.auth_challenge = auth_info;
1834 } 1842 }
1835 1843
1836 } // namespace net 1844 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698