Skip to content

Commit 399bfc7

Browse files
committed
feat(auth): warn on insecure auth URLs
Signed-off-by: so5iso4ka <so5iso4ka@icloud.com>
1 parent 4a43618 commit 399bfc7

7 files changed

Lines changed: 59 additions & 10 deletions

File tree

launcher/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,9 @@ SET(LAUNCHER_SOURCES
968968
JavaCommon.h
969969
JavaCommon.cpp
970970

971+
UrlUtils.h
972+
UrlUtils.cpp
973+
971974
# GUI - paged dialog base
972975
ui/pages/BasePage.h
973976
ui/pages/BasePageContainer.h

launcher/UrlUtils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "UrlUtils.h"
2+
3+
bool UrlUtils::isLocalhost(const QUrl& url)
4+
{
5+
return url.host() == "localhost" || url.host() == "127.0.0.1" || url.host() == "::1";
6+
}
7+
8+
bool UrlUtils::isUnsafe(const QUrl& url)
9+
{
10+
return !url.isEmpty() && url.scheme() == "http" && !isLocalhost(url);
11+
}

launcher/UrlUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <QUrl>
4+
5+
namespace UrlUtils {
6+
bool isLocalhost(const QUrl& url);
7+
bool isUnsafe(const QUrl& url);
8+
}

launcher/ui/dialogs/CustomLoginDialog.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include "CustomLoginDialog.h"
1717
#include "ui_CustomLoginDialog.h"
1818

19+
#include <QMessageBox>
1920
#include <QPushButton>
2021
#include <QUrl>
2122

2223
#include "Application.h"
24+
#include "UrlUtils.h"
2325
#include "net/Download.h"
2426

2527
namespace {
@@ -108,6 +110,8 @@ void CustomLoginDialog::onUrlResolving()
108110
return;
109111
}
110112

113+
m_resolvedUrl = m_loginUrl;
114+
111115
// modify url if header say so
112116
auto headers = m_requestTask->getRawHeaders();
113117
if (const auto it =
@@ -116,14 +120,20 @@ void CustomLoginDialog::onUrlResolving()
116120
it != headers.end()) {
117121
const QUrl location = QString::fromUtf8(it->second);
118122
if (location.isRelative()) {
119-
m_loginUrl = m_requestTask->url().resolved(location);
123+
m_resolvedUrl = m_requestTask->url().resolved(location);
120124
} else {
121-
m_loginUrl = location;
125+
m_resolvedUrl = location;
122126
}
123127
}
124128

129+
bool shouldContinue = showWarning();
130+
if (!shouldContinue) {
131+
emit onTaskFailed(tr("Aborted"));
132+
return;
133+
}
134+
125135
// Setup the login task and start it
126-
m_account = CustomAccount::createCustom(ui->userTextBox->text(), m_loginUrl.toString(QUrl::StripTrailingSlash),
136+
m_account = CustomAccount::createCustom(ui->userTextBox->text(), m_resolvedUrl.toString(QUrl::StripTrailingSlash),
127137
ui->loginUrlTextBox->text(), ui->refreshUrlTextBox->text());
128138
m_loginTask = m_account->login(ui->passTextBox->text());
129139
connect(m_loginTask.get(), &Task::failed, this, &CustomLoginDialog::onTaskFailed);
@@ -143,6 +153,22 @@ void CustomLoginDialog::setUserInputsEnabled(bool enable)
143153
ui->buttonBox->setEnabled(enable);
144154
}
145155

156+
bool CustomLoginDialog::showWarning()
157+
{
158+
QString text = tr("You entered:\n%1\n"
159+
"Your login credentials will be sent to:\n%2\n"
160+
"Do you want to continue?")
161+
.arg(m_loginUrl.toString(), m_resolvedUrl.toString());
162+
163+
if (UrlUtils::isUnsafe(m_loginUrl) || UrlUtils::isUnsafe(m_resolvedUrl)) {
164+
text.prepend(tr("Please note that http:// is not secure, and your login credentials may be intercepted.\n"));
165+
}
166+
167+
auto answer = QMessageBox::question(this, tr("Warning"), text);
168+
169+
return answer == QMessageBox::Yes;
170+
}
171+
146172
// Enable the OK button only when both textboxes contain something.
147173
void CustomLoginDialog::onTextBoxesChanged()
148174
{

launcher/ui/dialogs/CustomLoginDialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class CustomLoginDialog : public QDialog {
3838

3939
void setUserInputsEnabled(bool enable);
4040

41+
bool showWarning();
42+
4143
protected slots:
4244
void accept();
4345

@@ -58,4 +60,5 @@ class CustomLoginDialog : public QDialog {
5860
Task::Ptr m_loginTask;
5961
Net::Download::Ptr m_requestTask;
6062
QUrl m_loginUrl;
63+
QUrl m_resolvedUrl;
6164
};

launcher/ui/dialogs/CustomLoginDialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>476</width>
10-
<height>325</height>
9+
<width>472</width>
10+
<height>349</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">

launcher/ui/pages/global/APIPage.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "settings/SettingsObject.h"
5454
#include "tools/BaseProfiler.h"
5555
#include "ui/GuiUtil.h"
56+
#include "UrlUtils.h"
5657

5758
APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage)
5859
{
@@ -174,16 +175,13 @@ void APIPage::applySettings()
174175
resourceURL.setPath(path);
175176
}
176177

177-
auto isLocalhost = [](const QUrl& url) { return url.host() == "localhost" || url.host() == "127.0.0.1" || url.host() == "::1"; };
178-
auto isUnsafe = [isLocalhost](const QUrl& url) { return !url.isEmpty() && url.scheme() == "http" && !isLocalhost(url); };
179-
180178
// Don't allow HTTP, since meta is basically RCE with all the jar files.
181-
if (isUnsafe(metaURL)) {
179+
if (UrlUtils::isUnsafe(metaURL)) {
182180
metaURL.setScheme("https");
183181
}
184182

185183
// Also don't allow HTTP
186-
if (isUnsafe(resourceURL)) {
184+
if (UrlUtils::isUnsafe(resourceURL)) {
187185
resourceURL.setScheme("https");
188186
}
189187

0 commit comments

Comments
 (0)