Skip to content

Commit aa8981a

Browse files
DanielleMaywooddefelmnq
authored andcommitted
fix: urlencode email in reset password link (#15167)
Fixes #15151 This runs `urlencode` (provided by `text/template`) on the email address in the link. This ensures the link will work if a user has an email in the form `user+label@example.com`.
1 parent 559b4c3 commit aa8981a

5 files changed

+19
-8
lines changed

coderd/database/migrations/000267_fix_password_reset_notification_link.down.sql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
UPDATE notification_templates
2+
SET
3+
title_template = E'Reset your password for Coder',
4+
body_template = E'Hi {{.UserName}},\n\nUse the link below to reset your password.\n\nIf you did not make this request, you can ignore this message.',
5+
actions = '[{
6+
"label": "Reset password",
7+
"url": "{{base_url}}/reset-password/change?otp={{.Labels.one_time_passcode}}&email={{.UserEmail | urlquery}}"
8+
}]'::jsonb
9+
WHERE
10+
id = '62f86a30-2330-4b61-a26d-311ff3b608cf'

coderd/notifications/notifications_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
994994
id: notifications.TemplateUserRequestedOneTimePasscode,
995995
payload: types.MessagePayload{
996996
UserName: "Bobby",
997-
UserEmail: "bobby@coder.com",
997+
UserEmail: "bobby/drop-table+user@coder.com",
998998
UserUsername: "bobby",
999999
Labels: map[string]string{
10001000
"one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415",

coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
From: system@coder.com
2-
To: bobby@coder.com
2+
To: bobby/drop-table+user@coder.com
33
Subject: Reset your password for Coder
44
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
55
Date: Fri, 11 Oct 2024 09:03:06 +0000
@@ -18,7 +18,7 @@ If you did not make this request, you can ignore this message.
1818

1919

2020
Reset password: http://test.com/reset-password/change?otp=3Dfad9020b-6562-4=
21-
cdb-87f1-0486f1bea415&email=3Dbobby@coder.com
21+
cdb-87f1-0486f1bea415&email=3Dbobby%2Fdrop-table%2Buser%40coder.com
2222

2323
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
2424
Content-Transfer-Encoding: quoted-printable
@@ -57,9 +57,10 @@ argin: 8px 0 32px; line-height: 1.5;">
5757
<div style=3D"text-align: center; margin-top: 32px;">
5858
=20
5959
<a href=3D"http://test.com/reset-password/change?otp=3Dfad9020b-656=
60-
2-4cdb-87f1-0486f1bea415&email=3Dbobby@coder.com" style=3D"display: inline-=
61-
block; padding: 13px 24px; background-color: #020617; color: #f8fafc; text-=
62-
decoration: none; border-radius: 8px; margin: 0 4px;">
60+
2-4cdb-87f1-0486f1bea415&email=3Dbobby%2Fdrop-table%2Buser%40coder.com" sty=
61+
le=3D"display: inline-block; padding: 13px 24px; background-color: #020617;=
62+
color: #f8fafc; text-decoration: none; border-radius: 8px; margin: 0 4px;"=
63+
>
6364
Reset password
6465
</a>
6566
=20

coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"notification_name": "One-Time Passcode",
77
"notification_template_id": "00000000-0000-0000-0000-000000000000",
88
"user_id": "00000000-0000-0000-0000-000000000000",
9-
"user_email": "bobby@coder.com",
9+
"user_email": "bobby/drop-table+user@coder.com",
1010
"user_name": "Bobby",
1111
"user_username": "bobby",
1212
"actions": [
1313
{
1414
"label": "Reset password",
15-
"url": "http://test.com/reset-password/change?otp=00000000-0000-0000-0000-000000000000\u0026email=bobby@coder.com"
15+
"url": "http://test.com/reset-password/change?otp=00000000-0000-0000-0000-000000000000\u0026email=bobby%2Fdrop-table%2Buser%40coder.com"
1616
}
1717
],
1818
"labels": {

0 commit comments

Comments
 (0)