Skip to content

Enhance CORS management with support to configure regexes - #4833

Merged
ThaminduDilshan merged 1 commit into
thunder-id:mainfrom
NipuniBhagya:allowed-origin-fix
Aug 11, 2026
Merged

Enhance CORS management with support to configure regexes#4833
ThaminduDilshan merged 1 commit into
thunder-id:mainfrom
NipuniBhagya:allowed-origin-fix

Conversation

@NipuniBhagya

@NipuniBhagya NipuniBhagya commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Purpose

This pull request refactors the CORS Allowed Origins editor in the application creation flow to improve validation, user experience, and code maintainability. The main change is replacing the generic URI list editor with a dedicated CorsOriginsEditor component, which supports both exact origins and regular expressions, and aligns validation and messaging with the application's settings page. The update also changes the internal representation of CORS origins from plain strings to structured objects, ensuring more robust handling throughout the UI and tests.

Preview

image

Approach

CORS Allowed Origins Editor Improvements:

  • Introduced a new CorsOriginsEditor component, which provides a better user experience for editing CORS allowed origins by supporting both exact origins and regex patterns, and by surfacing consistent validation messages shared with the settings page.
  • Updated the application creation flow to use structured AllowedOriginDraftRow objects instead of plain strings for CORS origins, ensuring each entry explicitly states its type and value. (Fa9d7fb2L189, Fa9d7fb2L212, Fa9d7fb2L340)

Validation and Readiness Logic:

  • Enhanced the step readiness logic in ConfigureDetails.tsx to block progression if any CORS origin entry is invalid, preventing silent submission failures and improving feedback to the user. [1] [2]

Testing Updates:

  • Updated tests to reflect the new CORS origin structure and validation, ensuring that quick-add and invalid entry cases are correctly handled and validated using the new component and data model. (F3f90b15L176, F3f90b15L208, F3f90b15L272)

Code Cleanup and Consistency:

Dependency and Utility Updates:

  • Updated imports and utility usage to support the new data model and validation functions for CORS origins, ensuring all components interact consistently with the new structure. [1] [2] [3]

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
    • Ran Vale and fixed all errors and warnings
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards in WSO2 Secure Coding Guidelines
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • New Features

    • Configure CORS allowed origins as exact origins or regular expressions.
    • Add, edit, remove, and switch between origin entry types.
    • Regex-based CORS entries now take effect without requiring a restart.
  • Bug Fixes

    • Blocked application creation when displayed CORS entries contain validation errors.
    • Improved validation for invalid origins, malformed expressions, duplicates, and unanchored-expression warnings.
    • Preserved configured values and entry types during editing.
    • Displayed an error notification when CORS settings fail to save.

@NipuniBhagya NipuniBhagya added Type/Improvement trigger-pr-builder Add when the PR is ready for CI; starts the PR Builder for this and all later pushes labels Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 72ab9b21-f62c-4fc9-892c-4df24ec76dac

📥 Commits

Reviewing files that changed from the base of the PR and between 60bb32e and ea3b99c.

📒 Files selected for processing (2)
  • frontend/packages/configure-settings/src/components/cors/__tests__/CorsSection.test.tsx
  • frontend/packages/configure-settings/src/utils/validateAllowedOriginRows.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/packages/configure-settings/src/utils/validateAllowedOriginRows.ts
  • frontend/packages/configure-settings/src/components/cors/tests/CorsSection.test.tsx

📝 Walkthrough

Walkthrough

The change replaces string-based CORS origins with typed exact-origin and regex rows. It adds shared validation, settings editing, application-creation integration, localized messages, typed merge handling, and end-to-end regex coverage.

Changes

Typed CORS origin workflow

Layer / File(s) Summary
Row contracts and validation
frontend/packages/configure-settings/src/models/*, frontend/packages/configure-settings/src/utils/*, frontend/packages/configure-settings/src/index.ts
Typed rows preserve origin or regex type, stable IDs, normalized values, duplicate keys, validation errors, and warnings.
Settings draft editor
frontend/packages/configure-settings/src/components/cors/*, frontend/packages/configure-settings/src/hooks/useAllowedOriginsDraft.ts, frontend/packages/i18n/src/locales/en-US.ts
The settings editor supports typed rows, locked entries, type changes, row-scoped validation, warnings, reset behavior, and typed payloads.
Application creation integration
frontend/apps/console/src/features/applications/components/create-application/*, frontend/apps/console/src/features/applications/contexts/ApplicationCreate/*, frontend/apps/console/src/features/applications/pages/ApplicationCreatePage.tsx, frontend/apps/console/src/features/applications/utils/*
Application creation stores typed rows, renders CorsOriginsEditor, blocks readiness for visible validation errors, and merges valid rows without losing their type.
Regex persistence coverage
tests/e2e/pages/settings/settings.page.ts, tests/e2e/tests/settings/cors-allowed-origins.spec.ts
The page object uses row-scoped controls. The end-to-end test saves a regex entry and verifies the matching CORS response.

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

Suggested reviewers: brionmario, jeradrutnam, donomalvindula

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the required template and explains the purpose, approach, related issues, testing, checklist, and security considerations.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding regex support to CORS management.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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
`@frontend/apps/console/src/features/applications/pages/ApplicationCreatePage.tsx`:
- Around line 665-673: Update the CORS persistence flow around
updateCorsConfig.mutate and the ApplicationCreatePage form surface to handle
mutation failures inline instead of relying on hook-level failure toasts.
Preserve the created application and keep the form/error state visible with an
actionable retry path until the CORS update succeeds; only continue the existing
success navigation after the mutation completes successfully.

In `@frontend/packages/configure-settings/src/hooks/useAllowedOriginsDraft.ts`:
- Around line 80-88: Update the dynamic validation translation in computeIssues,
specifically the resolve helper, to map each validation code to an appropriate
fallback string and pass that fallback as the positional argument to t. Preserve
the existing settings:cors.validation.${code} key and the returned
errors/warnings structure.

In `@frontend/packages/configure-settings/src/utils/isRegexAnchored.ts`:
- Around line 19-20: Update the end-anchor detection in isRegexAnchored so a
trailing `$` is accepted only when it has an even number of preceding
backslashes, while preserving the existing \z check with equivalent escaping
awareness. Add coverage for escaped and unescaped end anchors, including
patterns such as ^foo\$ and valid anchored endings.

In `@tests/e2e/pages/settings/settings.page.ts`:
- Around line 60-63: Update rowFor to locate the input by its value using
Playwright’s value-oriented locator API rather than interpolating value into a
CSS selector. Preserve matching for both exact origins and regex patterns,
including values containing backslashes, so hasCustomOrigin and
removeAllowedOrigin continue finding persisted rows.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b0aed382-3979-4123-b194-e9b14f5076a0

📥 Commits

Reviewing files that changed from the base of the PR and between 990e5ca and 75e0360.

📒 Files selected for processing (35)
  • frontend/apps/console/src/features/applications/components/create-application/ConfigureDetails.tsx
  • frontend/apps/console/src/features/applications/components/create-application/ConfigureRedirectUris.tsx
  • frontend/apps/console/src/features/applications/components/create-application/CorsOriginsEditor.tsx
  • frontend/apps/console/src/features/applications/components/create-application/__tests__/ConfigureRedirectUris.test.tsx
  • frontend/apps/console/src/features/applications/components/create-application/__tests__/CorsOriginsEditor.test.tsx
  • frontend/apps/console/src/features/applications/contexts/ApplicationCreate/ApplicationCreateContext.tsx
  • frontend/apps/console/src/features/applications/contexts/ApplicationCreate/ApplicationCreateProvider.tsx
  • frontend/apps/console/src/features/applications/pages/ApplicationCreatePage.tsx
  • frontend/apps/console/src/features/applications/utils/__tests__/hasInvalidCorsRows.test.ts
  • frontend/apps/console/src/features/applications/utils/__tests__/mergeCorsOrigins.test.ts
  • frontend/apps/console/src/features/applications/utils/hasInvalidCorsRows.ts
  • frontend/apps/console/src/features/applications/utils/mergeCorsOrigins.ts
  • frontend/packages/configure-settings/src/components/cors/AllowedOriginRow.tsx
  • frontend/packages/configure-settings/src/components/cors/CorsSection.tsx
  • frontend/packages/configure-settings/src/components/cors/OriginRow.tsx
  • frontend/packages/configure-settings/src/components/cors/__tests__/AllowedOriginRow.test.tsx
  • frontend/packages/configure-settings/src/components/cors/__tests__/CorsSection.test.tsx
  • frontend/packages/configure-settings/src/hooks/__tests__/useAllowedOriginsDraft.test.ts
  • frontend/packages/configure-settings/src/hooks/useAllowedOriginsDraft.ts
  • frontend/packages/configure-settings/src/index.ts
  • frontend/packages/configure-settings/src/models/allowedOriginRow.ts
  • frontend/packages/configure-settings/src/utils/__tests__/allowedOriginRows.test.ts
  • frontend/packages/configure-settings/src/utils/__tests__/baselineKey.test.ts
  • frontend/packages/configure-settings/src/utils/__tests__/isRegexAnchored.test.ts
  • frontend/packages/configure-settings/src/utils/__tests__/normalizedNonEmpty.test.ts
  • frontend/packages/configure-settings/src/utils/__tests__/validateAllowedOriginRows.test.ts
  • frontend/packages/configure-settings/src/utils/allowedOriginRows.ts
  • frontend/packages/configure-settings/src/utils/baselineKey.ts
  • frontend/packages/configure-settings/src/utils/isRegexAnchored.ts
  • frontend/packages/configure-settings/src/utils/nonEmptyRowKeys.ts
  • frontend/packages/configure-settings/src/utils/normalizedNonEmpty.ts
  • frontend/packages/configure-settings/src/utils/validateAllowedOriginRows.ts
  • frontend/packages/i18n/src/locales/en-US.ts
  • tests/e2e/pages/settings/settings.page.ts
  • tests/e2e/tests/settings/cors-allowed-origins.spec.ts
💤 Files with no reviewable changes (3)
  • frontend/packages/configure-settings/src/utils/normalizedNonEmpty.ts
  • frontend/packages/configure-settings/src/utils/tests/normalizedNonEmpty.test.ts
  • frontend/packages/configure-settings/src/components/cors/OriginRow.tsx

Comment on lines 665 to 673
const corsAdditions = corsOrigins.filter((row) => !isRowEmpty(row));
if (selectedTemplateConfig?.capabilities?.cors && corsAdditions.length > 0) {
updateCorsConfig.mutate({
data: mergeCorsOrigins(
corsConfigData?.writable.allowedOrigins ?? [],
corsConfigData?.readOnly.allowedOrigins ?? [],
validCorsAdditions,
corsAdditions,
),
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Preserve a recovery path when CORS persistence fails.

Line 667 starts the CORS mutation without an error handler. The success path then navigates away. If this write fails, the application is created but its configured CORS entries are lost without an actionable retry path. Keep a retryable error state visible until the CORS update succeeds.

As per coding guidelines, render mutation failures inline where the form has a natural surface and do not use hook-level failure toasts.

🤖 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
`@frontend/apps/console/src/features/applications/pages/ApplicationCreatePage.tsx`
around lines 665 - 673, Update the CORS persistence flow around
updateCorsConfig.mutate and the ApplicationCreatePage form surface to handle
mutation failures inline instead of relying on hook-level failure toasts.
Preserve the created application and keep the form/error state visible with an
actionable retry path until the CORS update succeeds; only continue the existing
success navigation after the mutation completes successfully.

Source: Coding guidelines

Comment thread frontend/packages/configure-settings/src/utils/isRegexAnchored.ts Outdated
Comment thread tests/e2e/pages/settings/settings.page.ts Outdated
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.64706% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tures/applications/pages/ApplicationCreatePage.tsx 50.00% 3 Missing ⚠️
...components/create-application/ConfigureDetails.tsx 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

NipuniBhagya added a commit to NipuniBhagya/thunderid that referenced this pull request Aug 11, 2026
Refs thunder-id#4833

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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
`@frontend/packages/configure-settings/src/components/cors/__tests__/CorsSection.test.tsx`:
- Line 21: Remove the duplicate updateState declaration in the CorsSection test
module, retaining a single binding with its existing {isError, error} type and
initial value so the test compiles.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 14454b8d-3d70-4e80-9693-6777e019b5a6

📥 Commits

Reviewing files that changed from the base of the PR and between 75e0360 and cf7d4cf.

📒 Files selected for processing (15)
  • frontend/apps/console/src/features/applications/components/create-application/CorsOriginsEditor.tsx
  • frontend/apps/console/src/features/applications/components/create-application/__tests__/ConfigureDetails.test.tsx
  • frontend/apps/console/src/features/applications/components/create-application/__tests__/CorsOriginsEditor.test.tsx
  • frontend/apps/console/src/features/applications/pages/ApplicationCreatePage.tsx
  • frontend/packages/configure-settings/src/components/cors/AllowedOriginRow.tsx
  • frontend/packages/configure-settings/src/components/cors/__tests__/AllowedOriginRow.test.tsx
  • frontend/packages/configure-settings/src/components/cors/__tests__/CorsSection.test.tsx
  • frontend/packages/configure-settings/src/hooks/__tests__/useAllowedOriginsDraft.test.ts
  • frontend/packages/configure-settings/src/hooks/useAllowedOriginsDraft.ts
  • frontend/packages/configure-settings/src/index.ts
  • frontend/packages/configure-settings/src/utils/__tests__/isRegexAnchored.test.ts
  • frontend/packages/configure-settings/src/utils/isRegexAnchored.ts
  • frontend/packages/configure-settings/src/utils/validateAllowedOriginRows.ts
  • frontend/packages/i18n/src/locales/en-US.ts
  • tests/e2e/pages/settings/settings.page.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • frontend/apps/console/src/features/applications/components/create-application/tests/CorsOriginsEditor.test.tsx
  • frontend/apps/console/src/features/applications/pages/ApplicationCreatePage.tsx
  • frontend/packages/i18n/src/locales/en-US.ts
  • frontend/packages/configure-settings/src/components/cors/AllowedOriginRow.tsx
  • frontend/packages/configure-settings/src/utils/validateAllowedOriginRows.ts
  • frontend/packages/configure-settings/src/hooks/useAllowedOriginsDraft.ts
  • frontend/packages/configure-settings/src/index.ts
  • tests/e2e/pages/settings/settings.page.ts

const mockMutate = vi.fn();
const mockReset = vi.fn();
// The save-failure surface reads the mutation's own error state, so each test declares it.
let updateState: {isError: boolean; error: Error | null} = {isError: false, error: null};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Remove the duplicate updateState declaration.

The file declares the same let updateState binding twice. TypeScript cannot compile this test module.

Proposed fix
 let updateState: {isError: boolean; error: Error | null} = {isError: false, error: null};
-let updateState: {isError: boolean; error: Error | null} = {isError: false, error: null};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let updateState: {isError: boolean; error: Error | null} = {isError: false, error: null};
let updateState: {isError: boolean; error: Error | null} = {isError: false, error: null};
🤖 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
`@frontend/packages/configure-settings/src/components/cors/__tests__/CorsSection.test.tsx`
at line 21, Remove the duplicate updateState declaration in the CorsSection test
module, retaining a single binding with its existing {isError, error} type and
initial value so the test compiles.

NipuniBhagya added a commit to NipuniBhagya/thunderid that referenced this pull request Aug 11, 2026
Refs thunder-id#4833

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
NipuniBhagya added a commit to NipuniBhagya/thunderid that referenced this pull request Aug 11, 2026
Refs thunder-id#4833

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Refs thunder-id#4833

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@brionmario
brionmario enabled auto-merge August 11, 2026 12:44
@brionmario
brionmario added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 11, 2026
@ThaminduDilshan
ThaminduDilshan added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 11, 2026
@ThaminduDilshan
ThaminduDilshan added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 11, 2026
@ThaminduDilshan
ThaminduDilshan added this pull request to the merge queue Aug 11, 2026
Merged via the queue into thunder-id:main with commit c0c97f9 Aug 11, 2026
26 checks passed
KashiwalHarsh pushed a commit to Infosys/thunder-id that referenced this pull request Aug 14, 2026
Refs thunder-id#4833

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Harsh Kashiwal <harsh.kashiwal@infosys.com>
lashinijay pushed a commit to lashinijay/thunderid that referenced this pull request Sep 3, 2026
Refs thunder-id#4833

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

trigger-pr-builder Add when the PR is ready for CI; starts the PR Builder for this and all later pushes Type/Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console silently converts CORS origins to regex format in application edit section

3 participants