Skip to content

Commit

Permalink
Merge pull request #1462 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
tylerkaraszewski authored Mar 11, 2023
2 parents f8fbe77 + 60557e3 commit 7464f0a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
23 changes: 14 additions & 9 deletions libstuff/libstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2618,14 +2618,8 @@ int SQuery(sqlite3* db, const char* e, const string& sql, SQResult& result, int6
string sqlToLog = sql;

if ((int64_t)elapsed > warnThreshold || (int64_t)elapsed > 10000) {
// We should always avoid logging authTokens because they give access to accounts
pcrecpp::RE("\"authToken\":\"[0-9A-F]{400,1024}\"").GlobalReplace("\"authToken\":<REDACTED>", &sqlToLog);
SRedactSensitiveValues(sqlToLog);

// Let's redact queries that contain encrypted fields since there's no value in logging them
pcrecpp::RE("v[0-9]+:[0-9A-F]{10,}").GlobalReplace("<REDACTED>", &sqlToLog);

// We remove anything inside "html" because we intentionally don't log chats
pcrecpp::RE("\"html\":\".*\"").GlobalReplace("\"html\":\"<REDACTED>\"", &sqlToLog);
if ((int64_t)elapsed > warnThreshold) {
if (isSyncThread) {
SWARN("Slow query sync ("
Expand Down Expand Up @@ -2657,8 +2651,7 @@ int SQuery(sqlite3* db, const char* e, const string& sql, SQResult& result, int6
// Only OK and commit conflicts are allowed without warning because they're the only "successful" results that we expect here.
// OK means it succeeds, conflicts will get retried further up the call stack.
if (error != SQLITE_OK && extErr != SQLITE_BUSY_SNAPSHOT && !skipWarn) {
// We remove anything inside "html" because we intentionally don't log chats
pcrecpp::RE("\"html\":\".*\"").GlobalReplace("\"html\":\"<REDACTED>\"", &sqlToLog);
SRedactSensitiveValues(sqlToLog);

SWARN("'" << e << "', query failed with error #" << error << " (" << sqlite3_errmsg(db) << "): " << sqlToLog);
}
Expand Down Expand Up @@ -2760,6 +2753,18 @@ bool SREMatch(const string& regExp, const string& s, string& match) {
return pcrecpp::RE(regExp).FullMatch(s, &match);
}

void SRedactSensitiveValues(string& s) {
// The message may be truncated midway through the authToken, so there may not be a closing quote (") at the end of
// the authToken, so we need to optionally match the closing quote with a question mark (?).
pcrecpp::RE("\"authToken\":\".*\"?").GlobalReplace("\"authToken\":<REDACTED>", &s);

// Redact queries that contain encrypted fields since there's no value in logging them.
pcrecpp::RE("v[0-9]+:[0-9A-F]{10,}").GlobalReplace("<REDACTED>", &s);

// Remove anything inside "html" because we intentionally don't log chats.
pcrecpp::RE("\"html\":\".*\"").GlobalReplace("\"html\":\"<REDACTED>\"", &s);
}

SStopwatch::SStopwatch() {
start();
alarmDuration.store(0);
Expand Down
3 changes: 3 additions & 0 deletions libstuff/libstuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ bool SConstantTimeIEquals(const string& secret, const string& userInput);
bool SREMatch(const string& regExp, const string& s);
bool SREMatch(const string& regExp, const string& s, string& match);

// Redact values that should not be logged.
void SRedactSensitiveValues(string& s);

// Case testing and conversion
string SToLower(string value);
string SToUpper(string value);
Expand Down
3 changes: 2 additions & 1 deletion sqlitecluster/SQLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ int SQLite::_walHookCallback(void* sqliteObject, sqlite3* db, const char* name,

void SQLite::_sqliteLogCallback(void* pArg, int iErrCode, const char* zMsg) {
_mostRecentSQLiteErrorLog = "{SQLITE} Code: "s + to_string(iErrCode) + ", Message: "s + zMsg;
SSYSLOG(LOG_INFO, "[info] " << _mostRecentSQLiteErrorLog);
SRedactSensitiveValues(_mostRecentSQLiteErrorLog);
SINFO(_mostRecentSQLiteErrorLog);
}

int SQLite::_sqliteTraceCallback(unsigned int traceCode, void* c, void* p, void* x) {
Expand Down

0 comments on commit 7464f0a

Please sign in to comment.