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 May 25, 2024
1 parent 1f549cf commit cd1c9cf
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/discord/LocalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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 All @@ -120,6 +123,7 @@ bool LocalSettings::Save()
j["CheckUpdates"] = m_bCheckUpdates;
j["EnableTLSVerification"] = m_bEnableTLSVerification;
j["RemindUpdateCheckOn"] = (long long)(m_remindUpdatesOn);
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 @@ -91,6 +91,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();

private:
Expand All @@ -106,6 +112,7 @@ class LocalSettings
bool m_bCheckUpdates = false;
bool m_bAskToCheckUpdates = true;
bool m_bEnableTLSVerification = true;
bool m_bAddExtraHeaders = true;
time_t m_remindUpdatesOn = 0;
int m_width = 1000;
int m_height = 700;
Expand Down
4 changes: 3 additions & 1 deletion src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@
#define IDC_CHECK1 871
#define IDC_ENABLE_TLS_CHECKS 871
#define IDC_CHECK_UPDATES 872
#define IDC_CHECK2 873
#define IDC_TOGGLE_XSUPERPROPS 873
#define ID_FILE_PREFERENCES 1001
#define ID_FILE_STOPALLSPEECH 1002
#define ID_FILE_EXIT 1003
Expand Down Expand Up @@ -368,7 +370,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 83
#define _APS_NEXT_COMMAND_VALUE 1069
#define _APS_NEXT_CONTROL_VALUE 873
#define _APS_NEXT_CONTROL_VALUE 874
#define _APS_NEXT_SYMED_VALUE 40000
#endif
#endif
8 changes: 5 additions & 3 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,9 @@ BEGIN
PUSHBUTTON "Revert to official Discord backend",IDC_REVERTTODEFAULT,11,116,118,14
PUSHBUTTON "Update",IDC_UPDATE,197,116,50,14
ICON IDI_WARNING_IC,IDC_ICON_WARN_CONNECT,11,55,20,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,30,54,214,31
ICON IDI_WARNING_IC,IDC_ICON_WARN_WEBSOCKETSTUFF,12,87,20,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,30,87,214,29
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,30,54,214,28
ICON IDI_WARNING_IC,IDC_ICON_WARN_WEBSOCKETSTUFF,12,82,21,20,SS_REALSIZEIMAGE
LTEXT "NOTE: Discord Messenger automatically fetches the websocket gateway URL using the API_URL/gateway endpoint.",IDC_STATIC,30,82,214,19
GROUPBOX "Security Settings",IDC_STATIC,6,139,245,48
ICON IDI_WARNING_IC,IDC_ICON_WARN_WEBSOCKETSTUFF2,12,166,20,20,SS_REALSIZEIMAGE
LTEXT "WARNING: Disabling TLS certificate verification could expose you to MITM (man-in-the-middle) attacks via certificate spoofing!",IDC_STATIC,30,165,214,19
Expand All @@ -575,6 +575,8 @@ BEGIN
CONTROL "Check for updates using the GitHub API",IDC_CHECK_UPDATES,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,204,232,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


Expand Down
21 changes: 15 additions & 6 deletions src/windows/NetworkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -169,12 +174,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 @@ -174,8 +174,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 @@ -331,6 +332,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 cd1c9cf

Please sign in to comment.