diff options
author | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2011-06-07 18:14:13 (GMT) |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2011-06-09 14:05:14 (GMT) |
commit | 7b287a3861b2b71a31dfea53b5c93a0cb7d99fcc (patch) | |
tree | 758bf330f8974cdc3a3f31e2c424c57f44e43147 /src | |
parent | ab00a395bb00ccd130a01d49bf18c2bc597a1fe6 (diff) | |
download | Qt-7b287a3861b2b71a31dfea53b5c93a0cb7d99fcc.zip Qt-7b287a3861b2b71a31dfea53b5c93a0cb7d99fcc.tar.gz Qt-7b287a3861b2b71a31dfea53b5c93a0cb7d99fcc.tar.bz2 |
Limit the cookies count per domain to 50.
This makes it more difficult for a single server to fill the client's cookie
jar. All major browsers currently have a similar limit.
This patch also modifies the "find already existing cookie" loop to use indexes
instead of iterators to match the newly added loop.
Reviewed-by: Peter Hartmann
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qnetworkcookiejar.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp index 291bdec..e49a8e1 100644 --- a/src/network/access/qnetworkcookiejar.cpp +++ b/src/network/access/qnetworkcookiejar.cpp @@ -220,20 +220,33 @@ bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieLis continue; // not accepted } - QList<QNetworkCookie>::Iterator it = d->allCookies.begin(), - end = d->allCookies.end(); - for ( ; it != end; ++it) + for (int i = 0; i < d->allCookies.size(); ++i) { // does this cookie already exist? - if (cookie.name() == it->name() && - cookie.domain() == it->domain() && - cookie.path() == it->path()) { + const QNetworkCookie ¤t = d->allCookies.at(i); + if (cookie.name() == current.name() && + cookie.domain() == current.domain() && + cookie.path() == current.path()) { // found a match - d->allCookies.erase(it); + d->allCookies.removeAt(i); break; } + } // did not find a match if (!isDeletion) { + int countForDomain = 0; + for (int i = d->allCookies.size() - 1; i >= 0; --i) { + // Start from the end and delete the oldest cookies to keep a maximum count of 50. + const QNetworkCookie ¤t = d->allCookies.at(i); + if (isParentDomain(cookie.domain(), current.domain()) + || isParentDomain(current.domain(), cookie.domain())) { + if (countForDomain >= 49) + d->allCookies.removeAt(i); + else + ++countForDomain; + } + } + d->allCookies += cookie; ++added; } |