@@ -72,6 +72,7 @@ void checkFiles();
7272void checkRegistry ();
7373void error (std::string message);
7474std::string generate_random_number ();
75+ std::string curl_escape (CURL* curl, const std::string& input);
7576std::string seed;
7677void cleanUpSeedData (const std::string& seed);
7778std::string signature;
@@ -100,7 +101,7 @@ void KeyAuth::api::init()
100101 XorStr (" type=init" ) +
101102 XorStr (" &ver=" ) + version +
102103 XorStr (" &hash=" ) + hash +
103- XorStr (" &name=" ) + curl_easy_escape (curl, name. c_str (), 0 ) +
104+ XorStr (" &name=" ) + curl_escape (curl, name) +
104105 XorStr (" &ownerid=" ) + ownerid;
105106
106107 // to ensure people removed secret from main.cpp (some people will forget to)
@@ -1421,8 +1422,8 @@ std::string KeyAuth::api::webhook(std::string id, std::string params, std::strin
14211422 auto data =
14221423 XorStr (" type=webhook" ) +
14231424 XorStr (" &webid=" ) + id +
1424- XorStr (" ¶ms=" ) + curl_easy_escape (curl, params. c_str (), 0 ) +
1425- XorStr (" &body=" ) + curl_easy_escape (curl, body. c_str (), 0 ) +
1425+ XorStr (" ¶ms=" ) + curl_escape (curl, params) +
1426+ XorStr (" &body=" ) + curl_escape (curl, body) +
14261427 XorStr (" &conttype=" ) + contenttype +
14271428 XorStr (" &sessionid=" ) + sessionid +
14281429 XorStr (" &name=" ) + name +
@@ -1601,7 +1602,15 @@ void KeyAuth::api::logout() {
16011602
16021603int VerifyPayload (std::string signature, std::string timestamp, std::string body)
16031604{
1604- long long unix_timestamp = std::stoll (timestamp);
1605+ long long unix_timestamp = 0 ;
1606+ try {
1607+ unix_timestamp = std::stoll (timestamp);
1608+ }
1609+ catch (...) {
1610+ std::cerr << " [ERROR] Invalid timestamp format\n " ;
1611+ MessageBoxA (0 , " Signature verification failed (invalid timestamp)" , " KeyAuth" , MB_ICONERROR);
1612+ exit (2 );
1613+ }
16051614
16061615 auto current_time = std::chrono::system_clock::now ();
16071616 long long current_unix_time = std::chrono::duration_cast<std::chrono::seconds>(
@@ -1678,14 +1687,30 @@ std::string get_str_between_two_str(const std::string& s,
16781687 const std::string& start_delim,
16791688 const std::string& stop_delim)
16801689{
1681- unsigned first_delim_pos = s.find (start_delim);
1682- unsigned end_pos_of_first_delim = first_delim_pos + start_delim.length ();
1683- unsigned last_delim_pos = s.find (stop_delim);
1690+ const auto first_delim_pos = s.find (start_delim);
1691+ if (first_delim_pos == std::string::npos)
1692+ return {};
1693+ const auto end_pos_of_first_delim = first_delim_pos + start_delim.length ();
1694+ const auto last_delim_pos = s.find (stop_delim, end_pos_of_first_delim);
1695+ if (last_delim_pos == std::string::npos || last_delim_pos < end_pos_of_first_delim)
1696+ return {};
16841697
16851698 return s.substr (end_pos_of_first_delim,
16861699 last_delim_pos - end_pos_of_first_delim);
16871700}
16881701
1702+ std::string curl_escape (CURL* curl, const std::string& input)
1703+ {
1704+ if (!curl)
1705+ return input;
1706+ char * escaped = curl_easy_escape (curl, input.c_str (), 0 );
1707+ if (!escaped)
1708+ return {};
1709+ std::string out (escaped);
1710+ curl_free (escaped);
1711+ return out;
1712+ }
1713+
16891714void KeyAuth::api::setDebug (bool value) {
16901715 KeyAuth::api::debug = value;
16911716}
0 commit comments