Skip to content

[2177] Added Captcha UI#2183

Open
zesu22 wants to merge 5 commits into
mosip:develop-gofrom
Infosys:feature/2177
Open

[2177] Added Captcha UI#2183
zesu22 wants to merge 5 commits into
mosip:develop-gofrom
Infosys:feature/2177

Conversation

@zesu22

@zesu22 zesu22 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor
  • Added custom captcha renderer
  • Added Google ReCaptcha, hCaptcha, Cloudflare Turnstile captcha as options
  • Modified flow graph according to captcha component

resolve #2177

Summary by CodeRabbit

  • New Features
    • Added reusable CAPTCHA box to OTP, password, and KBI authentication flows, and included CAPTCHA in submitted credentials.
    • CAPTCHA supports Google reCAPTCHA, Cloudflare Turnstile, and hCaptcha with configurable provider, site key, theme, and size.
  • Improvements
    • Updated form validation to surface CAPTCHA errors and handle expire/error states correctly.
    • Register the new CAPTCHA renderer in the UI.
    • Login page now re-renders sign-in with revalidation after interaction.
  • Tests / Chores
    • Adjusted a page-not-found test expectation and updated ignored build/coverage folders.

Signed-off-by: Zeeshan Mehboob <zeeshan.mehboob@infosys.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@zesu22, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 425e98b5-e9d9-4e84-b1d8-922543dfe3cd

📥 Commits

Reviewing files that changed from the base of the PR and between cc3e7a5 and 720dc63.

⛔ Files ignored due to path filters (1)
  • oidc-ui/package-lock.json is excluded by !**/package-lock.json, !**/package-lock.json
📒 Files selected for processing (2)
  • oidc-ui/package.json
  • oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx

Walkthrough

Adds configurable CAPTCHA rendering for Google reCAPTCHA, Cloudflare Turnstile, and hCaptcha, registers it with the OIDC UI, and includes CAPTCHA inputs in OTP, credential, and KBI authentication flows.

Changes

CAPTCHA integration

Layer / File(s) Summary
CAPTCHA components and provider adapters
oidc-ui/src/components/CaptchaComponent/*
Defines CAPTCHA models, form validation and callbacks, provider selection, and adapters for three CAPTCHA providers.
Renderer registration and UI dependencies
oidc-ui/package.json, oidc-ui/src/components/index.tsx, oidc-ui/src/main.tsx, oidc-ui/src/pages/LoginPage.tsx, .gitignore, oidc-ui/src/__tests__/pages/PageNotFoundPage.test.tsx
Adds CAPTCHA packages and types, exports and registers the renderer, enables login revalidation, updates ignored build outputs, and aligns a page test assertion.
Authentication flow CAPTCHA inputs
esignet-service/data/flows/flow-esignet.yaml
Adds shared CAPTCHA input definitions and includes CAPTCHA in OTP, password credential, and KBI prompts and executor contracts.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LoginPage
  participant ThunderIDProvider
  participant CaptchaRenderer
  participant CaptchaProvider
  participant AuthFlow
  LoginPage->>ThunderIDProvider: render SignIn with revalidation
  ThunderIDProvider->>CaptchaRenderer: render CAPTCHA_BOX
  CaptchaRenderer->>CaptchaProvider: render configured provider
  CaptchaProvider->>CaptchaRenderer: return CAPTCHA token or event
  CaptchaRenderer->>AuthFlow: submit captcha with authentication inputs
Loading

Suggested reviewers: anushasunkada

Poem

A token appears,
Three CAPTCHA paths quietly bloom,
OTP gates now wait.
Credentials carry proof,
KBI joins the guarded flow.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The .gitignore update, LoginPage prop change, and PageNotFoundPage test edits appear unrelated to the captcha feature. Move unrelated .gitignore, login-page, and test changes into separate PRs so this patch stays focused on captcha integration.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and correctly summarizes the main change: adding a captcha UI to the eSignet flow.
Linked Issues check ✅ Passed The PR adds captcha components and wires them into the OIDC flow, which satisfies issue #2177's request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@esignet-service/data/flows/flow-esignet.yaml`:
- Around line 710-713: In esignet-service/data/flows/flow-esignet.yaml at lines
710-713 and 962-965, correct the CAPTCHA field property from reuired to required
in basic_cred_auth and basic_kbi_auth so both CAPTCHA inputs are enforced.
- Around line 151-152: Replace the hardcoded siteKey under the google-recaptcha
provider with the designated environment-variable reference, following the
repository’s existing configuration syntax and naming conventions. Keep the
provider setting unchanged and ensure no secret value remains in the YAML.

In `@oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx`:
- Around line 52-86: Update the currentProvider selection in CaptchaComponent to
store the selected provider’s JSX element directly instead of wrapping it in an
inline function. Adjust the render path to render currentProvider directly while
preserving the existing provider conditions and FormControl error handling.
- Around line 20-43: Remove onInputChangeRef and its assignment, then update
handleSuccess, handleExpire, and handleError to call context.onInputChange
directly while preserving their existing fieldRef and empty-token behavior.
- Around line 14-17: Replace the local error state in CaptchaComponent with a
render-time value derived from formErrors[fieldRef], and remove the associated
useEffect that validates and updates that state. Ensure the component uses the
derived error value so externally updated server-side errors are reflected
immediately.

In `@oidc-ui/src/components/CaptchaComponent/CaptchaModel.tsx`:
- Around line 11-16: Replace the unconstrained size field in CaptchaComponent
with provider-specific validation, using a discriminated type keyed by provider
so Google reCAPTCHA and hCaptcha accept only normal, compact, or invisible,
while Cloudflare Turnstile accepts only normal, compact, or flexible. Update the
adapter usage in GoogleReCaptcha, CloudflareTurnstile, and HCaptcha to rely on
the validated type and remove casts that only suppress TypeScript errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 11fd3473-c15d-41d4-ab92-b763aa9b2b0f

📥 Commits

Reviewing files that changed from the base of the PR and between c1ddaf1 and 2d29f6f.

⛔ Files ignored due to path filters (1)
  • oidc-ui/package-lock.json is excluded by !**/package-lock.json, !**/package-lock.json
📒 Files selected for processing (11)
  • esignet-service/data/flows/flow-esignet.yaml
  • oidc-ui/package.json
  • oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx
  • oidc-ui/src/components/CaptchaComponent/CaptchaModel.tsx
  • oidc-ui/src/components/CaptchaComponent/CaptchaRenderer.tsx
  • oidc-ui/src/components/CaptchaComponent/CloudflareTurnstile.tsx
  • oidc-ui/src/components/CaptchaComponent/GoogleReCaptcha.tsx
  • oidc-ui/src/components/CaptchaComponent/HCaptcha.tsx
  • oidc-ui/src/components/index.tsx
  • oidc-ui/src/main.tsx
  • oidc-ui/src/pages/LoginPage.tsx

Comment thread esignet-service/data/flows/flow-esignet.yaml Outdated
Comment thread esignet-service/data/flows/flow-esignet.yaml Outdated
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx Outdated
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx Outdated
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx Outdated
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaModel.tsx
Signed-off-by: Zeeshan Mehboob <zeeshan.mehboob@infosys.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
esignet-service/data/flows/flow-esignet.yaml (1)

930-933: 🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win

Fix type mismatch for CAPTCHA input to prevent bot-mitigation bypass.

The CAPTCHA_BOX input is defined as type: CUSTOM here, but the downstream basic_kbi_auth executor requires it to be type: PASSWORD_INPUT. According to the flow engine contract, only PASSWORD_INPUT and OTP_INPUT fields are forwarded to the credentials map. This mismatch will cause the engine to drop the CAPTCHA response, either breaking the KBI flow or silently bypassing the CAPTCHA check entirely, which violates strict MOSIP bot-mitigation compliance requirements.

🔒️ Proposed fix
           - ref: CAPTCHA_BOX
             identifier: captcha
-            type: CUSTOM
+            type: PASSWORD_INPUT
             required: true
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@esignet-service/data/flows/flow-esignet.yaml` around lines 930 - 933, Update
the CAPTCHA_BOX input definition for identifier captcha to use type
PASSWORD_INPUT instead of CUSTOM, ensuring the CAPTCHA response is forwarded in
the credentials map to the basic_kbi_auth executor and the existing required
behavior remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@esignet-service/data/flows/flow-esignet.yaml`:
- Around line 930-933: Update the CAPTCHA_BOX input definition for identifier
captcha to use type PASSWORD_INPUT instead of CUSTOM, ensuring the CAPTCHA
response is forwarded in the credentials map to the basic_kbi_auth executor and
the existing required behavior remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7f421a52-49f7-4f2d-a588-a9f6db726520

📥 Commits

Reviewing files that changed from the base of the PR and between 2d29f6f and 60e96b1.

📒 Files selected for processing (2)
  • esignet-service/data/flows/flow-esignet.yaml
  • oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx

Signed-off-by: Zeeshan Mehboob <zeeshan.mehboob@infosys.com>
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx Outdated
Signed-off-by: Zeeshan Mehboob <zeeshan.mehboob@infosys.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@oidc-ui/package.json`:
- Line 42: Align the `@vitest/coverage-v8` devDependency with the project's Vitest
version by pinning both packages to the same exact installed version, 4.1.10;
update the related Vitest dependency entry alongside the coverage entry and
preserve the existing dependency configuration.

In `@oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx`:
- Around line 63-64: Update the invalid-provider branch in CaptchaComponent so
it records a CAPTCHA_BOX validation error and blocks submission when
providerElement remains null, rather than allowing the authentication flow to
continue. Remove the production console.warn call while preserving normal
rendering and submission behavior for supported providers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1fcbefc6-d97a-4ad0-ad8f-2ddcfb9d030b

📥 Commits

Reviewing files that changed from the base of the PR and between 60e96b1 and cc3e7a5.

⛔ Files ignored due to path filters (1)
  • oidc-ui/package-lock.json is excluded by !**/package-lock.json, !**/package-lock.json
📒 Files selected for processing (4)
  • .gitignore
  • oidc-ui/package.json
  • oidc-ui/src/__tests__/pages/PageNotFoundPage.test.tsx
  • oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx

Comment thread oidc-ui/package.json
Comment thread oidc-ui/src/components/CaptchaComponent/CaptchaComponent.tsx Outdated
Signed-off-by: Zeeshan Mehboob <zeeshan.mehboob@infosys.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