The race scenario was as follows:
* Alice initiates email address change to bob@example.org
* a verification link is sent to bob@example.org
* separately, somebody creates a new account for bob@example.org
* Alice clicks on the verification link
At this point,
- if the database has an uniqueness constraint on auth_user.email,
Alice will receive a HTTP 500 error
- if there's no uniqueness constraint, the email change
will succeed and the system will have two accounts with the
same email address
The simple fix is to re-check the address availability just
before finalizing the email address change. Currently this is
not done in a transaction block, so the race condition still
exists in theory, but is much less likely to happen in practice.
Specifically, add read/write support for the new fields:
* success_kw
* failure_kw
* filter_subject
* filter_body
The API still supports reading/writing the "subject" and
"subject_fail" fields, but these are now marked as deprecated
in API documentation.
Fixes: #653
When adding "NOT NULL" on multiple columns at once, Django
throws errors:
django.db.utils.OperationalError:
cannot ALTER TABLE "api_check" because it has
pending trigger events
A workaround is to modify columns one by one in
separate migrations.
A similar issue has come up multiple times: the user
changes account's email address, enters a bad address
by mistake, and gets locked out of their account.
This commit adds an extra step in the "Change Email" flow:
* In "Account Settings", user clicks on [Change Email]
* User gets a prompt for a 6-digit confirmation code, which
has been sent to their old address. This is to prevent
account takeover when Eve sits down at a computer where Alice
is logged in.
* The user enters the confirmation code, and a "Change Email"
form loads.
* The user enters their new email address.
* (The new step!) Instead of changing the email right away,
we send a special login link to user's specified new address.
* (The new step, continued) The user clicks on the login link,
their account's email address gets updated, and they get
logged in.
The additional step makes sure the user can receive email
at their new address. If they cannot receive email there,
they cannot complete the "Change Email" procedure.
When testing with django==4.1a1, some tests were failing with
a message:
> ValueError: 'Check' instance needs to have a primary key
> value before this relationship can be used.
This commit fixes these failures, but there might be more
places to fix, that are not covered by tests yet.
I've run in the following problem a few times in tests:
* I create a model instance
* set its "created" field to a specific value
* I save the model instance
* I write testcase logic which relies on that specific "created" value
The testcase fails, because, with auto_now_add=True, Django
overwrites the created field. I can work around this by:
* Create and save a model instance
* Save it
* Set the created field to my desired value
* Save it again
But this is annoying to do, and annoying to troubleshoot
– it's easy to forget about the auto_now_add behaviour.
So I'm replacing auto_now_add=True with
default=django.utils.timezone.now.
The header format is:
Ping-Body-Limit: n
Where "n" is an integer number, the value of the PING_BODY_LIMIT
configuration setting.
Clients can use this header to decide how much POST data to send
in HTTP requests. If a client sends more than "n" bytes in the
request body, Healthchecks will store the first "n" bytes, and
ignore the rest.
The default value for PING_BODY_LIMIT is 10000 (10KB).