Skip to content

Commit

Permalink
* Add option to toggle these off/on.
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Jun 13, 2024
1 parent db47346 commit 49f03d4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/discord/LocalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ bool LocalSettings::Load()

if (j.contains("RemindUpdateCheckOn"))
m_remindUpdatesOn = (time_t) (long long) j["RemindUpdateCheckOn"];

if (j.contains("AddExtraHeaders"))
m_bAddExtraHeaders = j["AddExtraHeaders"];

return true;
}
Expand Down Expand Up @@ -144,7 +147,8 @@ bool LocalSettings::Save()
j["ImageBackgroundFileName"] = m_imageBackgroundFileName;
j["WatermarkAlignment"] = int(m_imageAlignment);
j["UserScale"] = m_userScale;

j["AddExtraHeaders"] = m_bAddExtraHeaders;

if (m_bSaveWindowSize) {
j["WindowWidth"] = m_width;
j["WindowHeight"] = m_height;
Expand Down
7 changes: 7 additions & 0 deletions src/discord/LocalSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class LocalSettings
void SetEnableTLSVerification(bool b) {
m_bEnableTLSVerification = b;
}
bool AddExtraHeaders() const {
return m_bAddExtraHeaders;
}
void SetAddExtraHeaders(bool b) {
m_bAddExtraHeaders = b;
}
void StopUpdateCheckTemporarily();
bool DisableFormatting() const {
return m_bDisableFormatting;
Expand Down Expand Up @@ -158,6 +164,7 @@ class LocalSettings
bool m_bDisableFormatting = false;
bool m_bShowScrollBarOnGuildList = false;
bool m_bCompactMemberList = false;
bool m_bAddExtraHeaders = true;
time_t m_remindUpdatesOn = 0;
int m_width = 1000;
int m_height = 700;
Expand Down
4 changes: 2 additions & 2 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@
#define IDC_UPLOADING_ETA 878
#define IDC_UPLOADING_XFERRATE 879
#define IDC_UPLOADING_ACTION 880
#define IDC_ANIMATE1 881
#define IDC_PROGRESS_ANIMATE 881
#define IDC_MESSAGE_STYLE 882
#define IDC_ACTIVE_IMAGE_BROWSE 884
Expand All @@ -391,6 +390,7 @@
#define IDC_COMBO_ALIGNMENT 889
#define IDC_COMBO_GUI_SCALE 890
#define IDC_NOTIFICATION_HINT 891
#define IDC_TOGGLE_XSUPERPROPS 892
#define ID_FILE_PREFERENCES 1001
#define ID_FILE_STOPALLSPEECH 1002
#define ID_FILE_EXIT 1003
Expand Down Expand Up @@ -469,7 +469,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 1069
#define _APS_NEXT_CONTROL_VALUE 892
#define _APS_NEXT_CONTROL_VALUE 893
#define _APS_NEXT_SYMED_VALUE 40000
#endif
#endif
4 changes: 3 additions & 1 deletion src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ BEGIN
ICON IDI_WARNING_IC,IDC_ICON_WARN_CONNECT,12,55,21,20,SS_REALSIZEIMAGE
LTEXT "For security reasons, when you update the URLs that Discord Messenger uses to interface with Discord's backend, you will be logged out. (your token is forgotten but not revoked)",IDC_STATIC,33,54,215,31
ICON IDI_WARNING_IC,IDC_ICON_WARN_WEBSOCKETSTUFF,12,87,21,20,SS_REALSIZEIMAGE
LTEXT "Wondering where the websocket gateway URL is located? Well, Discord Messenger issues a request to API_URL/gateway, which tells it the websocket URL to use.",IDC_STATIC,33,87,215,29
LTEXT "NOTE: Discord Messenger automatically fetches the websocket gateway URL using the API_URL/gateway endpoint.",IDC_STATIC,33,82,214,19
GROUPBOX "Security Settings",IDC_STATIC,6,139,248,48
ICON IDI_WARNING_IC,IDC_ICON_WARN_WEBSOCKETSTUFF2,12,166,21,20,SS_REALSIZEIMAGE
LTEXT "WARNING: Disabling TLS certificate verification could expose you to MITM (man-in-the-middle) attacks via certificate spoofing!",IDC_STATIC,33,165,215,19
Expand All @@ -608,6 +608,8 @@ BEGIN
CONTROL "Check for updates using the GitHub API",IDC_CHECK_UPDATES,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,204,236,10
LTEXT "iProgramInCpp cannot see your IP address via the update service.",IDC_STATIC,12,219,231,10
CONTROL "Add extra headers such as X-Super-Properties to HTTP requests.",IDC_TOGGLE_XSUPERPROPS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,104,231,10
END

IDD_DIALOG_UPLOADING DIALOGEX 0, 0, 275, 135
Expand Down
21 changes: 15 additions & 6 deletions src/windows/NetworkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static bool g_bQuittingFromSSLError;

int g_latestSSLError = 0; // HACK - used by httplib.h, to debug some weird issue

bool AddExtraHeaders()
{
return GetLocalSettings()->AddExtraHeaders();
}

int NetRequest::Priority() const
{
int prio = 0;
Expand Down Expand Up @@ -205,12 +210,16 @@ void NetworkerThread::FulfillRequest(NetRequest& req)

Headers headers;
headers.insert(std::make_pair("User-Agent", GetClientConfig()->GetUserAgent()));
headers.insert(std::make_pair("X-Super-Properties", GetClientConfig()->GetSerializedBase64Blob()));
headers.insert(std::make_pair("X-Discord-Timezone", GetClientConfig()->GetTimezone()));
headers.insert(std::make_pair("X-Discord-Locale", GetClientConfig()->GetLocale()));
headers.insert(std::make_pair("Sec-Ch-Ua", GetClientConfig()->GetSecChUa()));
headers.insert(std::make_pair("Sec-Ch-Ua-Mobile", "?0"));
headers.insert(std::make_pair("Sec-Ch-Ua-Platform", GetClientConfig()->GetOS()));

if (AddExtraHeaders())
{
headers.insert(std::make_pair("X-Super-Properties", GetClientConfig()->GetSerializedBase64Blob()));
headers.insert(std::make_pair("X-Discord-Timezone", GetClientConfig()->GetTimezone()));
headers.insert(std::make_pair("X-Discord-Locale", GetClientConfig()->GetLocale()));
headers.insert(std::make_pair("Sec-Ch-Ua", GetClientConfig()->GetSecChUa()));
headers.insert(std::make_pair("Sec-Ch-Ua-Mobile", "?0"));
headers.insert(std::make_pair("Sec-Ch-Ua-Platform", GetClientConfig()->GetOS()));
}

if (req.authorization.size())
{
Expand Down
11 changes: 9 additions & 2 deletions src/windows/OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ void WINAPI OnChildDialogInit(HWND hwndDlg)
SetDlgItemText(hwndDlg, IDC_EDIT_DISCORDAPI, tstrAPI);
SetDlgItemText(hwndDlg, IDC_EDIT_DISCORDCDN, tstrCDN);

CheckDlgButton(hwndDlg, IDC_ENABLE_TLS_CHECKS, GetLocalSettings()->EnableTLSVerification() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHECK_UPDATES, GetLocalSettings()->CheckUpdates() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ENABLE_TLS_CHECKS, GetLocalSettings()->EnableTLSVerification() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHECK_UPDATES, GetLocalSettings()->CheckUpdates() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_TOGGLE_XSUPERPROPS, GetLocalSettings()->AddExtraHeaders() ? BST_CHECKED : BST_UNCHECKED);

free(tstrAPI);
free(tstrCDN);
Expand Down Expand Up @@ -457,6 +458,12 @@ INT_PTR CALLBACK ChildDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
break;
}

case IDC_TOGGLE_XSUPERPROPS:
{
GetLocalSettings()->SetAddExtraHeaders(IsDlgButtonChecked(hWnd, IDC_TOGGLE_XSUPERPROPS));
break;
}

case IDC_REVERTTODEFAULT:
case IDC_UPDATE:
{
Expand Down

0 comments on commit 49f03d4

Please sign in to comment.