Skip to content

Comments

fix: harden validate_password_compliance against credential stuffing#1687

Merged
riderx merged 3 commits intomainfrom
riderx/fix-validate-password-compliance
Feb 25, 2026
Merged

fix: harden validate_password_compliance against credential stuffing#1687
riderx merged 3 commits intomainfrom
riderx/fix-validate-password-compliance

Conversation

@riderx
Copy link
Member

@riderx riderx commented Feb 24, 2026

Summary (AI generated)

  • Add a shared verifyCaptchaToken helper in supabase/functions/_backend/utils/captcha.ts used by both invite_new_user_to_org and validate_password_compliance.
  • Keep the validate_password_compliance flow compatible for authenticated callers by skipping CAPTCHA enforcement when a valid session token is present in authorization.
  • Ensure failed-auth throttling cannot be bypassed via unrelated successful logins by removing the success-path failed-auth counter reset from the compliance endpoint.
  • Preserve existing policy-checking and compliance persistence behavior while keeping endpoint responses and access checks consistent.

Motivation (AI generated)

The endpoint accepts public credentials checks with only an API key and had no robust abuse controls. The compatibility and throttling comments identified gaps that could block legitimate clients or weaken anti-abuse protections, so this follow-up tightens behavior without regressing existing app flows.

Business Impact (AI generated)

This keeps abuse protection in place for unauthenticated calls while avoiding false failures for established authenticated sessions, reducing risk of support regressions and maintaining reliable password compliance remediation for users.

Test Plan (AI generated)

  • bun lint
  • bun lint:backend
  • Manual verification of CAPTCHA_SECRET_KEY-enabled client path in validate_password_compliance (authenticated and unauthenticated).
  • Manual verification that failed auth attempts throttle by IP and that bypass via alternating unrelated successful logins no longer resets the failure counter.
  • Manual verification of successful compliance validation flow from src/pages/settings/account/ChangePassword.vue.

Generated with AI

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5cb5da2 and d9eb0b0.

📒 Files selected for processing (4)
  • supabase/functions/_backend/private/invite_new_user_to_org.ts
  • supabase/functions/_backend/private/validate_password_compliance.ts
  • supabase/functions/_backend/utils/captcha.ts
  • supabase/functions/_backend/utils/hono_middleware.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riderx/fix-validate-password-compliance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88bb7d0fbc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +113 to +115
if (!body.captcha_token) {
throw simpleError('invalid_request', 'Captcha token is required')
}

Choose a reason for hiding this comment

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

P1 Badge Keep captcha optional for existing compliance clients

When CAPTCHA_SECRET_KEY is configured, this now hard-fails requests that omit captcha_token, but the existing caller in src/pages/settings/account/ChangePassword.vue still sends only email, password, and org_id; that means users in captcha-enabled environments will receive invalid_request and cannot complete the password-compliance remediation flow. This change needs a compatibility path (or coordinated caller update) to avoid breaking current production clients.

Useful? React with 👍 / 👎.

return quickError(401, 'invalid_credentials', 'Invalid email or password')
}

await clearFailedAuth(c)

Choose a reason for hiding this comment

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

P1 Badge Keep failed-auth throttling from resetting on any success

Clearing the per-IP failed-auth counter after every successful login allows a credential-stuffing attacker to bypass the new limit by alternating failed guesses with one known-valid account from the same IP, which repeatedly resets the counter before it reaches the block threshold. This undermines the protection added in this commit; the counter should not be globally zeroed on unrelated successful authentications.

Useful? React with 👍 / 👎.

@riderx riderx force-pushed the riderx/fix-validate-password-compliance branch from 6f1aca1 to d9eb0b0 Compare February 25, 2026 05:52
@riderx riderx merged commit a2ceb0c into main Feb 25, 2026
11 of 12 checks passed
@riderx riderx deleted the riderx/fix-validate-password-compliance branch February 25, 2026 05:55
@sonarqubecloud
Copy link

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