Skip to content

Commit 15be845

Browse files
23rdjohn-preston
authored andcommitted
Blocked internal oauth links from inside the app.
Related commit: cb82740.
1 parent d343431 commit 15be845

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

‎Telegram/SourceFiles/core/click_handler_types.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ QString HiddenUrlClickHandler::dragText() const {
144144

145145
void HiddenUrlClickHandler::Open(QString url, QVariant context) {
146146
url = Core::TryConvertUrlToLocal(url);
147-
if (Core::InternalPassportLink(url)) {
147+
if (Core::InternalPassportOrOAuthLink(url)) {
148148
return;
149149
}
150150

@@ -241,7 +241,7 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) {
241241

242242
void BotGameUrlClickHandler::onClick(ClickContext context) const {
243243
const auto url = Core::TryConvertUrlToLocal(this->url());
244-
if (Core::InternalPassportLink(url)) {
244+
if (Core::InternalPassportOrOAuthLink(url)) {
245245
return;
246246
}
247247
const auto openLink = [=] {

‎Telegram/SourceFiles/core/local_url_handlers.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ QString TryConvertUrlToLocal(QString url) {
19541954
return url;
19551955
}
19561956

1957-
bool InternalPassportLink(const QString &url) {
1957+
bool InternalPassportOrOAuthLink(const QString &url) {
19581958
const auto urlTrimmed = url.trimmed();
19591959
if (!urlTrimmed.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
19601960
return false;
@@ -1967,23 +1967,33 @@ bool InternalPassportLink(const QString &url) {
19671967
u"^passport/?\\?(.+)(#|$)"_q,
19681968
command,
19691969
matchOptions);
1970+
const auto oauthMatch = regex_match(
1971+
u"^oauth/?\\?(.+)(#|$)"_q,
1972+
command,
1973+
matchOptions);
19701974
const auto usernameMatch = regex_match(
19711975
u"^resolve/?\\?(.+)(#|$)"_q,
19721976
command,
19731977
matchOptions);
1974-
const auto usernameValue = usernameMatch->hasMatch()
1975-
? url_parse_params(
1978+
auto usernameValue = QString();
1979+
if (usernameMatch->hasMatch()) {
1980+
const auto params = url_parse_params(
19761981
usernameMatch->captured(1),
1977-
UrlParamNameTransform::ToLower).value(u"domain"_q)
1978-
: QString();
1982+
UrlParamNameTransform::ToLower);
1983+
usernameValue = params.value(u"domain"_q);
1984+
}
19791985
const auto authLegacy = (usernameValue == u"telegrampassport"_q);
1980-
return authMatch->hasMatch() || authLegacy;
1986+
const auto oauthLegacy = (usernameValue == u"oauth"_q);
1987+
return authMatch->hasMatch()
1988+
|| oauthMatch->hasMatch()
1989+
|| authLegacy
1990+
|| oauthLegacy;
19811991
}
19821992

19831993
bool StartUrlRequiresActivate(const QString &url) {
19841994
return Core::App().passcodeLocked()
19851995
? true
1986-
: !InternalPassportLink(url);
1996+
: !InternalPassportOrOAuthLink(url);
19871997
}
19881998

19891999
void ResolveAndShowUniqueGift(

‎Telegram/SourceFiles/core/local_url_handlers.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct LocalUrlHandler {
4242

4343
[[nodiscard]] QString TryConvertUrlToLocal(QString url);
4444

45-
[[nodiscard]] bool InternalPassportLink(const QString &url);
45+
[[nodiscard]] bool InternalPassportOrOAuthLink(const QString &url);
4646

4747
[[nodiscard]] bool StartUrlRequiresActivate(const QString &url);
4848

‎Telegram/SourceFiles/core/ui_integration.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ bool UiIntegration::handleUrlClick(
409409
const QString &url,
410410
const QVariant &context) {
411411
const auto local = Core::TryConvertUrlToLocal(url);
412-
if (Core::InternalPassportLink(local)) {
412+
if (Core::InternalPassportOrOAuthLink(local)) {
413413
return true;
414414
}
415415

‎Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ void WebViewInstance::botDownloadsAction(
15001500

15011501
bool WebViewInstance::botHandleLocalUri(QString uri, bool keepOpen) {
15021502
const auto local = Core::TryConvertUrlToLocal(uri);
1503-
if (Core::InternalPassportLink(local)) {
1503+
if (Core::InternalPassportOrOAuthLink(local)) {
15041504
return true;
15051505
} else if (!local.startsWith(u"tg://"_q, Qt::CaseInsensitive)
15061506
&& !local.startsWith(u"tonsite://"_q, Qt::CaseInsensitive)

0 commit comments

Comments
 (0)