You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2026/04/29 19:32:32 UTC

(allura) branch db/8601 updated: [#8601] avoid flash samesite cookie issues by showing error on the page directly

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch db/8601
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/db/8601 by this push:
     new 79649ef41 [#8601] avoid flash samesite cookie issues by showing error on the page directly
79649ef41 is described below

commit 79649ef416673907251a6b7838952d360fc544b8
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Apr 29 15:32:05 2026 -0400

    [#8601] avoid flash samesite cookie issues by showing error on the page directly
---
 Allura/allura/controllers/auth.py                  |  8 ++----
 .../allura/templates/login_email_verify_error.html | 32 ++++++++++++++++++++++
 Allura/allura/tests/functional/test_auth.py        |  9 ++----
 3 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 30e719ebc..669117200 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -488,7 +488,7 @@ def login_email_sent(self, return_to='/', **kwargs):
             redirect('/auth/')
         return dict()
 
-    @expose()
+    @expose('jinja:allura:templates/login_email_verify_error.html')
     def login_email_verify(self, token, return_to='/', **kwargs):
         if not asbool(config.get('auth.email_auth_code.enabled', False)):
             raise wexc.HTTPNotFound
@@ -496,8 +496,7 @@ def login_email_verify(self, token, return_to='/', **kwargs):
             redirect(self._verify_return_to(return_to))
 
         if not session.get('multifactor-username'):
-            tg.flash('Your login session was disrupted.  Be sure to use the same browser when logging in and opening the email verification link.', 'error')
-            redirect('/auth/', {'return_to': kwargs['return_to']} if kwargs.get('return_to') else {})
+            return dict(error='Your login session was disrupted.<br>Be sure to use the same browser when logging in and opening the email verification link.')
 
         user = M.User.by_username(session['multifactor-username'])
         if not user:
@@ -506,11 +505,10 @@ def login_email_verify(self, token, return_to='/', **kwargs):
         try:
             EmailCodeAuthenticationService().validate_token(user, token)
         except InvalidEmailAuthCode:
-            tg.flash('Invalid or expired login link.', 'error')
             session.pop('multifactor-username', None)
             session.pop('mode', None)
             session.save()
-            redirect('/auth/')
+            return dict(error='Invalid or expired login link.')
 
         plugin.AuthenticationProvider.get(request).login(user=user, multifactor_success=True, email_verified=True)
         redirect(self._verify_return_to(return_to))
diff --git a/Allura/allura/templates/login_email_verify_error.html b/Allura/allura/templates/login_email_verify_error.html
new file mode 100644
index 000000000..42ce2a6d9
--- /dev/null
+++ b/Allura/allura/templates/login_email_verify_error.html
@@ -0,0 +1,32 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+{% set hide_left_bar = True %}
+{% extends g.theme.master %}
+
+{% block title %}{{ config['site_name'] }} Sign-In Error{% endblock %}
+
+{% block header %}Sign-In Error{% endblock %}
+
+{% block content %}
+<div style="width: max-content; font-size: 18px;">
+    <p class="error">{{ error|safe_html }}</p>
+</div>
+<p></p>
+<p><a href="/auth/">Return to login</a></p>
+{% endblock %}
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 4a5692eda..5db3a7f36 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -3457,8 +3457,7 @@ def test_email_auth_code(self, send_system_mail_to_user):
     @mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
     def test_input_auth_token_no_session(self):
         self.app.extra_environ = {'disable_auth_magic': 'True'}
-        r = self.app.get('/auth/login_email_verify?token=badtoken', status=302)
-        r = r.follow()
+        r = self.app.get('/auth/login_email_verify?token=badtoken', status=200)
         assert 'Your login session was disrupted' in r.text
         assert not r.session.get('username')
 
@@ -3479,8 +3478,7 @@ def test_input_incorrect_auth_token(self):
             r.mustcontain('Check Your Email')
 
             # Use an incorrect token
-            r = self.app.get('/auth/login_email_verify?token=badtoken', status=302)
-            r = r.follow()
+            r = self.app.get('/auth/login_email_verify?token=badtoken', status=200)
             assert 'Invalid or expired login link' in r.text
             assert not r.session.get('username')
 
@@ -3505,8 +3503,7 @@ def test_input_expired_auth_token(self):
             user_token = user.get_tool_data('AuthEmailCode', 'token')
             user.set_tool_data('AuthEmailCode', token_expiry=int(time_time()) - 900)
 
-            r = self.app.get(f'/auth/login_email_verify?token={user_token}', status=302)
-            r = r.follow()
+            r = self.app.get(f'/auth/login_email_verify?token={user_token}', status=200)
             assert 'Invalid or expired login link' in r.text
             assert not r.session.get('username')