Repository navigation
Conversation
With auto_now_add, Django overwrites the cast_at that one_election_cast_confirm assigns when the CastVote is saved, so cast_at was always the confirmation time. A default keeps the assigned value, so cast_at can hold the time the ballot was received (next commit). The migration only changes the field definition: the column type is the same and it runs no SQL on PostgreSQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
one_election_cast, where the server receives the encrypted ballot, stores the time in the session next to the ballot (UTC, as an ISO string, since the session is JSON). It uses save_in_session_across_logouts, like encrypted_vote, so it survives a logout before confirmation. Posting the same ballot again in the session keeps the first time. one_election_cast_confirm uses that time as the ballot's cast_at. A ballot this voter already cast keeps the time it was first received. Without a reception time the confirmation is refused (fails closed) and the voter has to cast again. The session is already stored server-side, so this needs no new table, and if a session is purged its pending ballot goes with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before saving, compare the reception time of the ballot being confirmed with the voter's current ballot. If it isn't later, reject the confirmation, drop the pending ballot from the session and show a page that explains why. A confirmation held back and released late (Meyer and Smyth's re-voting attack) no longer replaces a ballot received after it. The rejection page logs the voter out like cast_done, and pops CURRENT_VOTER_ID the way cast_done does since benadida#518. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A confirmation that arrives without a reception time in the session is still refused, but instead of going back to the election page with no explanation, the voter now sees the rejection page with its own message: the server has no record of when it received the ballot, so vote again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ceilovee
marked this pull request as ready for review
November 24, 2026 02:03
Owner
|
I appreciate the PR, but I don't think this attack is one that can be reasonably expected, and I'd rather not complicate the flow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A voter's current ballot is the one with the latest
cast_at, andcast_atis set when the ballot is confirmed (auto_now_add). The ballot reaches the server earlier, though. The booth posts it to/castand the server keeps it in the session. Only after the voter logs in on/cast_confirmand confirms is theCastVotecreated. So a ballot whose confirmation arrives late looks newer than the ballots the voter cast in the meantime.Meyer and Smyth describe how to exploit this. The adversary has to be able to delay traffic from one terminal: for example, someone supervising a polling place who controls its network. They have the voter cast a "test" ballot on that terminal and hold back the message that completes it, which is the OAuth callback or the confirmation POST. The voter later votes privately, and that ballot is recorded. When the adversary releases the held message, the test ballot is confirmed at that moment, gets the latest
cast_at, and replaces the voter's real ballot.The check in
Voter.store_vote(cast_vote.cast_at < self.cast_at) doesn't stop this, because both times are confirmation times.Fix
Order a voter's ballots by when the server received them, using the server's clock. Meyer and Smyth suggest a timestamp from the voter's device or from the identity provider, but a device clock can be set by whoever controls the device.
one_election_caststores the reception time in the session asencrypted_vote_received_at, next to the pending ballot. It's a UTC ISO string, since the session is JSON. It's saved withsave_in_session_across_logouts, likeencrypted_vote. Posting the same ballot again in the same session keeps the first time.one_election_cast_confirmuses that time as theCastVote'scast_at. If this voter already cast this exact ballot, it keeps its original time. Ballots are public, so otherwise resubmitting a copy of an older ballot would make it look newer.cast_vote.cast_at <= voter.cast_at) is rejected. The pending ballot is dropped and a newcast_rejectedpage explains why. That page logs the voter out likecast_donedoes.CastVote.cast_at: changed fromauto_now_add=Truetodefault=datetime.datetime.utcnow, sinceauto_now_addoverwrites the assigned value on save. Migration0013only changes model state. The column type is unchanged and it runs no SQL on PostgreSQL.The time is kept in the session rather than in a new table. It has to be recorded before the voter is known, and the pending ballot already lives in the server-side session. That adds no new storage. And if a session expires or is purged, its pending ballot goes with it, so there's nothing left to confirm.
What else changes:
cast_atmeaning:cast_atis now the reception time, stored in UTC.auto_now_addstored localTIME_ZONEtime (becauseUSE_TZ = False), while code such as the recent-votes cutoff instats_viewsalready usesutcnow().Voter.store_votenow compares reception times, so it keeps the newer ballot.Tests