From a9f94e348c7c0f7d125f29e2abe2a783a47189c1 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 16 Oct 2024 12:53:55 +0800 Subject: [PATCH 1/2] fix --- web_src/js/features/common-global.js | 9 +++++++++ web_src/js/features/user-auth.js | 7 ++++++- web_src/js/index.js | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 65eb237ddeee3..69dca72f2018f 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -453,3 +453,12 @@ export function checkAppUrl() { showGlobalErrorMessage(`Your ROOT_URL in app.ini is "${appUrl}", it's unlikely matching the site you are visiting. Mismatched ROOT_URL config causes wrong URL links for web UI/mail content/webhook notification/OAuth2 sign-in.`, 'warning'); } + +export function checkAppUrlScheme() { + const curUrl = window.location.href; + // some users visit "http://domain" while appUrl is "https://domain", COOKIE_SECURE makes it impossible to sign in + if (curUrl.startsWith('http:') && appUrl.startsWith('https:')) { + showGlobalErrorMessage(`Your ROOT_URL in app.ini "${appUrl}" uses HTTPS, it doesn't match the HTTP site you are visiting. +Mismatched ROOT_URL config would cause problems for sign-in/sign-up, etc.`, 'warning'); + } +} diff --git a/web_src/js/features/user-auth.js b/web_src/js/features/user-auth.js index a871ac471c2ec..13147ca72797b 100644 --- a/web_src/js/features/user-auth.js +++ b/web_src/js/features/user-auth.js @@ -1,4 +1,9 @@ -import {checkAppUrl} from './common-global.js'; +import {checkAppUrl, checkAppUrlScheme} from './common-global.js'; + +export function initUserCheckAppUrl() { + if (!document.querySelector('.page-content.user.signin, .page-content.user.signup, .page-content.user.link-account')) return; + checkAppUrlScheme(); +} export function initUserAuthOauth2() { const outer = document.getElementById('oauth2-login-navigator'); diff --git a/web_src/js/index.js b/web_src/js/index.js index 4c3852b4065a0..8cbeeea5d72cb 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -23,7 +23,7 @@ import {initFindFileInRepo} from './features/repo-findfile.js'; import {initCommentContent, initMarkupContent} from './markup/content.js'; import {initPdfViewer} from './render/pdf.js'; -import {initUserAuthOauth2} from './features/user-auth.js'; +import {initUserAuthOauth2, initUserCheckAppUrl} from './features/user-auth.js'; import { initRepoIssueDue, initRepoIssueReferenceRepositorySearch, @@ -184,6 +184,7 @@ onDomReady(() => { initCommitStatuses(); initCaptcha(); + initUserCheckAppUrl(); initUserAuthOauth2(); initUserAuthWebAuthn(); initUserAuthWebAuthnRegister(); From 4b9c2be1cfed9a212174f3b4e2ee33b74918abc7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 17 Oct 2024 00:06:16 +0800 Subject: [PATCH 2/2] Update web_src/js/features/common-global.js --- web_src/js/features/common-global.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 69dca72f2018f..80916b049d7f7 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -458,7 +458,6 @@ export function checkAppUrlScheme() { const curUrl = window.location.href; // some users visit "http://domain" while appUrl is "https://domain", COOKIE_SECURE makes it impossible to sign in if (curUrl.startsWith('http:') && appUrl.startsWith('https:')) { - showGlobalErrorMessage(`Your ROOT_URL in app.ini "${appUrl}" uses HTTPS, it doesn't match the HTTP site you are visiting. -Mismatched ROOT_URL config would cause problems for sign-in/sign-up, etc.`, 'warning'); + showGlobalErrorMessage(`This instance is configured to run under HTTPS (by ROOT_URL config), you are accessing by HTTP. Mismatched scheme might cause problems for sign-in/sign-up.`, 'warning'); } }