2020-04-06 15:24:15 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "CookieLogging.h"
|
2020-04-06 15:27:05 +03:00
|
|
|
#include "Cookie.h"
|
2020-04-06 15:24:15 +03:00
|
|
|
|
2020-04-06 15:32:45 +03:00
|
|
|
constexpr auto TIME_STRING_LENGTH = 40;
|
|
|
|
|
2020-04-06 15:24:15 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
LazyLogModule gCookieLog("cookie");
|
|
|
|
|
|
|
|
static const char* SameSiteToString(uint32_t aSameSite) {
|
|
|
|
switch (aSameSite) {
|
|
|
|
case nsICookie::SAMESITE_NONE:
|
|
|
|
return "none";
|
|
|
|
case nsICookie::SAMESITE_LAX:
|
|
|
|
return "lax";
|
|
|
|
case nsICookie::SAMESITE_STRICT:
|
|
|
|
return "strict";
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Invalid nsICookie sameSite value");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CookieLogging::LogSuccess(bool aSetCookie, nsIURI* aHostURI,
|
|
|
|
const nsACString& aCookieString, Cookie* aCookie,
|
|
|
|
bool aReplacing) {
|
|
|
|
// if logging isn't enabled, return now to save cycles
|
|
|
|
if (!MOZ_LOG_TEST(gCookieLog, LogLevel::Debug)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
2020-04-06 15:32:45 +03:00
|
|
|
if (aHostURI) {
|
|
|
|
aHostURI->GetAsciiSpec(spec);
|
|
|
|
}
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("===== %s =====\n", aSetCookie ? "COOKIE ACCEPTED" : "COOKIE SENT"));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("request URL: %s\n", spec.get()));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("cookie string: %s\n", aCookieString.BeginReading()));
|
2020-04-06 15:32:45 +03:00
|
|
|
if (aSetCookie) {
|
2020-04-06 15:24:15 +03:00
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("replaces existing cookie: %s\n", aReplacing ? "true" : "false"));
|
2020-04-06 15:32:45 +03:00
|
|
|
}
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
LogCookie(aCookie);
|
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CookieLogging::LogFailure(bool aSetCookie, nsIURI* aHostURI,
|
|
|
|
const nsACString& aCookieString,
|
|
|
|
const char* aReason) {
|
|
|
|
// if logging isn't enabled, return now to save cycles
|
2020-04-06 15:32:45 +03:00
|
|
|
if (!MOZ_LOG_TEST(gCookieLog, LogLevel::Warning)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
nsAutoCString spec;
|
2020-04-06 15:32:45 +03:00
|
|
|
if (aHostURI) {
|
|
|
|
aHostURI->GetAsciiSpec(spec);
|
|
|
|
}
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Warning,
|
|
|
|
("===== %s =====\n",
|
|
|
|
aSetCookie ? "COOKIE NOT ACCEPTED" : "COOKIE NOT SENT"));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Warning, ("request URL: %s\n", spec.get()));
|
2020-04-06 15:32:45 +03:00
|
|
|
if (aSetCookie) {
|
2020-04-06 15:24:15 +03:00
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Warning,
|
|
|
|
("cookie string: %s\n", aCookieString.BeginReading()));
|
2020-04-06 15:32:45 +03:00
|
|
|
}
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
PRExplodedTime explodedTime;
|
|
|
|
PR_ExplodeTime(PR_Now(), PR_GMTParameters, &explodedTime);
|
2020-04-06 15:32:45 +03:00
|
|
|
char timeString[TIME_STRING_LENGTH];
|
|
|
|
PR_FormatTimeUSEnglish(timeString, TIME_STRING_LENGTH, "%c GMT",
|
|
|
|
&explodedTime);
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Warning, ("current time: %s", timeString));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Warning, ("rejected because %s\n", aReason));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Warning, ("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CookieLogging::LogCookie(Cookie* aCookie) {
|
|
|
|
PRExplodedTime explodedTime;
|
|
|
|
PR_ExplodeTime(PR_Now(), PR_GMTParameters, &explodedTime);
|
2020-04-06 15:32:45 +03:00
|
|
|
char timeString[TIME_STRING_LENGTH];
|
|
|
|
PR_FormatTimeUSEnglish(timeString, TIME_STRING_LENGTH, "%c GMT",
|
|
|
|
&explodedTime);
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("current time: %s", timeString));
|
|
|
|
|
|
|
|
if (aCookie) {
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("----------------\n"));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("name: %s\n", aCookie->Name().get()));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("value: %s\n", aCookie->Value().get()));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("%s: %s\n", aCookie->IsDomain() ? "domain" : "host",
|
|
|
|
aCookie->Host().get()));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("path: %s\n", aCookie->Path().get()));
|
|
|
|
|
|
|
|
PR_ExplodeTime(aCookie->Expiry() * int64_t(PR_USEC_PER_SEC),
|
|
|
|
PR_GMTParameters, &explodedTime);
|
2020-04-06 15:32:45 +03:00
|
|
|
PR_FormatTimeUSEnglish(timeString, TIME_STRING_LENGTH, "%c GMT",
|
|
|
|
&explodedTime);
|
2020-04-06 15:24:15 +03:00
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("expires: %s%s", timeString,
|
|
|
|
aCookie->IsSession() ? " (at end of session)" : ""));
|
|
|
|
|
|
|
|
PR_ExplodeTime(aCookie->CreationTime(), PR_GMTParameters, &explodedTime);
|
2020-04-06 15:32:45 +03:00
|
|
|
PR_FormatTimeUSEnglish(timeString, TIME_STRING_LENGTH, "%c GMT",
|
|
|
|
&explodedTime);
|
2020-04-06 15:24:15 +03:00
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("created: %s", timeString));
|
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("is secure: %s\n", aCookie->IsSecure() ? "true" : "false"));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("is httpOnly: %s\n", aCookie->IsHttpOnly() ? "true" : "false"));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("sameSite: %s - rawSameSite: %s\n",
|
|
|
|
SameSiteToString(aCookie->SameSite()),
|
|
|
|
SameSiteToString(aCookie->RawSameSite())));
|
2020-06-02 16:48:28 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
gCookieLog, LogLevel::Debug,
|
|
|
|
("schemeMap %d (http: %s | https: %s | file: %s)\n",
|
|
|
|
aCookie->SchemeMap(),
|
|
|
|
(aCookie->SchemeMap() & nsICookie::SCHEME_HTTP ? "true" : "false"),
|
|
|
|
(aCookie->SchemeMap() & nsICookie::SCHEME_HTTPS ? "true" : "false"),
|
|
|
|
(aCookie->SchemeMap() & nsICookie::SCHEME_FILE ? "true" : "false")));
|
2020-04-06 15:24:15 +03:00
|
|
|
|
|
|
|
nsAutoCString suffix;
|
|
|
|
aCookie->OriginAttributesRef().CreateSuffix(suffix);
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug,
|
|
|
|
("origin attributes: %s\n",
|
|
|
|
suffix.IsEmpty() ? "{empty}" : suffix.get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CookieLogging::LogEvicted(Cookie* aCookie, const char* details) {
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("===== COOKIE EVICTED =====\n"));
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("%s\n", details));
|
|
|
|
|
|
|
|
LogCookie(aCookie);
|
|
|
|
|
|
|
|
MOZ_LOG(gCookieLog, LogLevel::Debug, ("\n"));
|
|
|
|
}
|
|
|
|
|
2020-06-02 16:50:32 +03:00
|
|
|
// static
|
|
|
|
void CookieLogging::LogMessageToConsole(nsIConsoleReportCollector* aCRC,
|
|
|
|
nsIURI* aURI, uint32_t aErrorFlags,
|
|
|
|
const nsACString& aCategory,
|
|
|
|
const nsACString& aMsg,
|
|
|
|
const nsTArray<nsString>& aParams) {
|
|
|
|
MOZ_ASSERT(aURI);
|
|
|
|
|
|
|
|
if (!aCRC) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString uri;
|
|
|
|
nsresult rv = aURI->GetSpec(uri);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCRC->AddConsoleReport(aErrorFlags, aCategory,
|
|
|
|
nsContentUtils::eNECKO_PROPERTIES, uri, 0, 0, aMsg,
|
|
|
|
aParams);
|
|
|
|
}
|
|
|
|
|
2020-04-06 15:24:15 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|