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

Side by Side Diff: Source/core/dom/Document.cpp

Issue 50573004: Don't set document.domain to an IP address fragment. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: missing weboriginexport header Created 7 years, 1 month 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 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 #include "core/svg/SVGStyleElement.h" 167 #include "core/svg/SVGStyleElement.h"
168 #include "core/xml/XSLTProcessor.h" 168 #include "core/xml/XSLTProcessor.h"
169 #include "core/xml/parser/XMLDocumentParser.h" 169 #include "core/xml/parser/XMLDocumentParser.h"
170 #include "platform/DateComponents.h" 170 #include "platform/DateComponents.h"
171 #include "platform/Language.h" 171 #include "platform/Language.h"
172 #include "platform/Timer.h" 172 #include "platform/Timer.h"
173 #include "platform/TraceEvent.h" 173 #include "platform/TraceEvent.h"
174 #include "platform/network/HTTPParsers.h" 174 #include "platform/network/HTTPParsers.h"
175 #include "platform/text/PlatformLocale.h" 175 #include "platform/text/PlatformLocale.h"
176 #include "platform/text/SegmentedString.h" 176 #include "platform/text/SegmentedString.h"
177 #include "weborigin/OriginAccessEntry.h"
177 #include "weborigin/SchemeRegistry.h" 178 #include "weborigin/SchemeRegistry.h"
178 #include "weborigin/SecurityOrigin.h" 179 #include "weborigin/SecurityOrigin.h"
179 #include "wtf/CurrentTime.h" 180 #include "wtf/CurrentTime.h"
180 #include "wtf/HashFunctions.h" 181 #include "wtf/HashFunctions.h"
181 #include "wtf/MainThread.h" 182 #include "wtf/MainThread.h"
182 #include "wtf/PassRefPtr.h" 183 #include "wtf/PassRefPtr.h"
183 #include "wtf/StdLibExtras.h" 184 #include "wtf/StdLibExtras.h"
184 #include "wtf/TemporaryChange.h" 185 #include "wtf/TemporaryChange.h"
185 #include "wtf/UnusedParam.h" 186 #include "wtf/UnusedParam.h"
186 #include "wtf/text/StringBuffer.h" 187 #include "wtf/text/StringBuffer.h"
(...skipping 3567 matching lines...) Expand 10 before | Expand all | Expand 10 after
3754 return securityOrigin()->domain(); 3755 return securityOrigin()->domain();
3755 } 3756 }
3756 3757
3757 void Document::setDomain(const String& newDomain, ExceptionState& es) 3758 void Document::setDomain(const String& newDomain, ExceptionState& es)
3758 { 3759 {
3759 if (SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(securityOrigin() ->protocol())) { 3760 if (SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(securityOrigin() ->protocol())) {
3760 es.throwSecurityError(ExceptionMessages::failedToSet("domain", "Document ", "assignment is forbidden for the '" + securityOrigin()->protocol() + "' schem e.")); 3761 es.throwSecurityError(ExceptionMessages::failedToSet("domain", "Document ", "assignment is forbidden for the '" + securityOrigin()->protocol() + "' schem e."));
3761 return; 3762 return;
3762 } 3763 }
3763 3764
3764 // Both NS and IE specify that changing the domain is only allowed when 3765 String exceptionMessage = ExceptionMessages::failedToSet("domain", "Document ", "'" + newDomain + "' is not a suffix of '" + domain() + "'.");
3765 // the new domain is a suffix of the old domain. 3766 if (newDomain.isEmpty()) {
3766
3767 // If the new domain is the same as the old domain, still call
3768 // securityOrigin()->setDomainForDOM. This will change the
3769 // security check behavior. For example, if a page loaded on port 8000
3770 // assigns its current domain using document.domain, the page will
3771 // allow other pages loaded on different ports in the same domain that
3772 // have also assigned to access this page.
3773 if (equalIgnoringCase(domain(), newDomain)) {
3774 securityOrigin()->setDomainFromDOM(newDomain);
3775 if (m_frame)
3776 m_frame->script().updateSecurityOrigin();
3777 return;
3778 }
3779
3780 int oldLength = domain().length();
3781 int newLength = newDomain.length();
3782 String exceptionMessage = ExceptionMessages::failedToSet("domain", "Documen t", "'" + newDomain + "' is not a suffix of '" + domain() + "'.");
3783 // e.g. newDomain = subdomain.www.example.com (25) and domain() = www.exampl e.com (15)
3784 if (newLength >= oldLength) {
3785 es.throwSecurityError(exceptionMessage); 3767 es.throwSecurityError(exceptionMessage);
3786 return; 3768 return;
3787 } 3769 }
3788 3770
3789 String test = domain(); 3771 OriginAccessEntry::IPAddressSetting ipAddressSetting = settings() && setting s()->treatIPAddressAsDomain() ? OriginAccessEntry::TreatIPAddressAsDomain : Orig inAccessEntry::TreatIPAddressAsIPAddress;
3790 // Check that it's a complete suffix, not e.g. "ample.com" 3772 OriginAccessEntry accessEntry(securityOrigin()->protocol(), newDomain, Origi nAccessEntry::AllowSubdomains, ipAddressSetting);
3791 if (test[oldLength - newLength - 1] != '.') { 3773 if (!accessEntry.matchesOrigin(*securityOrigin())) {
3792 es.throwSecurityError(exceptionMessage); 3774 es.throwSecurityError(exceptionMessage);
3793 return; 3775 return;
3794 } 3776 }
3795
3796 // Now test is "example.com" from domain()
3797 // and we check that it's the same thing as newDomain
3798 test.remove(0, oldLength - newLength);
3799 if (test != newDomain) {
3800 es.throwSecurityError(exceptionMessage);
3801 return;
3802 }
3803 3777
3804 securityOrigin()->setDomainFromDOM(newDomain); 3778 securityOrigin()->setDomainFromDOM(newDomain);
3805 if (m_frame) 3779 if (m_frame)
3806 m_frame->script().updateSecurityOrigin(); 3780 m_frame->script().updateSecurityOrigin();
3807 } 3781 }
3808 3782
3809 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-lastmodified 3783 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-lastmodified
3810 String Document::lastModified() const 3784 String Document::lastModified() const
3811 { 3785 {
3812 DateComponents date; 3786 DateComponents date;
(...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after
5251 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode) 5225 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode)
5252 { 5226 {
5253 if (!isActive()) 5227 if (!isActive())
5254 return; 5228 return;
5255 5229
5256 styleEngine()->modifiedStyleSheet(sheet); 5230 styleEngine()->modifiedStyleSheet(sheet);
5257 styleResolverChanged(when, updateMode); 5231 styleResolverChanged(when, updateMode);
5258 } 5232 }
5259 5233
5260 } // namespace WebCore 5234 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/xmlhttprequest/document-domain-set.html ('k') | Source/core/page/Settings.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698