Skip to content

Add kaptcha verification to signup module#638

Open
vagisha wants to merge 4 commits into
release26.3-SNAPSHOTfrom
26.3_fb_signup-kaptcha
Open

Add kaptcha verification to signup module#638
vagisha wants to merge 4 commits into
release26.3-SNAPSHOTfrom
26.3_fb_signup-kaptcha

Conversation

@vagisha
Copy link
Copy Markdown
Collaborator

@vagisha vagisha commented May 21, 2026

Rationale

We need to add bot protection to the self-sign-up form.

Changes

  • Added server-side kaptcha verification to SignUpApiAction and BeginAction
  • Extracted shared helpers so both action paths follow the same verification sequence in the same order
  • Added emailConfirm field requiring users to enter their email address twice
  • Fixed two API path bugs: EmailValidator.isValid was not called, and a sendEmail failure was falling through to status=USER_ADDED
  • Wrapped TempUser insert + confirmation email in a transaction so the row is rolled back if email delivery fails
  • Rewrote signupPage.jsp to use <labkey:form> and <labkey:input> taglibs

Manual test plan

  • Valid kaptcha + valid form: confirmation email sent, TempUser row inserted
  • Invalid kaptcha: error returned, no row inserted
  • Session expired / kaptcha not initialized: load the page, delete the JSESSIONID cookie in DevTools → Application → Cookies, submit the form → expect "Captcha not initialized, please retry."
  • Invalid email format (e.g. "notanemail"): rejected with error message
  • Email / Confirm Email mismatch: rejected with error message
  • Email already registered: API returns status=USER_EXISTS
  • Tested as unauthenticated guest

See ai/todos/active/TODO-LK-20260517_add-kaptcha-to-signup.md

Co-Authored-By: Claude noreply@anthropic.com

vagisha and others added 2 commits May 20, 2026 18:47
* Added kaptchaText field to SignupForm
* SignUpController.SignUpApiAction.execute() now checks the session
  kaptcha value, rejects mismatches, and clears the attribute on success
* Populated error_message in the JSON response for invalid-email and
  validateSignupForm error paths so the wiki form can display them

See ai/todos/active/TODO-LK-20260517_add-kaptcha-to-signup.md

Co-Authored-By: Claude <noreply@anthropic.com>
* Extracted verifyCaptcha, parseAndValidateEmail, sendConfirmationEmail
  helpers; both actions now run the same sequence (captcha -> blank
  fields -> email format -> userExists -> send)
* Added emailConfirm field to SignupForm; validateSignupForm now also
  checks blank + match
* sendConfirmationEmail wraps the TempUser insert + sendEmail in a
  DbScope transaction so the row rolls back on send failure
* SignUpApiAction now also runs EmailValidator.isValid (closes a real
  divergence from BeginAction) and no longer falls through to
  status=USER_ADDED after a sendEmail failure
* Rewrote signupPage.jsp using <labkey:form>/<labkey:input> with
  Confirm Email and kaptcha sections

See ai/todos/active/TODO-LK-20260517_add-kaptcha-to-signup.md

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

ERROR: A pull request from 26.3_fb_signup-kaptcha is expected to target release26.3-SNAPSHOT, not develop

@vagisha vagisha changed the base branch from develop to release26.3-SNAPSHOT May 21, 2026 19:30
- Catch ConfigurationException from sendEmail (was only catching MessagingException)
- Add status="ERROR" to API captcha-failure response for consistency with other response paths
- Remove hardcoded "six characters" from kaptcha instruction text
- Add aria-label to kaptcha input field
- Use method reference in errorsToMessages stream

Co-Authored-By: Claude <noreply@anthropic.com>
@vagisha vagisha marked this pull request as ready for review May 21, 2026 20:29
@vagisha vagisha requested a review from Copilot May 21, 2026 20:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds bot protection and improves correctness of the self-sign-up flow by introducing server-side captcha verification and aligning validation + email delivery handling across both the form POST and API signup paths.

Changes:

  • Added server-side captcha verification and shared helper methods used by both BeginAction and SignUpApiAction.
  • Added emailConfirm field and related validation to reduce email-entry mistakes.
  • Wrapped TempUser creation + confirmation email sending in a transaction to avoid persisting rows when email delivery fails; refactored signup JSP to use LabKey taglibs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
signup/src/org/labkey/signup/signupPage.jsp Reworked signup form markup to use <labkey:form> / <labkey:input>, added confirm-email field and captcha UI with reload behavior.
signup/src/org/labkey/signup/SignUpController.java Added captcha verification + shared validation helpers, added confirm-email field support, and refactored email send + TempUser insert to be transactional.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread signup/src/org/labkey/signup/signupPage.jsp
Comment thread signup/src/org/labkey/signup/SignUpController.java
Comment thread signup/src/org/labkey/signup/SignUpController.java
Comment thread signup/src/org/labkey/signup/SignUpController.java
Comment thread signup/src/org/labkey/signup/SignUpController.java
* SignUpApiAction.execute: add status="ERROR" to blank-field, bad-email,
  and send-failure error paths (was inconsistent with captcha path)
* verifyCaptcha: use parameterized logging instead of string concatenation
* verifyCaptcha: fix typo in comment ("a a" -> "a")

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants