Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea/
cmake-build-debug/
build/
_codeql_build_dir/
_codeql_detected_source_root
devices/
playdl.conf
30 changes: 28 additions & 2 deletions lib/playapi/util/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@

using namespace playapi;

static std::string redact_url_query(const std::string& url) {
auto pos = url.find('?');
if (pos == std::string::npos) return url;
std::string base = url.substr(0, pos + 1); // include '?'
std::string query = url.substr(pos + 1);
std::string out;
size_t i = 0;
while (i < query.size()) {
size_t amp = query.find('&', i);
std::string part = (amp == std::string::npos) ? query.substr(i) : query.substr(i, amp - i);
size_t eq = part.find('=');
if (eq == std::string::npos) {
// key without value
out += part;
} else {
// keep key and '=' then redact value
out += part.substr(0, eq + 1);
out += "[redacted]";
}
if (amp == std::string::npos) break;
out += '&';
i = amp + 1;
}
return base + out;
}

void url_encoded_entity::add_pair(const std::string& key, const std::string& val) {
pairs.push_back({key, val});
}
Expand Down Expand Up @@ -179,7 +205,7 @@ http_response http_request::perform() {
return http_response(curlerr, status, output.str());
} else {
std::stringstream errormsg;
errormsg << "Failed to perform http request to " << url << " : CURLcode " << curlerr << " Details: " << errbuf;
errormsg << "Failed to perform http request to " << redact_url_query(url) << " : CURLcode " << curlerr << " Details: " << errbuf;
curl_easy_cleanup(curl);
throw std::runtime_error(errormsg.str().data());
}
Expand Down Expand Up @@ -211,7 +237,7 @@ void http_request::perform(std::function<void(http_response)> success, std::func
success(http_response(curlerr, status, output.str()));
} else {
std::stringstream errormsg;
errormsg << "Failed to perform http request to " << req->url << " : CURLcode " << curlerr << " Details: " << errbuf;
errormsg << "Failed to perform http request to " << redact_url_query(req->url) << " : CURLcode " << curlerr << " Details: " << errbuf;
try {
throw std::runtime_error(errormsg.str().data());
} catch (...) {
Expand Down