@@ -1466,8 +1466,61 @@ std::string getPath() {
14661466 }
14671467}
14681468
1469+ void RedactField (nlohmann::json& jsonObject, const std::string& fieldName)
1470+ {
1471+
1472+ if (jsonObject.contains (fieldName)) {
1473+ jsonObject[fieldName] = " REDACTED" ;
1474+ }
1475+ }
1476+
14691477void debugInfo (std::string data, std::string url, std::string response) {
14701478
1479+ // turn response into json
1480+ nlohmann::json responses = nlohmann::json::parse (response);
1481+ RedactField (responses, " sessionid" );
1482+ RedactField (responses, " ownerid" );
1483+ RedactField (responses, " app" );
1484+ RedactField (responses, " name" );
1485+ RedactField (responses, " contents" );
1486+ RedactField (responses, " key" );
1487+ RedactField (responses, " username" );
1488+ RedactField (responses, " password" );
1489+ RedactField (responses, " secret" );
1490+ RedactField (responses, " version" );
1491+ RedactField (responses, " fileid" );
1492+ RedactField (responses, " webhooks" );
1493+ std::string redacted_response = responses.dump ();
1494+
1495+ // turn data into json
1496+ std::replace (data.begin (), data.end (), ' &' , ' ' );
1497+
1498+ nlohmann::json datas;
1499+
1500+ std::istringstream iss (data);
1501+ std::vector<std::string> results ((std::istream_iterator<std::string>(iss)),
1502+ std::istream_iterator<std::string>());
1503+
1504+ for (auto const & value : results) {
1505+ datas[value.substr (0 , value.find (' =' ))] = value.substr (value.find (' =' ) + 1 );
1506+ }
1507+
1508+ RedactField (datas, " sessionid" );
1509+ RedactField (datas, " ownerid" );
1510+ RedactField (datas, " app" );
1511+ RedactField (datas, " name" );
1512+ RedactField (datas, " key" );
1513+ RedactField (datas, " username" );
1514+ RedactField (datas, " password" );
1515+ RedactField (datas, " contents" );
1516+ RedactField (datas, " secret" );
1517+ RedactField (datas, " version" );
1518+ RedactField (datas, " fileid" );
1519+ RedactField (datas, " webhooks" );
1520+
1521+ std::string redacted_data = datas.dump ();
1522+
1523+
14711524 // gets the path
14721525 std::string path = getPath ();
14731526
@@ -1485,7 +1538,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
14851538 // /////////////////////
14861539
14871540 // creates variables for the paths needed :smile:
1488- std::string KeyAuthPath = path + " \\ KeyAuth" ;
1541+ std::string KeyAuthPath = path + " \\ KeyAuth" ;
14891542 std::string logPath = KeyAuthPath + " \\ Debug\\ " + filenameOnly.substr (0 , filenameOnly.size () - 4 );
14901543
14911544 // basically loops until we have all the paths
@@ -1530,7 +1583,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
15301583
15311584 std::string currentTimeString = std::to_string (hours) + " :" + formattedMinutes + " " + period;
15321585
1533- std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + data + " \n Response : " + response + " Sent to: " + url;
1586+ std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + redacted_data + " \n Response : " + redacted_response + " Sent to: " + url;
15341587
15351588 logfile << contents;
15361589
0 commit comments