Skip to content

Commit

Permalink
Hide bot token in exception messages
Browse files Browse the repository at this point in the history
for security reasons
  • Loading branch information
baderouaich committed Feb 24, 2024
1 parent f89ddea commit 068e8fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/tgbotxx/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace tgbotxx {
cpr::Timeout m_uploadFilesTimeout = DEFAULT_UPLOAD_FILES_TIMEOUT; /// Api files upload timeout
cpr::Timeout m_downloadFilesTimeout = DEFAULT_DOWNLOAD_FILES_TIMEOUT; /// Api files download timeout

friend class Bot;
public:
/// @brief Constructs Api object.
/// @param token Bot Token from FatherBot.
Expand Down
1 change: 1 addition & 0 deletions src/Api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <chrono>
#include <tgbotxx/Api.hpp>
#include <tgbotxx/Bot.hpp>
#include <tgbotxx/Exception.hpp>
/// Objects
#include <tgbotxx/objects/Animation.hpp>
Expand Down
4 changes: 3 additions & 1 deletion src/Bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ void Bot::start() {
m_updates = m_api->getUpdates(/*offset=*/m_lastUpdateId);
} catch (const std::exception& err) {
/// Callback -> onLongPollError
this->onLongPollError(err.what());
std::string errStr = err.what();
StringUtils::replace(errStr, m_api->m_token, "***HIDDEN_BOT_TOKEN***"); // Hide bot token in the exception message for security reasons
this->onLongPollError(errStr);
continue;
} catch (...) {
/// Callback -> onLongPollError
Expand Down

0 comments on commit 068e8fb

Please sign in to comment.