Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce https in flow2 for https connections #3542

Merged
merged 4 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/gui/creds/flow2auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void Flow2Auth::fetchNewToken(const TokenAction action)

// Step 1: Initiate a login, do an anonymous POST request
QUrl url = Utility::concatUrlPath(_account->url().toString(), QLatin1String("/index.php/login/v2"));
_enforceHttps = url.scheme() == QStringLiteral("https");

// add 'Content-Length: 0' header (see https://github.com/nextcloud/desktop/issues/1473)
QNetworkRequest req;
Expand All @@ -98,6 +99,11 @@ void Flow2Auth::fetchNewToken(const TokenAction action)
&& !json.isEmpty()) {
pollToken = json.value("poll").toObject().value("token").toString();
pollEndpoint = json.value("poll").toObject().value("endpoint").toString();
if (_enforceHttps && QUrl(pollEndpoint).scheme() != QStringLiteral("https")) {
qCWarning(lcFlow2auth) << "Can not poll endpoint because the returned url" << _pollEndpoint << "does not start with https";
emit result(Error, tr("The polling URL does not start with https despite the login URL started with https. Login will not be possible because this might be a security issue. Please contact your administrator."));
return;
}
loginUrl = json["login"].toString();
}

Expand Down Expand Up @@ -200,6 +206,11 @@ void Flow2Auth::slotPollTimerTimeout()
if (reply->error() == QNetworkReply::NoError && jsonParseError.error == QJsonParseError::NoError
&& !json.isEmpty()) {
serverUrl = json["server"].toString();
if (_enforceHttps && serverUrl.scheme() != QStringLiteral("https")) {
qCWarning(lcFlow2auth) << "Returned server url" << serverUrl << "does not start with https";
emit result(Error, tr("The returned server URL does not start with https despite the login URL started with https. Login will not be possible because this might be a security issue. Please contact your administrator."));
return;
}
loginName = json["loginName"].toString();
appPassword = json["appPassword"].toString();
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/creds/flow2auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private slots:
qint64 _secondsInterval;
bool _isBusy;
bool _hasToken;
bool _enforceHttps = false;
};

} // namespace OCC
21 changes: 20 additions & 1 deletion src/gui/wizard/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class WebEnginePage : public QWebEnginePage {

protected:
bool certificateError(const QWebEngineCertificateError &certificateError) override;

bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;

private:
bool _enforceHttps = false;
};

// We need a separate class here, since we cannot simply return the same WebEnginePage object
Expand Down Expand Up @@ -186,8 +191,10 @@ QWebEnginePage * WebEnginePage::createWindow(QWebEnginePage::WebWindowType type)
return view;
}

void WebEnginePage::setUrl(const QUrl &url) {
void WebEnginePage::setUrl(const QUrl &url)
{
QWebEnginePage::setUrl(url);
_enforceHttps = url.scheme() == QStringLiteral("https");
}

bool WebEnginePage::certificateError(const QWebEngineCertificateError &certificateError)
Expand All @@ -211,6 +218,18 @@ bool WebEnginePage::certificateError(const QWebEngineCertificateError &certifica
return ret == QMessageBox::Yes;
}

bool WebEnginePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
Q_UNUSED(type);
Q_UNUSED(isMainFrame);

if (_enforceHttps && url.scheme() != QStringLiteral("https")) {
QMessageBox::warning(nullptr, "Security warning", "Can not follow non https link on a https website. This might be a security issue. Please contact your administrator");
return false;
}
return true;
}

ExternalWebEnginePage::ExternalWebEnginePage(QWebEngineProfile *profile, QObject* parent) : QWebEnginePage(profile, parent) {

}
Expand Down