Skip to content

Commit 7e0fd4c

Browse files
authored
Warn users when they try to use a non-root-url to sign in/up (#32272) (#32273)
1 parent db7349b commit 7e0fd4c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

web_src/js/features/common-global.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,11 @@ export function checkAppUrl() {
453453
showGlobalErrorMessage(`Your ROOT_URL in app.ini is "${appUrl}", it's unlikely matching the site you are visiting.
454454
Mismatched ROOT_URL config causes wrong URL links for web UI/mail content/webhook notification/OAuth2 sign-in.`, 'warning');
455455
}
456+
457+
export function checkAppUrlScheme() {
458+
const curUrl = window.location.href;
459+
// some users visit "http://domain" while appUrl is "https://domain", COOKIE_SECURE makes it impossible to sign in
460+
if (curUrl.startsWith('http:') && appUrl.startsWith('https:')) {
461+
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');
462+
}
463+
}

web_src/js/features/user-auth.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import {checkAppUrl} from './common-global.js';
1+
import {checkAppUrl, checkAppUrlScheme} from './common-global.js';
2+
3+
export function initUserCheckAppUrl() {
4+
if (!document.querySelector('.page-content.user.signin, .page-content.user.signup, .page-content.user.link-account')) return;
5+
checkAppUrlScheme();
6+
}
27

38
export function initUserAuthOauth2() {
49
const outer = document.getElementById('oauth2-login-navigator');

web_src/js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {initFindFileInRepo} from './features/repo-findfile.js';
2323
import {initCommentContent, initMarkupContent} from './markup/content.js';
2424
import {initPdfViewer} from './render/pdf.js';
2525

26-
import {initUserAuthOauth2} from './features/user-auth.js';
26+
import {initUserAuthOauth2, initUserCheckAppUrl} from './features/user-auth.js';
2727
import {
2828
initRepoIssueDue,
2929
initRepoIssueReferenceRepositorySearch,
@@ -184,6 +184,7 @@ onDomReady(() => {
184184
initCommitStatuses();
185185
initCaptcha();
186186

187+
initUserCheckAppUrl();
187188
initUserAuthOauth2();
188189
initUserAuthWebAuthn();
189190
initUserAuthWebAuthnRegister();

0 commit comments

Comments
 (0)