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/22 21:45:07 UTC
(allura) branch db/8601 created (now f8a696a12)
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a change to branch db/8601
in repository https://gitbox.apache.org/repos/asf/allura.git
at f8a696a12 [#8601] Do email verification for untrusted logins even if they did multifactor (protects against MITM attacks)
This branch includes the following new commits:
new 09208d2e1 [#8601] use link instead of code for email auth, and longer code
new 7fd2191f8 [#8601] remove very old and not helpful showbrowser() on test assertion failures
new fd3428c41 [#8601] consistent file extension for mail templates
new d18050c0f [#8601] update precommit hook for .md.jinja2 and update hook to published version now
new 4cf8e1a45 [#8601] use full domain in link for plaintext mail version to be better
new f8a696a12 [#8601] Do email verification for untrusted logins even if they did multifactor (protects against MITM attacks)
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(allura) 03/06: [#8601] consistent file extension for mail templates
Posted by br...@apache.org.
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
commit fd3428c413e086dee18f775531c43f995372a0e0
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Apr 21 17:29:50 2026 -0400
[#8601] consistent file extension for mail templates
---
Allura/allura/controllers/auth.py | 18 +++++++++---------
Allura/allura/model/auth.py | 8 ++++----
Allura/allura/model/notification.py | 7 +++----
Allura/allura/model/repo_refresh.py | 2 +-
Allura/allura/tasks/export_tasks.py | 2 +-
.../mail/{Discussion.txt => Discussion.md.jinja2} | 0
.../mail/{MergeRequest.txt => MergeRequest.md.jinja2} | 0
.../templates/mail/{Ticket.txt => Ticket.md.jinja2} | 0
...tication_code.txt => authentication_code.md.jinja2} | 0
.../mail/{bulk_export.html => bulk_export.md.jinja2} | 0
...ting_email.txt => claimed_existing_email.md.jinja2} | 0
.../templates/mail/{commits.md => commits.md.jinja2} | 0
.../mail/{email_added.md => email_added.md.jinja2} | 0
.../mail/{email_removed.md => email_removed.md.jinja2} | 0
.../templates/mail/{footer.txt => footer.md.jinja2} | 0
.../{forgot_password.txt => forgot_password.md.jinja2} | 0
...email_footer.txt => monitor_email_footer.md.jinja2} | 0
...{password_changed.md => password_changed.md.jinja2} | 0
...mail_changed.md => primary_email_changed.md.jinja2} | 0
.../{twofactor_apps.md => twofactor_apps.md.jinja2} | 0
...factor_disabled.md => twofactor_disabled.md.jinja2} | 0
...wofactor_enabled.md => twofactor_enabled.md.jinja2} | 0
...ery_regen.md => twofactor_recovery_regen.md.jinja2} | 0
...rmentions_email.md => usermentions_email.md.jinja2} | 0
24 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 6a3a3bc51..3f3feaf8b 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -230,7 +230,7 @@ def set_new_password(self, hash=None, pw=None, pw2=None):
user.set_tool_data('AuthPasswordReset', hash='', hash_expiry='') # Clear password reset token
user.set_tool_data('allura', pwd_reset_preserve_session=session.id)
h.auditlog_user('Password changed (through recovery process)', user=user)
- email_body = g.jinja2_env.get_template('allura:templates/mail/password_changed.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/password_changed.md.jinja2').render(dict(
user=user,
config=config
))
@@ -352,7 +352,7 @@ def _verify_addr(self, addr, do_auth_check=True):
if do_auth_check:
# don't send email when do_auth_check=False (e.g. admin panel move)
- email_body = g.jinja2_env.get_template('allura:templates/mail/email_added.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/email_added.md.jinja2').render(dict(
user=user,
config=config,
addr=addr.email
@@ -713,7 +713,7 @@ def _update_emails(self, user, admin=False, form_params={}):
user.set_tool_data('AuthPasswordReset', hash='', hash_expiry='')
h.auditlog_user('Email address deleted: %s', user.email_addresses[i], user=user)
if not admin:
- email_body = g.jinja2_env.get_template('allura:templates/mail/email_removed.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/email_removed.md.jinja2').render(dict(
user=user,
config=config,
addr=user.email_addresses[i]
@@ -774,7 +774,7 @@ def _update_emails(self, user, admin=False, form_params={}):
primary_addr,
user=user)
if not admin:
- email_body = g.jinja2_env.get_template('allura:templates/mail/primary_email_changed.md').render(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/primary_email_changed.md.jinja2').render(
dict(user=user, config=config, addr=primary_addr))
# send to previous primary addr
send_system_mail_to_user(old_primary_addr, 'Primary Email Address Changed', email_body)
@@ -826,7 +826,7 @@ def change_password(self, **kw):
redirect('.')
flash('Password changed')
h.auditlog_user('Password changed')
- email_body = g.jinja2_env.get_template('allura:templates/mail/password_changed.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/password_changed.md.jinja2').render(dict(
user=c.user,
config=config,
))
@@ -929,7 +929,7 @@ def totp_set(self, code, **kw):
del session['totp_new_key']
session.save()
tg.flash('Two factor authentication has now been set up.')
- email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_enabled.md').render(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_enabled.md.jinja2').render(
dict(user=c.user, config=config, ))
send_system_mail_to_user(c.user, 'Two-Factor Authentication Enabled', email_body)
redirect('/auth/preferences/multifactor_recovery')
@@ -949,7 +949,7 @@ def multifactor_disable(self, **kw):
c.user.set_pref('multifactor', False)
c.user.set_tool_data('allura', multifactor_date=None)
tg.flash('Multifactor authentication has now been disabled.')
- email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_disabled.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_disabled.md.jinja2').render(dict(
user=c.user,
config=config,
))
@@ -962,7 +962,7 @@ def totp_send_link(self, **kw):
if not asbool(config.get('auth.multifactor.totp', False)):
raise wexc.HTTPNotFound
- email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_apps.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_apps.md.jinja2').render(dict(
user=c.user,
config=config,
))
@@ -1001,7 +1001,7 @@ def multifactor_recovery_regen(self, **kw):
recovery = RecoveryCodeService.get()
recovery.regenerate_codes(c.user)
- email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_recovery_regen.md').render(dict(
+ email_body = g.jinja2_env.get_template('allura:templates/mail/twofactor_recovery_regen.md.jinja2').render(dict(
user=c.user,
config=config,
))
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 70990552c..b3eee63fc 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -156,7 +156,7 @@ def send_claim_attempt(self):
if confirmed_email:
log.info('Sending claim attempt email to %s', self.email)
- text = g.jinja2_env.get_template('allura:templates/mail/claimed_existing_email.txt').render(dict(
+ text = g.jinja2_env.get_template('allura:templates/mail/claimed_existing_email.md.jinja2').render(dict(
email=self,
user=confirmed_email[0].claimed_by_user(),
config=config
@@ -455,7 +455,7 @@ def send_password_reset_email(self, email_address=None, subject_tmpl='{site_name
log.info('Sending password recovery link to %s', utils.hide_email(email_address))
subject = subject_tmpl.format(site_name=config['site_name'])
- text = g.jinja2_env.get_template('allura:templates/mail/forgot_password.txt').render(dict(
+ text = g.jinja2_env.get_template('allura:templates/mail/forgot_password.md.jinja2').render(dict(
user=self,
config=config,
reset_url=reset_url,
@@ -484,7 +484,7 @@ def send_email_auth_code(self, return_to='/', subject_tmpl='{site_name} Authenti
link_params['return_to'] = return_to
verify_url = h.absurl(tg.url('/auth/login_email_verify', link_params))
subject = subject_tmpl.format(site_name=config['site_name'])
- text = g.jinja2_env.get_template('allura:templates/mail/authentication_code.txt').render(dict(
+ text = g.jinja2_env.get_template('allura:templates/mail/authentication_code.md.jinja2').render(dict(
user=self,
config=config,
verify_url=verify_url,
@@ -548,7 +548,7 @@ def send_user_mention_notification(self, mentioned_by, artifact):
"""Send user mention notification to {self} user.
"""
- tmpl = g.jinja2_env.get_template('allura:templates/mail/usermentions_email.md')
+ tmpl = g.jinja2_env.get_template('allura:templates/mail/usermentions_email.md.jinja2')
subject = '[{}:{}] Your name was mentioned'.format(
c.project.shortname, c.app.config.options.mount_point)
item_url = artifact.url()
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index 0cfe7ee93..0a8885a31 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -227,8 +227,7 @@ def _make_notification(cls, artifact, topic, **kwargs):
d['text'] = ''
try:
''' Add addional text to the notification e-mail based on the artifact type '''
- template = cls.view.get_template(
- 'mail/' + artifact.type_s + '.txt')
+ template = cls.view.get_template('mail/' + artifact.type_s + '.md.jinja2')
d['text'] += template.render(dict(c=c, g=g,
config=config, data=artifact, post=post, h=h))
except jinja2.TemplateNotFound:
@@ -698,7 +697,7 @@ def _render(cls, template, **kw):
@classmethod
def standard(cls, notification, allow_email_posting=True, **kw):
- return cls._render('mail/footer.txt',
+ return cls._render('mail/footer.md.jinja2',
domain=config['domain'],
notification=notification,
prefix=config['base_url'],
@@ -707,7 +706,7 @@ def standard(cls, notification, allow_email_posting=True, **kw):
@classmethod
def monitored(cls, toaddr, app_url, setting_url):
- return cls._render('mail/monitor_email_footer.txt',
+ return cls._render('mail/monitor_email_footer.md.jinja2',
domain=config['domain'],
email=toaddr,
app_url=app_url,
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 2e1fa2a3a..b2ff40f88 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -260,7 +260,7 @@ def send_notifications(repo, commit_ids):
else:
commit = commit_msgs[0]
subject = 'New commit {} by {}'.format(commit['shorthand_id'], commit['author'])
- text = g.jinja2_env.get_template("allura:templates/mail/commits.md").render(
+ text = g.jinja2_env.get_template("allura:templates/mail/commits.md.jinja2").render(
commit_msgs=commit_msgs,
max_num_commits=asint(tg.config.get('scm.notify.max_commits', 100)),
)
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index 0c83b734a..95d02a647 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -72,7 +72,7 @@ def process(self, project, tools, user, filename=None, send_email=True, with_att
if not send_email:
return
- tmpl = g.jinja2_env.get_template('allura:templates/mail/bulk_export.html')
+ tmpl = g.jinja2_env.get_template('allura:templates/mail/bulk_export.md.jinja2')
instructions = tg.config.get('bulk_export_download_instructions', '')
instructions = instructions.format(
project=project.shortname,
diff --git a/Allura/allura/templates/mail/Discussion.txt b/Allura/allura/templates/mail/Discussion.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/Discussion.txt
rename to Allura/allura/templates/mail/Discussion.md.jinja2
diff --git a/Allura/allura/templates/mail/MergeRequest.txt b/Allura/allura/templates/mail/MergeRequest.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/MergeRequest.txt
rename to Allura/allura/templates/mail/MergeRequest.md.jinja2
diff --git a/Allura/allura/templates/mail/Ticket.txt b/Allura/allura/templates/mail/Ticket.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/Ticket.txt
rename to Allura/allura/templates/mail/Ticket.md.jinja2
diff --git a/Allura/allura/templates/mail/authentication_code.txt b/Allura/allura/templates/mail/authentication_code.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/authentication_code.txt
rename to Allura/allura/templates/mail/authentication_code.md.jinja2
diff --git a/Allura/allura/templates/mail/bulk_export.html b/Allura/allura/templates/mail/bulk_export.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/bulk_export.html
rename to Allura/allura/templates/mail/bulk_export.md.jinja2
diff --git a/Allura/allura/templates/mail/claimed_existing_email.txt b/Allura/allura/templates/mail/claimed_existing_email.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/claimed_existing_email.txt
rename to Allura/allura/templates/mail/claimed_existing_email.md.jinja2
diff --git a/Allura/allura/templates/mail/commits.md b/Allura/allura/templates/mail/commits.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/commits.md
rename to Allura/allura/templates/mail/commits.md.jinja2
diff --git a/Allura/allura/templates/mail/email_added.md b/Allura/allura/templates/mail/email_added.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/email_added.md
rename to Allura/allura/templates/mail/email_added.md.jinja2
diff --git a/Allura/allura/templates/mail/email_removed.md b/Allura/allura/templates/mail/email_removed.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/email_removed.md
rename to Allura/allura/templates/mail/email_removed.md.jinja2
diff --git a/Allura/allura/templates/mail/footer.txt b/Allura/allura/templates/mail/footer.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/footer.txt
rename to Allura/allura/templates/mail/footer.md.jinja2
diff --git a/Allura/allura/templates/mail/forgot_password.txt b/Allura/allura/templates/mail/forgot_password.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/forgot_password.txt
rename to Allura/allura/templates/mail/forgot_password.md.jinja2
diff --git a/Allura/allura/templates/mail/monitor_email_footer.txt b/Allura/allura/templates/mail/monitor_email_footer.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/monitor_email_footer.txt
rename to Allura/allura/templates/mail/monitor_email_footer.md.jinja2
diff --git a/Allura/allura/templates/mail/password_changed.md b/Allura/allura/templates/mail/password_changed.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/password_changed.md
rename to Allura/allura/templates/mail/password_changed.md.jinja2
diff --git a/Allura/allura/templates/mail/primary_email_changed.md b/Allura/allura/templates/mail/primary_email_changed.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/primary_email_changed.md
rename to Allura/allura/templates/mail/primary_email_changed.md.jinja2
diff --git a/Allura/allura/templates/mail/twofactor_apps.md b/Allura/allura/templates/mail/twofactor_apps.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/twofactor_apps.md
rename to Allura/allura/templates/mail/twofactor_apps.md.jinja2
diff --git a/Allura/allura/templates/mail/twofactor_disabled.md b/Allura/allura/templates/mail/twofactor_disabled.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/twofactor_disabled.md
rename to Allura/allura/templates/mail/twofactor_disabled.md.jinja2
diff --git a/Allura/allura/templates/mail/twofactor_enabled.md b/Allura/allura/templates/mail/twofactor_enabled.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/twofactor_enabled.md
rename to Allura/allura/templates/mail/twofactor_enabled.md.jinja2
diff --git a/Allura/allura/templates/mail/twofactor_recovery_regen.md b/Allura/allura/templates/mail/twofactor_recovery_regen.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/twofactor_recovery_regen.md
rename to Allura/allura/templates/mail/twofactor_recovery_regen.md.jinja2
diff --git a/Allura/allura/templates/mail/usermentions_email.md b/Allura/allura/templates/mail/usermentions_email.md.jinja2
similarity index 100%
rename from Allura/allura/templates/mail/usermentions_email.md
rename to Allura/allura/templates/mail/usermentions_email.md.jinja2
(allura) 02/06: [#8601] remove very old and not helpful showbrowser() on test assertion failures
Posted by br...@apache.org.
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
commit 7fd2191f86410f580fa64bebc0ae641d24938248
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Apr 21 11:56:17 2026 -0400
[#8601] remove very old and not helpful showbrowser() on test assertion failures
---
Allura/allura/tests/functional/test_admin.py | 4 ++--
Allura/allura/tests/functional/test_auth.py | 4 ++--
.../forgegit/tests/functional/test_controllers.py | 18 +++++++++---------
.../forgesvn/tests/functional/test_controllers.py | 12 ++++++------
.../forgetracker/tests/functional/test_rest.py | 2 +-
.../forgetracker/tests/functional/test_root.py | 22 +++++++++++-----------
6 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 8af17b513..49c590ba5 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -791,13 +791,13 @@ def test_project_multi_groups(self):
'username': 'test-user'})
assert r.json['error'] == 'Test User (test-user) is already in the group Admin.'
r = self.app.get('/admin/groups/')
- assert 'test-user' in str(r), r.showbrowser()
+ assert 'test-user' in str(r)
with audits('remove user test-user from Admin'):
r = self.app.post('/admin/groups/remove_user', params={
'role_id': admin_id,
'username': 'test-user'})
r = self.app.get('/admin/groups/')
- assert 'test-user' not in str(r), r.showbrowser()
+ assert 'test-user' not in str(r)
@td.with_wiki
def test_new_group(self):
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 524d95820..8d8f1edd1 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -96,12 +96,12 @@ def test_login(self):
r = self.app.post('/auth/do_login', antispam=True, extra_environ=dict(username='*anonymous'), params=dict(
username='test-user', password='food',
_csrf_token=self.app.cookies['_csrf_token']))
- assert 'Invalid login' in str(r), r.showbrowser()
+ assert 'Invalid login' in str(r)
r = self.app.post('/auth/do_login', antispam=True, extra_environ=dict(username='*anonymous'), params=dict(
username='test-usera', password='foo',
_csrf_token=self.app.cookies['_csrf_token']))
- assert 'Invalid login' in str(r), r.showbrowser()
+ assert 'Invalid login' in str(r)
def test_login_invalid_username(self):
extra = {'username': '*anonymous'}
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index b0e74de78..750d7f2d3 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -220,7 +220,7 @@ def _get_ci(self, repo='/p/test/src-git/'):
def test_commit(self):
ci = self._get_ci()
resp = self.app.get(ci)
- assert 'Rick' in resp, resp.showbrowser()
+ assert 'Rick' in resp
def test_feed(self):
for ext in ['', '.rss']:
@@ -254,17 +254,17 @@ def test_feed(self):
def test_tree(self):
ci = self._get_ci()
resp = self.app.get(ci + 'tree/')
- assert len(resp.html.find_all('tr')) == 2, resp.showbrowser()
+ assert len(resp.html.find_all('tr')) == 2
resp = self.app.get(ci + 'tree/')
- assert 'README' in resp, resp.showbrowser()
+ assert 'README' in resp
links = [a.get('href') for a in resp.html.find_all('a')]
- assert 'README' in links, resp.showbrowser()
- assert 'README/' not in links, resp.showbrowser()
+ assert 'README' in links
+ assert 'README/' not in links
def test_tree_extra_params(self):
ci = self._get_ci()
resp = self.app.get(ci + 'tree/?format=raw')
- assert 'README' in resp, resp.showbrowser()
+ assert 'README' in resp
def test_tree_invalid(self):
ci = self._get_ci()
@@ -325,8 +325,8 @@ def test_invalid_file(self):
def test_diff(self):
ci = self._get_ci()
resp = self.app.get(ci + 'tree/README?diff=df30427c488aeab84b2352bdf88a3b19223f9d7a')
- assert 'readme' in resp, resp.showbrowser()
- assert '+++' in resp, resp.showbrowser()
+ assert 'readme' in resp
+ assert '+++' in resp
def test_diff_weirdchars(self):
self._setup_weird_chars_repo()
@@ -458,7 +458,7 @@ def test_subscribe(self):
def test_timezone(self):
ci = self._get_ci()
resp = self.app.get(ci + 'tree/')
- assert "Thu Oct 07, 2010 06:44 PM UTC" in resp, resp.showbrowser()
+ assert "Thu Oct 07, 2010 06:44 PM UTC" in resp
def test_checkout_input(self):
ci = self._get_ci()
diff --git a/ForgeSVN/forgesvn/tests/functional/test_controllers.py b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
index c81972b55..be0f6e1af 100644
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -87,7 +87,7 @@ def test_status_html(self):
def test_index(self):
resp = self.app.get('/src/').follow()
assert 'svn checkout' in resp
- assert '[r5]' in resp, resp.showbrowser()
+ assert '[r5]' in resp
def test_index_empty(self):
resp = self.app.get('/svn/')
@@ -138,7 +138,7 @@ def test_feed(self):
def test_commit(self):
resp = self.app.get('/src/3/tree/')
- assert len(resp.html.find_all('tr')) == 3, resp.showbrowser()
+ assert len(resp.html.find_all('tr')) == 3
def test_commit_unicode_and_special_chars(self):
resp = self.app.get('/src/6/')
@@ -172,9 +172,9 @@ def test_commit_unicode_and_special_chars(self):
def test_tree(self):
resp = self.app.get('/src/1/tree/')
- assert len(resp.html.find_all('tr')) == 2, resp.showbrowser()
+ assert len(resp.html.find_all('tr')) == 2
resp = self.app.get('/src/3/tree/a/')
- assert len(resp.html.find_all('tr')) == 2, resp.showbrowser()
+ assert len(resp.html.find_all('tr')) == 2
def test_file(self):
resp = self.app.get('/src/1/tree/README')
@@ -189,8 +189,8 @@ def test_invalid_file(self):
def test_diff(self):
resp = self.app.get('/src/3/tree/README?diff=2')
- assert 'This is readme' in resp, resp.showbrowser()
- assert '+++' in resp, resp.showbrowser()
+ assert 'This is readme' in resp
+ assert '+++' in resp
def test_checkout_svn(self):
self.app.post('/p/test/admin/src/set_checkout_url',
diff --git a/ForgeTracker/forgetracker/tests/functional/test_rest.py b/ForgeTracker/forgetracker/tests/functional/test_rest.py
index 6353284f0..8092e2fcb 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_rest.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_rest.py
@@ -111,7 +111,7 @@ def test_update_ticket(self):
args['private'] = str(args['private'])
args['discussion_disabled'] = str(args['discussion_disabled'])
ticket_view = self.api_post('/rest/p/test/bugs/1/save', params={'ticket_form': args})
- assert ticket_view.status_int == 200, ticket_view.showbrowser()
+ assert ticket_view.status_int == 200
json = ticket_view.json['ticket']
assert int(json['ticket_num']) == 1
assert json['summary'] == 'test update ticket', json
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index fcbb68199..92259e040 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -90,13 +90,13 @@ def new_ticket(self, mount_point='/bugs/', extra_environ=None, **kw):
class TestMilestones(TrackerTestController):
def test_milestone_list(self):
r = self.app.get('/bugs/milestones')
- assert '1.0' in r, r.showbrowser()
+ assert '1.0' in r
def test_milestone_list_progress(self):
self.new_ticket(summary='foo', _milestone='1.0')
self.new_ticket(summary='bar', _milestone='1.0', status='closed')
r = self.app.get('/bugs/milestones')
- assert '1 / 2' in r, r.showbrowser()
+ assert '1 / 2' in r
def test_default_milestone_created_if_missing(self):
p = M.Project.query.get(shortname='test')
@@ -252,7 +252,7 @@ def test_search_page_ticket_visibility(self):
ThreadLocalODMSession.flush_all()
response = self.app.get('/p/test/sub1/tickets/search/?q=my',
extra_environ=dict(username='*anonymous'))
- assert 'my ticket' in response, response.showbrowser()
+ assert 'my ticket' in response
@td.with_tool('test/sub1', 'Tickets', 'tickets')
def test_deleted_ticket_visibility(self):
@@ -812,8 +812,8 @@ def test_ticket_diffs(self):
'description': '1\n3\n4\n',
})
r = self.app.get('/bugs/1/')
- assert '<span class="gd">-2</span>' in r, r.showbrowser()
- assert '<span class="gi">+4</span>' in r, r.showbrowser()
+ assert '<span class="gd">-2</span>' in r
+ assert '<span class="gi">+4</span>' in r
def test_meta_comment(self):
self.new_ticket(summary="foo")
@@ -888,7 +888,7 @@ def test_delete_attachment(self):
ticket_editor = self.app.post('/bugs/1/update_ticket', {
'summary': 'zzz'
}, upload_files=[upload]).follow()
- assert file_name in ticket_editor, ticket_editor.showbrowser()
+ assert file_name in ticket_editor
req = self.app.get('/bugs/1/')
form = self._find_update_ticket_form(req)
file_link = BeautifulSoup(form.text, features="html5lib").find_all('a')[2]
@@ -1345,7 +1345,7 @@ def test_edit_ticket_validation(self):
form = self._find_update_ticket_form(error_form)
form['ticket_form.summary'] = new_summary
r = form.submit()
- assert r.status_int == 302, r.showbrowser()
+ assert r.status_int == 302
success = r.follow().html
assert success.find_all('form', {'action': '/p/test/bugs/1/update_ticket_from_widget'}) is not None
assert success.find('input', {'name': 'ticket_form.summary'})['value'] == new_summary
@@ -1441,12 +1441,12 @@ def test_search_current_user(self):
ThreadLocalODMSession.flush_all()
response = self.app.get('/p/test/bugs/search/?q=reported_by_s:$USER',
extra_environ={'username': 'test-user-0'})
- assert '1 result' in response, response.showbrowser()
- assert 'test first ticket' in response, response.showbrowser()
+ assert '1 result' in response
+ assert 'test first ticket' in response
response = self.app.get('/p/test/bugs/search/?q=reported_by_s:$USER',
extra_environ={'username': 'test-user-1'})
- assert '1 result' in response, response.showbrowser()
- assert 'test second ticket' in response, response.showbrowser()
+ assert '1 result' in response
+ assert 'test second ticket' in response
def test_feed(self):
self.new_ticket(
(allura) 05/06: [#8601] use full domain in link for plaintext mail version to be better
Posted by br...@apache.org.
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
commit 4cf8e1a45a276844c199b8ad72f6171152a33914
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Apr 22 11:37:38 2026 -0400
[#8601] use full domain in link for plaintext mail version to be better
---
Allura/allura/templates/mail/authentication_code.md.jinja2 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Allura/allura/templates/mail/authentication_code.md.jinja2 b/Allura/allura/templates/mail/authentication_code.md.jinja2
index e359b0d77..370b7d14b 100644
--- a/Allura/allura/templates/mail/authentication_code.md.jinja2
+++ b/Allura/allura/templates/mail/authentication_code.md.jinja2
@@ -25,4 +25,4 @@ If this was you, click the link below to complete your sign-in:
This link expires in 10 minutes.
-If you didn't request it, click <a href="/auth/forgotten_password">here</a> to reset your password immediately
+If you didn't request it, click [here]({{ config['base_url'] }}/auth/forgotten_password) to reset your password immediately.
(allura) 01/06: [#8601] use link instead of code for email auth, and longer code
Posted by br...@apache.org.
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
commit 09208d2e1e7f86ff604811105b21106498b3204e
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Apr 21 11:52:52 2026 -0400
[#8601] use link instead of code for email auth, and longer code
---
Allura/allura/controllers/auth.py | 71 +++++++++----
Allura/allura/lib/multifactor.py | 34 +++----
Allura/allura/lib/plugin.py | 13 ++-
Allura/allura/model/auth.py | 18 +++-
...thentication_code.txt => login_email_sent.html} | 21 ++--
Allura/allura/templates/login_multifactor.html | 66 +++++-------
.../allura/templates/mail/authentication_code.txt | 6 +-
Allura/allura/tests/functional/test_auth.py | 112 ++++++++++-----------
8 files changed, 190 insertions(+), 151 deletions(-)
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index fee01427a..6a3a3bc51 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations
+import hmac
import logging
import json
import os
@@ -27,7 +28,7 @@
import bson
import formencode as fe
import tg
-from tg import expose, flash, redirect, validate, config, session
+from tg import expose, flash, redirect, validate, config, session, override_template
from tg.decorators import with_trailing_slash, without_trailing_slash
from tg import tmpl_context as c, app_globals as g
from tg import request, response
@@ -404,8 +405,10 @@ def _verify_return_to(return_to):
@utils.AntiSpam.validate('Spambot protection engaged')
def do_login(self, return_to=None, **kw):
location = '/'
- if session.get('multifactor-username'):
- location = tg.url('/auth/multifactor', dict(return_to=return_to))
+ if session.get('mode') == 'email_code':
+ location = tg.url('/auth/login_email_sent', dict(return_to=return_to) if return_to else {})
+ elif session.get('multifactor-username'):
+ location = tg.url('/auth/multifactor', dict(return_to=return_to) if return_to else {})
elif session.get('expired-username'):
if return_to and return_to not in plugin.AuthenticationProvider.pwd_expired_allowed_urls:
location = tg.url(plugin.AuthenticationProvider.pwd_expired_allowed_urls[0], dict(return_to=return_to))
@@ -418,15 +421,17 @@ def do_login(self, return_to=None, **kw):
@expose('jinja:allura:templates/login_multifactor.html')
def multifactor(self, return_to='', mode='totp', **kwargs):
- if not asbool(config.get('auth.multifactor.totp', False)):
- raise wexc.HTTPNotFound
-
if not c.user.is_anonymous():
# already logged in, no need to do this form
redirect(self._verify_return_to(return_to))
- # currently only email_code mode is set via session
- if session.get('mode') == 'email_code':
- mode = 'email_code'
+
+ # this URL is also used for email code verification, but there's a different template to use
+ if session.get('mode') == 'email_code' and asbool(config.get('auth.email_auth_code.enabled', False)):
+ override_template(self.multifactor, 'jinja:allura:templates/login_email_sent.html')
+ return dict()
+
+ if not asbool(config.get('auth.multifactor.totp', False)):
+ raise wexc.HTTPNotFound
return dict(
return_to=return_to,
@@ -445,7 +450,7 @@ def do_multifactor(self, code, mode, **kwargs):
if 'multifactor-username' not in session:
tg.flash('Your multifactor login was disrupted, please start over.', 'error')
- plugin.AuthenticationProvider.get(request).logout() # clears all cookies that might be interfering
+ plugin.AuthenticationProvider.get(request).logout() # clears all cookies that might be interfering - also the flash message cookie :(
redirect('/auth/', {'return_to': kwargs.get('return_to', '')})
user = M.User.by_username(session['multifactor-username'])
@@ -458,10 +463,6 @@ def do_multifactor(self, code, mode, **kwargs):
recovery = RecoveryCodeService.get()
recovery.verify_and_remove_code(user, code)
h.auditlog_user('Logged in using a multifactor recovery code', user=user)
- elif mode == 'email_code':
- email_code_service = EmailCodeAuthenticationService()
- email_code_service.validate_code(user, code)
- h.auditlog_user('Logged in using email authentication code', user=user)
except (InvalidToken, InvalidRecoveryCode):
request.validation.errors['code'] = 'Invalid code, please try again.'
h.auditlog_user('Multifactor login - invalid code', user=user)
@@ -470,15 +471,49 @@ def do_multifactor(self, code, mode, **kwargs):
request.validation.errors['code'] = 'Multifactor rate limit exceeded, slow down and try again later.'
h.auditlog_user('Multifactor login - rate limit', user=user)
return self.multifactor(mode=mode, **kwargs)
- except InvalidEmailAuthCode:
- request.validation.errors['code'] = 'Invalid code, please try again.'
- h.auditlog_user('Email code login - invalid code', user=user)
- return self.multifactor(mode=mode, **kwargs)
else:
plugin.AuthenticationProvider.get(request).login(user=user, multifactor_success=True)
return_to = self._verify_return_to(kwargs.get('return_to'))
redirect(return_to)
+ @expose('jinja:allura:templates/login_email_sent.html')
+ def login_email_sent(self, return_to='/', **kwargs):
+ if not asbool(config.get('auth.email_auth_code.enabled', False)):
+ raise wexc.HTTPNotFound
+ if not c.user.is_anonymous():
+ redirect(self._verify_return_to(return_to))
+ if 'multifactor-username' not in session:
+ redirect('/auth/')
+ return dict()
+
+ @expose()
+ def login_email_verify(self, token, return_to='/', **kwargs):
+ if not asbool(config.get('auth.email_auth_code.enabled', False)):
+ raise wexc.HTTPNotFound
+ if not c.user.is_anonymous():
+ 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 {})
+
+ user = M.User.by_username(session['multifactor-username'])
+ if not user:
+ redirect('/auth/')
+
+ 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/')
+
+ h.auditlog_user('Logged in using email authentication link', user=user)
+ plugin.AuthenticationProvider.get(request).login(user=user, multifactor_success=True)
+ redirect(self._verify_return_to(return_to))
+
@expose(content_type='text/plain')
def refresh_repo(self, *repo_path):
# post-commit hooks use this
diff --git a/Allura/allura/lib/multifactor.py b/Allura/allura/lib/multifactor.py
index 053c670e6..1a46fe05f 100644
--- a/Allura/allura/lib/multifactor.py
+++ b/Allura/allura/lib/multifactor.py
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-
+import hmac
import os
import logging
import random
@@ -458,23 +458,21 @@ def verify_and_remove_code(self, user, code):
raise InvalidRecoveryCode
-class EmailCodeAuthenticationService(MongodbMultifactorCommon):
- def generate_code(self, user):
- code_length = 6
- code_expiration_time = 300 # seconds
-
- code = ''.join(secrets.choice(string.digits) for i in range(code_length))
- code_expiration_timestamp = int(time() + code_expiration_time)
- user.set_tool_data('AuthEmailCode', code=code, code_expiry=code_expiration_timestamp)
- return code
-
- def validate_code(self, user, code):
- user_code = user.get_tool_data('AuthEmailCode', 'code')
- user_code_expiry = user.get_tool_data('AuthEmailCode', 'code_expiry')
- if user_code:
- self.enforce_rate_limit(user)
- if user_code == code and int(time()) < user_code_expiry:
+class EmailCodeAuthenticationService:
+ def generate_token(self, user):
+ token_expiration_secs = 10 * 60
+ token = secrets.token_urlsafe(nbytes=8)
+ token_expiration_timestamp = int(time() + token_expiration_secs)
+ user.set_tool_data('AuthEmailCode', token=token, token_expiry=token_expiration_timestamp)
+ return token
+
+ def validate_token(self, user, token):
+ user_token = user.get_tool_data('AuthEmailCode', 'token')
+ user_token_expiry = user.get_tool_data('AuthEmailCode', 'token_expiry')
+ if user_token:
+ # compare_digest more secure than == (against timing analysis attacks)
+ if hmac.compare_digest(user_token, token) and int(time()) < user_token_expiry:
# remove the AuthEmailCode tool data from the user
- user.set_tool_data('AuthEmailCode', code="", code_expiry=0)
+ user.set_tool_data('AuthEmailCode', token='', token_expiry=0)
return True
raise InvalidEmailAuthCode
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 216d516e2..476c1bf69 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -96,6 +96,8 @@ class AuthenticationProvider:
multifactor_allowed_urls = [
'/auth/multifactor',
'/auth/do_multifactor',
+ '/auth/login_email_sent',
+ '/auth/login_email_verify',
'/auth/logout',
]
cfg_prefix_pwds = 'auth.password.'
@@ -188,7 +190,7 @@ def register_user(self, user_doc):
'''
raise NotImplementedError('register_user')
- def _login(self):
+ def _login(self) -> M.User:
'''
Authorize a user, usually using ``self.request.params['username']`` and ``['password']``
@@ -212,6 +214,9 @@ def login(self, user: M.User = None, multifactor_success: bool = False) -> M.Use
h.auditlog_user('Failed login', user=M.User.by_username(self.request.params['username']))
raise
+ if user.is_anonymous():
+ raise ValueError('Cannot log in an anonymous user')
+
if user.get_pref('multifactor') and not multifactor_success:
self.session['multifactor-username'] = user.username
h.auditlog_user('Multifactor login - password ok, code not entered yet', user=user)
@@ -232,7 +237,7 @@ def login(self, user: M.User = None, multifactor_success: bool = False) -> M.Use
self.session['multifactor-username'] = user.username
self.session['mode'] = 'email_code'
self.session.save()
- user.send_email_auth_code()
+ user.send_email_auth_code(return_to=self.request.params.get('return_to', '/'))
return None
else:
# Validate if we used an auth code to skip the `after_login` which sends a foreign login email
@@ -651,7 +656,7 @@ def register_user(self, user_doc):
u.reg_date = datetime.utcnow()
return u
- def _login(self):
+ def _login(self) -> M.User:
user = self.by_username(self.request.params['username'])
if not self.validate_password(user, self.request.params['password']):
raise exc.HTTPUnauthorized()
@@ -907,7 +912,7 @@ def set_password(self, user, old_password, new_password, set_timestamp=True):
except ldap.INVALID_CREDENTIALS:
raise exc.HTTPUnauthorized()
- def _login(self):
+ def _login(self) -> M.User:
if ldap is None:
raise Exception('The python-ldap package needs to be installed. '
'Run `pip install python-ldap` in your allura environment.')
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 0b331ed3a..70990552c 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -20,8 +20,9 @@
import logging
import typing
+import tg
from markupsafe import Markup
-from urllib.parse import urlparse
+from urllib.parse import urlparse, urlencode
from email import header
from hashlib import sha256
from collections import deque
@@ -470,14 +471,23 @@ def make_password_reset_url(self):
reset_url = h.absurl(f'/auth/forgotten_password/{hash}')
return reset_url
- def send_email_auth_code(self, subject_tmpl='{site_name} Authentication Code'):
+ def send_email_auth_code(self, return_to='/', subject_tmpl='{site_name} Authentication Code'):
+ from allura.controllers.auth import AuthController
+
email_address = self.get_pref('email_address')
- email_auth_code = EmailCodeAuthenticationService().generate_code(self)
+ token = EmailCodeAuthenticationService().generate_token(self)
+ return_to = AuthController._verify_return_to(return_to)
+ link_params = {
+ 'token': token,
+ }
+ if return_to and return_to != '/':
+ link_params['return_to'] = return_to
+ verify_url = h.absurl(tg.url('/auth/login_email_verify', link_params))
subject = subject_tmpl.format(site_name=config['site_name'])
text = g.jinja2_env.get_template('allura:templates/mail/authentication_code.txt').render(dict(
user=self,
config=config,
- email_auth_code=email_auth_code,
+ verify_url=verify_url,
))
allura.tasks.mail_tasks.send_system_mail_to_user(email_address, subject, text)
diff --git a/Allura/allura/templates/mail/authentication_code.txt b/Allura/allura/templates/login_email_sent.html
similarity index 61%
copy from Allura/allura/templates/mail/authentication_code.txt
copy to Allura/allura/templates/login_email_sent.html
index 9f4637116..9152677cc 100644
--- a/Allura/allura/templates/mail/authentication_code.txt
+++ b/Allura/allura/templates/login_email_sent.html
@@ -1,4 +1,4 @@
-{#
+{#-
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
@@ -16,11 +16,20 @@
specific language governing permissions and limitations
under the License.
-#}
+{% set hide_left_bar = True %}
+{% extends g.theme.master %}
-An attempt to sign-in to your {{ config['site_name'] }} account was detected.
+{% block title %}{{ config['site_name'] }} Verify Your Sign-In{% endblock %}
-If this was you, use the following verification code:
+{% block header %}Verify Your Sign-In{% endblock %}
-{{ email_auth_code }}
-
-If you didn't request it, click <a href="/auth/forgotten_password">here</a> to reset your password immediately
+{% block content %}
+<h2>Check Your Email</h2>
+<p>A sign-in verification link has been sent to your email address.</p>
+<p>Click the link in the email to complete your sign-in. The link expires in 10 minutes.</p>
+<p>
+ <a href="/auth/logout?return_to=/auth/">
+ <input type="button" value="Log Out and Start Over">
+ </a>
+</p>
+{% endblock %}
diff --git a/Allura/allura/templates/login_multifactor.html b/Allura/allura/templates/login_multifactor.html
index cf05f0064..579a482df 100644
--- a/Allura/allura/templates/login_multifactor.html
+++ b/Allura/allura/templates/login_multifactor.html
@@ -25,50 +25,30 @@
{% block content %}
<form method="post" action="/auth/do_multifactor">
- {% if mode == "email_code" %}
- <h2>E-mail Code Authentication</h2>
- <p>
- <span>Please enter the 6-digit code sent to your email:</span>
- <br>
- {% if request.validation.errors['code'] %}
- <span class="fielderror">{{ request.validation.errors['code'] }}</span><br>
- {% endif %}
- <input id="auth_code" type="text" name="code" autofocus autocomplete="off"/>
- <input type="hidden" name="return_to" value="{{ return_to }}"/>
- <br>
- <input type="submit" value="Log In">
- <a href="/auth/logout?return_to=/auth/{{ '?return_to=' + return_to | urlencode }}">
- <input type="button" value="Cancel">
- </a>
- <input type="hidden" name="mode" value="{{ mode }}"/>
- {{ lib.csrf_token() }}
- </p>
- {% else %}
- <h2>Enter your Multifactor Authentication Code</h2>
- <p>
- <span class="totp">Please enter the {{ config['auth.multifactor.totp.length'] }}-digit code from your authenticator app:</span>
- <span class="recovery">Please enter a recovery code:</span>
- <br>
- {% if request.validation.errors['code'] %}
- <span class="fielderror">{{ request.validation.errors['code'] }}</span><br>
- {% endif %}
- <input type="text" name="code" autofocus autocomplete="off"/>
- <input type="hidden" name="return_to" value="{{ return_to }}"/>
- <br>
- <input type="submit" value="Log In">
- <span class="alternate-links">
- <span class="totp">
- or <a href="#" class="show-recovery">use a recovery code</a>
- </span>
- <span class="recovery">
- or <a href="#" class="show-totp">use an authenticator app code</a>
- </span>
- </span>
- or <a href="/auth/logout?return_to=/auth/{{ '?return_to=' + return_to | urlencode }}">Cancel</a>
- <input type="hidden" name="mode" value="{{ mode }}"/>
- {{ lib.csrf_token() }}
- </p>
+ <h2>Enter your Multifactor Authentication Code</h2>
+ <p>
+ <span class="totp">Please enter the {{ config['auth.multifactor.totp.length'] }}-digit code from your authenticator app:</span>
+ <span class="recovery">Please enter a recovery code:</span>
+ <br>
+ {% if request.validation.errors['code'] %}
+ <span class="fielderror">{{ request.validation.errors['code'] }}</span><br>
{% endif %}
+ <input type="text" name="code" autofocus autocomplete="off"/>
+ <input type="hidden" name="return_to" value="{{ return_to }}"/>
+ <br>
+ <input type="submit" value="Log In">
+ <span class="alternate-links">
+ <span class="totp">
+ or <a href="#" class="show-recovery">use a recovery code</a>
+ </span>
+ <span class="recovery">
+ or <a href="#" class="show-totp">use an authenticator app code</a>
+ </span>
+ </span>
+ or <a href="/auth/logout?return_to=/auth/{{ '?return_to=' + return_to | urlencode }}">Cancel</a>
+ <input type="hidden" name="mode" value="{{ mode }}"/>
+ {{ lib.csrf_token() }}
+ </p>
</form>
diff --git a/Allura/allura/templates/mail/authentication_code.txt b/Allura/allura/templates/mail/authentication_code.txt
index 9f4637116..e359b0d77 100644
--- a/Allura/allura/templates/mail/authentication_code.txt
+++ b/Allura/allura/templates/mail/authentication_code.txt
@@ -19,8 +19,10 @@
An attempt to sign-in to your {{ config['site_name'] }} account was detected.
-If this was you, use the following verification code:
+If this was you, click the link below to complete your sign-in:
-{{ email_auth_code }}
+{{ verify_url }}
+
+This link expires in 10 minutes.
If you didn't request it, click <a href="/auth/forgotten_password">here</a> to reset your password immediately
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index e28d4dabd..524d95820 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -2958,12 +2958,13 @@ def test_settings_off(self):
'/auth/preferences/multifactor_disable',
'/auth/preferences/multifactor_recovery',
'/auth/preferences/multifactor_recovery_regen',
- '/auth/multifactor',
'/auth/do_multifactor',
]:
self.app.post(url,
{'password': 'foo', '_csrf_token': self.app.cookies['_csrf_token']},
status=404)
+ self.app.get('/auth/multifactor/', status=404,
+ extra_environ={'username': '*anonymous'},)
def test_user_disabled(self):
r = self.app.get('/auth/preferences/')
@@ -3357,14 +3358,13 @@ class TestEmailAuthCode(TestController):
@mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
@patch('allura.tasks.mail_tasks.send_system_mail_to_user')
- def test_email_auth_code_with_mfa(self, send_system_mail_to_user):
- self.app.get('/auth/preferences/') # establish session_id cookie
+ def test_mfa_no_email_auth(self, send_system_mail_to_user):
+ self.app.extra_environ = {'disable_auth_magic': 'True'}
user = M.User.by_username('test-user')
user.set_pref('multifactor', True)
with patch('allura.lib.plugin.AuthenticationProvider.trusted_login_source', return_value=True):
- extra = {'username': '*anonymous'}
- r = self.app.get('/auth/', extra_environ=extra)
+ r = self.app.get('/auth/')
f = r.forms[0]
encoded = self.app.antispam_field_names(f)
@@ -3376,14 +3376,13 @@ def test_email_auth_code_with_mfa(self, send_system_mail_to_user):
@mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
@patch('allura.tasks.mail_tasks.send_system_mail_to_user')
- def test_email_auth_code_no_mfa(self, send_system_mail_to_user):
- self.app.get('/auth/preferences/') # establish session_id cookie
- self.app.extra_environ = {'username': '*anonymous'}
+ def test_email_auth_code(self, send_system_mail_to_user):
+ self.app.extra_environ = {'disable_auth_magic': 'True'}
user = M.User.by_username('test-user')
user.set_pref('multifactor', False)
with patch('allura.lib.plugin.AuthenticationProvider.trusted_login_source', return_value=False):
- r = self.app.get('/auth/')
+ r = self.app.get('/auth/?return_to=/p/test/')
f = r.forms[0]
encoded = self.app.antispam_field_names(f)
f[encoded['username']] = 'test-user'
@@ -3391,49 +3390,47 @@ def test_email_auth_code_no_mfa(self, send_system_mail_to_user):
r = f.submit(status=302)
r = r.follow()
- # Validate the email with the auth code was sent
+ # Validate that the user is directed to the "check your email" page
+ assert 'Check Your Email' in r.text
+ assert r.request.path == '/auth/login_email_sent'
+
+ user = M.User.by_username('test-user')
+ user_token = user.get_tool_data('AuthEmailCode', 'token')
+ user_expiry_ts = user.get_tool_data('AuthEmailCode', 'token_expiry')
+
+ # Make sure a token was generated
+ assert user_token
+ assert len(user_token) > 10
+
+ # Validate the token is still valid
+ assert int(time_time()) < int(user_expiry_ts)
+
+ # Validate the email with the verification link was sent
args, kwargs = send_system_mail_to_user.call_args
assert r.session.get('mode') == 'email_code'
assert args[1] == f"{config['site_name']} Authentication Code"
assert send_system_mail_to_user.call_count == 1
+ email_text = send_system_mail_to_user.call_args[0][2]
- # Validate that the user is directed to the authentication code page
- assert 'Please enter the 6-digit code sent to your email' in r.text
+ link = [line for line in email_text.splitlines() if '/auth/login_email_verify' in line][0]
+ assert f'token={user_token}' in link
- @mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
- def test_input_correct_auth_code(self):
- self.app.get('/auth/preferences/')
- self.app.extra_environ = {'username': '*anonymous'}
- user = M.User.by_username('test-user')
- user.set_pref('multifactor', False)
+ # Click the verification link and validate the user is logged in and at final return_to URL
+ r = self.app.get(link, status=302)
+ assert r.location == 'http://localhost/p/test/'
+ assert r.session.get('username') == 'test-user'
- with patch('allura.lib.plugin.AuthenticationProvider.trusted_login_source', return_value=False):
- r = self.app.get('/auth/')
- f = r.forms[0]
- encoded = self.app.antispam_field_names(f)
- f[encoded['username']] = 'test-user'
- f[encoded['password']] = 'foo'
- r = f.submit(status=302)
- r = r.follow()
-
- user = M.User.by_username('test-user')
- user_code = user.get_tool_data('AuthEmailCode', 'code')
- user_expiry_ts = user.get_tool_data('AuthEmailCode', 'code_expiry')
- # Make sure a 6-digit code was generated
- assert len(str(user_code)) == 6
-
- # Validate the auth code is still valid
- assert int(time_time()) < int(user_expiry_ts)
-
- # Submit the code and validate the user is logged in
- r.form['code'] = user_code
- r = r.form.submit(status=302)
- assert r.location == 'http://localhost/'
+ @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()
+ assert 'Your login session was disrupted' in r.text
+ assert not r.session.get('username')
@mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
- def test_input_incorrect_auth_code(self):
- self.app.get('/auth/preferences/')
- self.app.extra_environ = {'username': '*anonymous'}
+ def test_input_incorrect_auth_token(self):
+ self.app.extra_environ = {'disable_auth_magic': 'True'}
user = M.User.by_username('test-user')
user.set_pref('multifactor', False)
@@ -3445,16 +3442,17 @@ def test_input_incorrect_auth_code(self):
f[encoded['password']] = 'foo'
r = f.submit(status=302)
r = r.follow()
+ r.mustcontain('Check Your Email')
- # Submit an incorrect code
- r.form['code'] = '1234567'
- r = r.form.submit()
- assert 'Invalid code' in r.text
+ # Use an incorrect token
+ r = self.app.get('/auth/login_email_verify?token=badtoken', status=302)
+ r = r.follow()
+ assert 'Invalid or expired login link' in r.text
+ assert not r.session.get('username')
@mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
- def test_input_expired_auth_code(self):
- self.app.get('/auth/preferences/')
- self.app.extra_environ = {'username': '*anonymous'}
+ def test_input_expired_auth_token(self):
+ self.app.extra_environ = {'disable_auth_magic': 'True'}
user = M.User.by_username('test-user')
user.set_pref('multifactor', False)
@@ -3466,15 +3464,17 @@ def test_input_expired_auth_code(self):
f[encoded['password']] = 'foo'
r = f.submit(status=302)
r = r.follow()
+ r.mustcontain('Check Your Email')
- # Set the code expiration to 5 minutes ago
+ # Set the token expiration to 15 minutes ago
user = M.User.by_username('test-user')
- user.set_tool_data('AuthEmailCode', code_expiry=int(time_time()) - 300)
- user_code = user.get_tool_data('AuthEmailCode', 'code')
- r.form['code'] = user_code
- r = r.form.submit()
+ user_token = user.get_tool_data('AuthEmailCode', 'token')
+ user.set_tool_data('AuthEmailCode', token_expiry=int(time_time()) - 900)
- assert 'Invalid code' in r.text
+ r = self.app.get(f'/auth/login_email_verify?token={user_token}', status=302)
+ r = r.follow()
+ assert 'Invalid or expired login link' in r.text
+ assert not r.session.get('username')
class TestTrackUserSessions(TestController):
(allura) 04/06: [#8601] update precommit hook for .md.jinja2 and update hook to published version now
Posted by br...@apache.org.
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
commit d18050c0fdfa31210b23fe47e4efe1e5b62a3891
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Apr 21 17:37:02 2026 -0400
[#8601] update precommit hook for .md.jinja2 and update hook to published version now
---
.pre-commit-config.yaml | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 62f87e102..aadea827c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -70,13 +70,14 @@ repos:
exclude: 'node_modules'
- repo: https://github.com/aristanetworks/j2lint
- rev: f291b271118c524b9ecb0bb5df9f846345963469 # latest as of June 2024
+ rev: v1.2.0
hooks:
- id: j2lint
- types: [html]
+ types: [file]
+ files: \.(html|jinja2|j2)$
args:
- --extensions
- - html
+ - html,jinja2,j2
# only check jinja-syntax-error and jinja-statements-no-tabs
- --ignore
- single-space-decorator
(allura) 06/06: [#8601] Do email verification for untrusted logins even if they did multifactor (protects against MITM attacks)
Posted by br...@apache.org.
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
commit f8a696a123e721e44d2833ce4b8d97c9432a30f6
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Apr 22 15:53:27 2026 -0400
[#8601] Do email verification for untrusted logins even if they did multifactor (protects against MITM attacks)
---
Allura/allura/controllers/auth.py | 5 +-
Allura/allura/lib/plugin.py | 37 +++++++--------
Allura/allura/tests/functional/test_auth.py | 74 +++++++++++++++++++++--------
3 files changed, 75 insertions(+), 41 deletions(-)
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 3f3feaf8b..30e719ebc 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -473,6 +473,8 @@ def do_multifactor(self, code, mode, **kwargs):
return self.multifactor(mode=mode, **kwargs)
else:
plugin.AuthenticationProvider.get(request).login(user=user, multifactor_success=True)
+ if session.get('mode') == 'email_code':
+ redirect(tg.url('/auth/login_email_sent', dict(return_to=kwargs.get('return_to', '/'))))
return_to = self._verify_return_to(kwargs.get('return_to'))
redirect(return_to)
@@ -510,8 +512,7 @@ def login_email_verify(self, token, return_to='/', **kwargs):
session.save()
redirect('/auth/')
- h.auditlog_user('Logged in using email authentication link', user=user)
- plugin.AuthenticationProvider.get(request).login(user=user, multifactor_success=True)
+ plugin.AuthenticationProvider.get(request).login(user=user, multifactor_success=True, email_verified=True)
redirect(self._verify_return_to(return_to))
@expose(content_type='text/plain')
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 476c1bf69..6cd02d63c 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -205,7 +205,7 @@ def after_login(self, user: M.User, request):
'''
pass
- def login(self, user: M.User = None, multifactor_success: bool = False) -> M.User | None:
+ def login(self, user: M.User = None, multifactor_success: bool = False, email_verified: bool = False) -> M.User | None:
from allura import model as M
if user is None:
try:
@@ -217,37 +217,36 @@ def login(self, user: M.User = None, multifactor_success: bool = False) -> M.Use
if user.is_anonymous():
raise ValueError('Cannot log in an anonymous user')
+ login_details = self.get_login_detail(self.request, user)
+
+ # Stage: TOTP — MFA users who haven't completed TOTP yet
if user.get_pref('multifactor') and not multifactor_success:
self.session['multifactor-username'] = user.username
h.auditlog_user('Multifactor login - password ok, code not entered yet', user=user)
self.session.save()
return None
- else:
- self.session.pop('multifactor-username', None)
-
- login_details = self.get_login_detail(self.request, user)
- # check if the user doesn't have mfa enabled but is logging in from an unknown location
- # they'll get an authentication code via email
- skip_after_login = False
- if asbool(config.get('auth.email_auth_code.enabled', False)) and not user.get_pref('multifactor') and not self.trusted_login_source(user, login_details) and not multifactor_success:
- h.auditlog_user('User without MFA attempted to login from untrusted location, '
- 'sending code via email for them to enter',
- user=user)
+ # Stage: email link — any user logging in from an untrusted location (after TOTP if applicable)
+ if asbool(config.get('auth.email_auth_code.enabled', False)) and not self.trusted_login_source(user, login_details) and not email_verified:
+ h.auditlog_user('Attempted login from untrusted location, sending email verification link', user=user)
self.session['multifactor-username'] = user.username
self.session['mode'] = 'email_code'
self.session.save()
user.send_email_auth_code(return_to=self.request.params.get('return_to', '/'))
return None
- else:
- # Validate if we used an auth code to skip the `after_login` which sends a foreign login email
- skip_after_login = self.session.get('mode') == 'email_code'
- self.session.pop('multifactor-username', None)
- self.session.pop('mode', None)
+
+ # All stages complete — clean up and proceed to login
+ skip_after_login = self.session.get('mode') == 'email_code' # if we used an email link we'll skip `after_login` which sends a foreign login email
+ self.session.pop('multifactor-username', None)
+ self.session.pop('mode', None)
+
+ auditlog_msg = 'Successful login'
+ if email_verified:
+ auditlog_msg += ' using email verification'
expire_reason = None
if self.is_password_expired(user):
- h.auditlog_user('Successful login; Password expired', user=user)
+ h.auditlog_user(f'{auditlog_msg}; Password expired', user=user)
expire_reason = 'via expiration process'
if not expire_reason:
expire_reason = self.login_check_password_change_needed(user, self.request.params.get('password'),
@@ -258,7 +257,7 @@ def login(self, user: M.User = None, multifactor_success: bool = False) -> M.Use
self.session['expired-reason'] = expire_reason
else:
self.session['username'] = user.username
- h.auditlog_user('Successful login', user=user)
+ h.auditlog_user(auditlog_msg, user=user)
if not skip_after_login:
self.after_login(user, self.request)
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 8d8f1edd1..4a5692eda 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -3125,7 +3125,10 @@ def test_disable(self):
assert tasks[0].kwargs['subject'] == 'Two-Factor Authentication Disabled'
assert 'disabled two-factor authentication' in tasks[0].kwargs['text']
- def test_login_totp(self):
+ @mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
+ @patch('allura.tasks.mail_tasks.send_system_mail_to_user')
+ @patch('allura.lib.plugin.AuthenticationProvider.trusted_login_source', return_value='exact ip')
+ def test_login_totp(self, trusted_login_source, send_system_mail_to_user):
self._init_totp()
# so test-admin isn't automatically logged in for all requests
@@ -3143,6 +3146,8 @@ def test_login_totp(self):
assert r.location.endswith('/auth/multifactor?return_to=%2Fp%2Ffoo'), r
r = r.follow()
assert not r.session.get('username')
+ assert r.session.get('multifactor-username') == 'test-admin'
+ assert send_system_mail_to_user.call_count == 0
# try an invalid code
r.form['code'] = 'invalid-code'
@@ -3158,14 +3163,61 @@ def test_login_totp(self):
with audits('Successful login', user=True):
r = r.form.submit()
- # confirm login and final page
+ # confirm login and final page — trusted source, so no email link stage
assert r.session['username'] == 'test-admin'
assert r.location.endswith('/p/foo'), r
+ assert send_system_mail_to_user.call_count == 0
# if you end up on multifactor page again somehow, redir
r = self.app.get('/auth/multifactor?return_to=/p/foo', status=302)
assert r.location == 'http://localhost/p/foo'
+ @mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
+ @patch('allura.tasks.mail_tasks.send_system_mail_to_user')
+ @patch('allura.lib.plugin.AuthenticationProvider.trusted_login_source', return_value=False)
+ def test_login_totp_untrusted_source(self, trusted_login_source, send_system_mail_to_user):
+ """MFA users from untrusted locations go through a 3-stage flow: password → TOTP → email link."""
+ self._init_totp()
+
+ # so test-admin isn't automatically logged in for all requests
+ self.app.extra_environ = {'disable_auth_magic': 'True'}
+
+ # regular login
+ r = self.app.get('/auth/?return_to=/p/foo')
+ f = r.forms[0]
+ encoded = self.app.antispam_field_names(f)
+ f[encoded['username']] = 'test-admin'
+ f[encoded['password']] = 'foo'
+ with audits('Multifactor login - password ok, code not entered yet', user=True):
+ r = r.form.submit()
+
+ # check results
+ assert r.location.endswith('/auth/multifactor?return_to=%2Fp%2Ffoo'), r
+ r = r.follow()
+ assert not r.session.get('username')
+ assert r.session.get('multifactor-username') == 'test-admin'
+ assert send_system_mail_to_user.call_count == 0
+
+ # use a valid code
+ totp = TotpService().Totp(self.sample_key)
+ code = totp.generate(time_time())
+ r.form['code'] = code
+ with audits('Attempted login from untrusted location, sending email verification link', user=True):
+ r = r.form.submit()
+ r = r.follow()
+
+ # have to verify by email now
+ assert r.request.path == '/auth/login_email_sent', self.webflash(r)
+ assert send_system_mail_to_user.call_count == 1
+ assert not r.session.get('username')
+ email_text = send_system_mail_to_user.call_args[0][2]
+ link = [line for line in email_text.splitlines() if '/auth/login_email_verify' in line][0]
+
+ # confirm login and final page
+ r = self.app.get(link, status=302)
+ assert r.location == 'http://localhost/p/foo'
+ assert r.session.get('username') == 'test-admin'
+
def test_login_rate_limit(self):
self._init_totp()
@@ -3356,24 +3408,6 @@ def test_send_links(self):
class TestEmailAuthCode(TestController):
- @mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
- @patch('allura.tasks.mail_tasks.send_system_mail_to_user')
- def test_mfa_no_email_auth(self, send_system_mail_to_user):
- self.app.extra_environ = {'disable_auth_magic': 'True'}
- user = M.User.by_username('test-user')
- user.set_pref('multifactor', True)
-
- with patch('allura.lib.plugin.AuthenticationProvider.trusted_login_source', return_value=True):
- r = self.app.get('/auth/')
-
- f = r.forms[0]
- encoded = self.app.antispam_field_names(f)
- f[encoded['username']] = 'test-user'
- f[encoded['password']] = 'foo'
- r = f.submit(status=302)
- assert send_system_mail_to_user.call_count == 0
- assert r.session.get('mode') is None
-
@mock.patch.dict(config, {'auth.email_auth_code.enabled': True})
@patch('allura.tasks.mail_tasks.send_system_mail_to_user')
def test_email_auth_code(self, send_system_mail_to_user):