Skip to content

fix: renew a proof that expired while the page was in the background - #11

Merged
oxyc merged 1 commit into
mainfrom
fix/renew-expired-on-resume
Nov 18, 2026
Merged

oxyc merged 1 commit into
mainfrom
fix/renew-expired-on-resume

Conversation

@oxyc

@oxyc oxyc commented Nov 18, 2026

Copy link
Copy Markdown
Member

A visitor on kokkikartano.fi was turned away from the feedback form today. The rejection was logged as gform altcha rejected blog 1 form 3 (expired): 575 s past expiry. They were on an Android phone, and the access log shows why: the widget renewed its challenge every 10 minutes while the page was open, then stopped after 14:08:27 (screen off or tab in the background). The POST at 14:28:02 carried a proof that had expired at 14:18:27. They got through on a later try.

Cause: the widget learns of expiry from a setTimeout (expiresAt * 1000 - Date.now()), and a phone doesn't run timers while the page is frozen. Back on the page, the widget still says verified, so whenSolved() lets the submit through with the expired proof.

Fix: keep each proof's expiresAt (read from the verified event's payload) and check it against the clock:

  • The submit hold renews a proof whose time has passed and waits for the new one, the same way it already handles expired and unverified.
  • visibilitychange back to visible renews a stale proof straight away, so the submit doesn't wait on proof-of-work.
  • The recorded expiry is cleared whenever the widget leaves verified. Otherwise the old expiry would trigger one extra renewal after a normal timer-driven renewal.

Tested: there's no JS test harness in the repo, so I ran the script in Node against a stubbed widget and GF filter. A fresh proof submits without renewing. A stale proof holds the submit, renews once and then goes ahead. Coming back to the tab renews a stale proof and leaves a fresh one alone. A normal expiry while a submit waits renews only once. main's version fails the stale-proof cases. npm run build:production passes. I haven't tried it on a real phone yet.

🤖 Generated with Claude Code

The widget learns of expiry from a setTimeout, which a phone doesn't run
while its screen is off or the tab is backgrounded. Back on the page the
widget still says verified while holding an expired proof, and the submit
hold lets it through, so the server rejects it as expired.

Keep each proof's expiresAt from the verified payload and check the clock:
the submit hold renews a stale proof and waits for the new one, and coming
back to the tab renews it straight away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oxyc
oxyc merged commit 6fa1b92 into main Nov 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant