Warn users when they try to use a non-root-url to sign in/up (#32272) (#32273)

pull/32282/head
wxiaoguang 4 weeks ago committed by GitHub
parent db7349bc0d
commit 7e0fd4c208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      web_src/js/features/common-global.js
  2. 7
      web_src/js/features/user-auth.js
  3. 3
      web_src/js/index.js

@ -453,3 +453,11 @@ 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(`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');
}
}

@ -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');

@ -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();

Loading…
Cancel
Save