Bug 1562233 - Add logging of CONNECT requests with headers, add possibility to disable authorization headers sanitization by a preference (default is sanitization enabled), r=valentin

Differential Revision: https://phabricator.services.mozilla.com/D36336

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Honza Bambas 2019-06-28 17:50:43 +00:00
parent 86f47aee6f
commit b5a80ffb5e
4 changed files with 35 additions and 19 deletions

View File

@ -12,6 +12,8 @@
#include "PLDHashTable.h"
#include "mozilla/Mutex.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/Preferences.h"
#include "mozilla/Unused.h"
#include "nsCRT.h"
#include "nsHttpRequestHead.h"
#include "nsHttpResponseHead.h"
@ -805,5 +807,27 @@ void LogCallingScriptLocation(void* instance) {
col));
}
void LogHeaders(const char* lineStart) {
static bool sanitize = true;
static nsresult once = Preferences::AddBoolVarCache(
&sanitize, "network.http.sanitize-headers-in-logs", true);
Unused << once;
nsAutoCString buf;
char* endOfLine;
while ((endOfLine = PL_strstr(lineStart, "\r\n"))) {
buf.Assign(lineStart, endOfLine - lineStart);
if (sanitize && (PL_strcasestr(buf.get(), "authorization: ") ||
PL_strcasestr(buf.get(), "proxy-authorization: "))) {
char* p = PL_strchr(buf.get(), ' ');
while (p && *++p) {
*p = '*';
}
}
LOG1((" %s\n", buf.get()));
lineStart = endOfLine + 2;
}
}
} // namespace net
} // namespace mozilla

View File

@ -330,6 +330,8 @@ class ParsedHeaderValueListList {
nsCString mFull;
};
void LogHeaders(const char* lineStart);
} // namespace net
} // namespace mozilla

View File

@ -2178,6 +2178,7 @@ void nsHttpConnection::SetInSpdyTunnel(bool arg) {
mProxyConnectInProgress = false;
}
// static
nsresult nsHttpConnection::MakeConnectString(nsAHttpTransaction* trans,
nsHttpRequestHead* request,
nsACString& result, bool h2ws) {
@ -2242,6 +2243,14 @@ nsresult nsHttpConnection::MakeConnectString(nsAHttpTransaction* trans,
result.Truncate();
request->Flatten(result, false);
if (LOG1_ENABLED()) {
LOG(("nsHttpConnection::MakeConnectString for transaction=%p [",
trans->QueryHttpTransaction()));
LogHeaders(result.BeginReading());
LOG(("]"));
}
result.AppendLiteral("\r\n");
return NS_OK;
}

View File

@ -62,25 +62,6 @@ using namespace mozilla::net;
namespace mozilla {
namespace net {
//-----------------------------------------------------------------------------
// helpers
//-----------------------------------------------------------------------------
static void LogHeaders(const char* lineStart) {
nsAutoCString buf;
char* endOfLine;
while ((endOfLine = PL_strstr(lineStart, "\r\n"))) {
buf.Assign(lineStart, endOfLine - lineStart);
if (PL_strcasestr(buf.get(), "authorization: ") ||
PL_strcasestr(buf.get(), "proxy-authorization: ")) {
char* p = PL_strchr(PL_strchr(buf.get(), ' ') + 1, ' ');
while (p && *++p) *p = '*';
}
LOG1((" %s\n", buf.get()));
lineStart = endOfLine + 2;
}
}
//-----------------------------------------------------------------------------
// nsHttpTransaction <public>
//-----------------------------------------------------------------------------