Skip to content

fix: password reset delivery, captcha bypass, and map races - #80

Merged
jay739 merged 3 commits into
mainfrom
fix/pwr-delivery-captcha-races-email-render
Sep 10, 2026
Merged

jay739 merged 3 commits into
mainfrom
fix/pwr-delivery-captcha-races-email-render

Conversation

@jay739

@jay739 jay739 commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Summary

Three related bug classes found while investigating a user whose password reset never arrived, plus a broken button in the reset email.

  • Captcha bypass (security). verifyCaptcha shadowed its found-flag when looking up an invite captcha, so an unknown captcha ID left the outer flag true and fell through to comparing a zero-value Captcha. Submitting an unknown ID with empty text compared "" == "" and passed, bypassing the signup captcha entirely.
  • Unsynchronised shared state. pwrCaptchas and internalPWRs were plain maps written from both request handlers and the housekeeping daemon with no locking. That can overwrite a captcha answer mid-flight (a correctly typed answer gets rejected) or trip Go's fatal concurrent map write, which no recover() can catch. Both now use locked accessors, matching the existing ConfirmationKeys treatment.
  • Silently dropped resets. validatePWR logged parse failures at debug level and returned, and the RetryCount/RetryInterval constants were never wired up, so a file read before Jellyfin finished flushing it was dropped with no trace. It now retries and logs at error level once it gives up.
  • Success reported for undelivered messages. sendByID reassigned err per contact method with every error check commented out, and returned nil when a user had no contact method at all. Callers treated that as success, so a reset was logged as sent when nothing went out. Errors are now collected per method and a missing contact method returns ErrNoContactMethod.
  • Broken reset button. mj-raw is not processed inside mj-button, so the tag survived MJML compilation and reached mail clients wrapping the button label. Clients strip unknown elements, leaving the button with no text.

Test plan

  • go build ./... clean
  • go test ./... passing, including the email construction tests
  • New captcha_test.go covering the bypass, invite and PWR paths, and concurrent map access
  • Regression test verified to fail against the unfixed verifyCaptcha and pass with the fix
  • go test -race clean on the captcha tests
  • All templates recompiled, no mj- tags survive in the output
  • Verify a real password reset email end to end after deploy

Known and not fixed here

Go's html/template strips HTML comments, and MJML relies on Outlook conditional comments. On password-reset.html that removes all 24 conditional blocks (18.2 KB to 13.3 KB), so MSO layout is broken in every email. This is upstream jfa-go behaviour, not a regression, and Gmail is unaffected. Fixing it means parsing HTML emails with text/template and escaping injected data by hand.

…utexes

verifyCaptcha shadowed its "found" flag when looking up an invite captcha, so
an unknown captcha ID left the outer flag true and fell through to comparing a
zero-value Captcha. Submitting an unknown ID with empty text matched that empty
answer and passed verification, bypassing the signup captcha entirely.

pwrCaptchas and internalPWRs were plain maps written from both request handlers
and the housekeeping daemon with no synchronisation, which can overwrite a
captcha answer mid-flight or trip Go's fatal concurrent map write and take the
process down. Both now go through locked accessors, matching how
ConfirmationKeys is already handled.

Also returns after rendering the 404 page in GetCaptcha and GenCaptcha, which
previously carried on and wrote a second response.
…ng success

sendByID reassigned err on every contact method and had all of its error checks
commented out, so one method's failure was masked by the next, and a user with
no contact method at all returned nil. Callers took that as success, so
ResetMyPassword logged a reset as sent when nothing had gone out. Errors are now
collected per method and a missing contact method returns ErrNoContactMethod.

validatePWR dropped resets silently when Jellyfin's file was read before it had
finished flushing, because the parse failure only logged at debug level and the
RetryCount and RetryInterval constants were never wired up. It now retries,
logs at error level once it gives up, and says so when the user has no contact
method configured.
mj-raw is not processed inside mj-button, so the tag survived MJML compilation
and reached mail clients wrapping the button label. Clients strip unknown
elements, which left the reset button with no text on it.
@jay739
jay739 merged commit 1a3b4a2 into main Sep 10, 2026
7 checks passed
@jay739
jay739 deleted the fix/pwr-delivery-captcha-races-email-render branch September 10, 2026 08:32
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

⌂ 换网址