Changeset 150916 in webkit


Ignore:
Timestamp:
May 29, 2013 11:46:40 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Handle Host-Only cookies
https://bugs.webkit.org/show_bug.cgi?id=116969

PR 338809
Patch by Otto Derek Cheung <otcheung@rim.com> on 2013-05-29
Reviewed by Rob Buis.
Internally Reviewed by Joe Mason.

Adding support for host-only cookies (cookies with no
specified domains). These cookies should only be returned
when the host matches the cookie domain exactly.

Tested using Opera and Browser cookie test suite. Tested
that host cookies are being stored in it's own map using
Web Inspector.

  • platform/blackberry/CookieManager.cpp:

(WebCore::CookieManager::getRawCookies):
(WebCore::CookieManager::checkAndTreatCookie):
(WebCore::CookieManager::findOrCreateCookieMap):

  • platform/blackberry/CookieParser.cpp:

(WebCore::CookieParser::CookieParser):
(WebCore::CookieParser::parseOneCookie):

  • platform/blackberry/ParsedCookie.h:

(WebCore::ParsedCookie::isHostOnly):
(ParsedCookie):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150912 r150916  
     12013-05-29  Otto Derek Cheung  <otcheung@rim.com>
     2
     3        [BlackBerry] Handle Host-Only cookies
     4        https://bugs.webkit.org/show_bug.cgi?id=116969
     5
     6        PR 338809
     7        Reviewed by Rob Buis.
     8        Internally Reviewed by Joe Mason.
     9
     10        Adding support for host-only cookies (cookies with no
     11        specified domains). These cookies should only be returned
     12        when the host matches the cookie domain exactly.
     13
     14        Tested using Opera and Browser cookie test suite. Tested
     15        that host cookies are being stored in it's own map using
     16        Web Inspector.
     17
     18        * platform/blackberry/CookieManager.cpp:
     19        (WebCore::CookieManager::getRawCookies):
     20        (WebCore::CookieManager::checkAndTreatCookie):
     21        (WebCore::CookieManager::findOrCreateCookieMap):
     22        * platform/blackberry/CookieParser.cpp:
     23        (WebCore::CookieParser::CookieParser):
     24        (WebCore::CookieParser::parseOneCookie):
     25        * platform/blackberry/ParsedCookie.h:
     26        (WebCore::ParsedCookie::isHostOnly):
     27        (ParsedCookie):
     28
    1292013-05-29  Ryosuke Niwa  <rniwa@webkit.org>
    230
  • trunk/Source/WebCore/platform/blackberry/CookieManager.cpp

    r149822 r150916  
    11/*
    22 * Copyright (C) 2008, 2009 Julien Chaffraix <julien.chaffraix@gmail.com>
    3  * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
     3 * Copyright (C) 2010, 2011, 2012, 2013 Research In Motion Limited. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    297297            currentMap->getAllCookies(&cookieCandidates);
    298298
     299            // Get cookies from Host-only cookies
     300            if (canonicalIP.empty()) {
     301                CookieLog("CookieManager - looking for host-only cookies for host - %s", requestURL.host().utf8().data());
     302                CookieMap* hostMap = currentMap->getSubdomainMap(requestURL.host());
     303                if (hostMap)
     304                    hostMap->getAllCookies(&cookieCandidates);
     305            }
     306
    299307            // Get cookies from the valid domain maps
    300308            int i = delimitedHost.size() - 1;
     
    423431    } else {
    424432        ASSERT(curMap);
     433        CookieLog("CookieManager - adding cookiemap - %s\n", curMap->getName().utf8().data());
    425434        addCookieToMap(curMap, candidateCookie, postToBackingStore, filter);
    426435    }
     
    549558    Vector<String> delimitedHost;
    550559
    551     // If the domain is an IP address, don't split it.
    552     if (candidateCookie->domainIsIPAddress())
     560    // If the domain is an IP address or is a host-only domain, don't split it.
     561    if (candidateCookie->domainIsIPAddress() || candidateCookie->isHostOnly())
    553562        delimitedHost.append(candidateCookie->domain());
    554563    else
  • trunk/Source/WebCore/platform/blackberry/CookieParser.cpp

    r149822 r150916  
    3333#include <wtf/CurrentTime.h>
    3434#include <wtf/text/CString.h>
     35#include <wtf/text/StringBuilder.h>
    3536
    3637namespace WebCore {
     
    6162        m_defaultCookieHost = hostDomainCanonical;
    6263        m_defaultDomainIsIPAddress = true;
    63     } else
    64         m_defaultCookieHost = m_defaultCookieHost.startsWith(".") ? m_defaultCookieHost : "." + m_defaultCookieHost;
     64    }
    6565}
    6666
     
    266266                    LOG_ERROR_AND_RETURN("Invalid cookie attribute %s (domain): it does not contain an embedded dot", cookie.ascii().data());
    267267
    268                 // If the domain does not start with a dot, add one for security checks,
     268                // If the domain does not start with a dot, add one for security checks and to distinguish it from host-only domains
    269269                // For example: ab.c.com dose not domain match b.c.com;
    270                 String realDomain = parsedValue[0] == '.' ? parsedValue : "." + parsedValue;
     270                StringBuilder parsedValueBuilder;
     271                if (parsedValue[0] != '.')
     272                    parsedValueBuilder.appendLiteral(".");
     273                parsedValueBuilder.append(parsedValue);
     274                String realDomain = parsedValueBuilder.toString();
     275
     276                StringBuilder defaultHostBuilder;
     277                defaultHostBuilder.appendLiteral(".");
     278                defaultHostBuilder.append(m_defaultCookieHost);
     279                String defaultHost = defaultHostBuilder.toString();
    271280
    272281                // Try to return an canonical ip address if the domain is an ip
     
    279288                if (m_defaultDomainIsIPAddress) {
    280289                    String realDomainCanonical = BlackBerry::Platform::getCanonicalIPFormat(realDomain);
    281                     if (realDomainCanonical.isEmpty() || realDomainCanonical != m_defaultCookieHost)
     290                    if (realDomainCanonical.isEmpty() || realDomainCanonical != defaultHost)
    282291                        LOG_ERROR_AND_RETURN("Invalid cookie attribute %s (domain): domain is IP but does not match host's IP", cookie.ascii().data());
    283292                    realDomain = realDomainCanonical;
     
    289298                    // a.b.com matches b.com, a.b.com matches .B.com and a.b.com matches .A.b.Com
    290299                    // and so on.
    291                     // We also have to make a special case for IP addresses. If a website tries to set
    292                     // a cookie to 61.97, that domain is not an IP address and will end with the m_defaultCookieHost
    293                     if (!m_defaultCookieHost.endsWith(realDomain, false))
     300                    if (!defaultHost.endsWith(realDomain, false))
    294301                        LOG_ERROR_AND_RETURN("Invalid cookie attribute %s (domain): it does not domain match the host", cookie.ascii().data());
     302
    295303                    // We should check for an embedded dot in the portion of string in the host not in the domain
    296304                    // but to match firefox behaviour we do not.
  • trunk/Source/WebCore/platform/blackberry/ParsedCookie.h

    r145163 r150916  
    8686    bool isSession() const { return m_isSession; }
    8787
     88    bool isHostOnly() const { return !m_domain.startsWith("."); }
     89
    8890    bool hasExpired() const;
    8991    bool isForceExpired() const { return m_isForceExpired; }
Note: See TracChangeset for help on using the changeset viewer.