Skip to content

Conversation

@ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Jun 4, 2025

closes ##10916

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option for specifying trusted origins, enhancing control over allowed origins for CORS, Web Authentication, and social sign-in redirections.
  • Improvements

    • Updated internal logic to validate origins based on the new trusted origins setting.
    • Enhanced documentation for configuration properties related to trusted origins.
    • Improved handling of forwarded headers and allowed hosts by integrating trusted origins into middleware setup.
  • Configuration

    • Added a "TrustedOrigins" array to the configuration file for clearer management of allowed origins.

@ysmoradi ysmoradi requested review from Copilot and msynk June 4, 2025 19:21
@coderabbitai
Copy link

coderabbitai bot commented Jun 4, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes refactor origin validation across the server and web projects by introducing and standardizing a TrustedOrigins property for CORS, Web Auth, and forwarded headers configuration. The logic now consistently uses IsTrustedOrigin instead of IsAllowedOrigin for origin checks, updates related documentation, and adjusts configuration files and middleware setup accordingly.

Changes

Files / Groups Change Summary
ServerApiSettings.cs Renamed internal method IsAllowedOrigin to IsTrustedOrigin, updated/moved TrustedOrigins property and docs.
HttpRequestExtensions.cs, Program.Services.cs Replaced usage of IsAllowedOrigin with IsTrustedOrigin for origin validation logic.
Program.Middlewares.cs (Server & Web) Merged TrustedOrigins into AllowedHosts for forwarded headers; updated logic for applying middleware.
ServerWebSettings.cs Added new public property TrustedOrigins with documentation.
appsettings.json Replaced AllowedHosts with TrustedOrigins for CORS and Web Auth; repositioned config keys and added comments.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ServerApi
    participant Settings

    Client->>ServerApi: Sends request with Origin header
    ServerApi->>Settings: Calls IsTrustedOrigin(origin)
    Settings-->>ServerApi: Returns true/false
    alt Origin is trusted
        ServerApi-->>Client: Process request as valid
    else Origin is not trusted
        ServerApi-->>Client: Return BadRequestException
    end
Loading

Poem

In the warren of code, a change hops through,
Trusted origins now guide what requests can do.
CORS and headers, all neat and aligned,
Security and clarity, perfectly combined.
With settings updated and logic refined,
This bunny’s heart is quite reassigned! 🥕


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

Fix merging of trusted origins into forwarded headers allowed hosts and introduce TrustedOrigins setting for CORS, social sign-in redirect URLs, and forwarded headers.

  • Add TrustedOrigins array and documentation to both Web and API settings.
  • Update middleware configuration to include TrustedOrigins in ForwardedHeadersOptions.AllowedHosts.
  • Rename IsAllowedOrigin to IsTrustedOrigin and update all references.
  • Adjust appsettings.json to replace top-level AllowedHosts with TrustedOrigins.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
appsettings.json Replaced top-level AllowedHosts with TrustedOrigins, moved ResponseCaching and AllowedHosts entries.
ServerWebSettings.cs Added TrustedOrigins property with XML doc comment.
Program.Middlewares.cs (Web) Merge TrustedOrigins into ForwardedHeadersOptions.AllowedHosts and adjust conditional UseForwardedHeaders.
ServerApiSettings.cs Moved TrustedOrigins definition, renamed IsAllowedOrigin to IsTrustedOrigin.
Program.Services.cs Updated CORS policy to call settings.IsTrustedOrigin.
Program.Middlewares.cs (API) Same merge of TrustedOrigins for API forwarded headers.
HttpRequestExtensions.cs Changed origin check to use settings.IsTrustedOrigin.
Comments suppressed due to low confidence (2)

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/ServerWebSettings.cs:14

  • [nitpick] Summary for TrustedOrigins conflates multiple responsibilities (CORS, social sign-in URLs, forwarded headers). Consider splitting documentation or clarifying this property’s single responsibility.
/// Specifies the allowed origins for CORS requests, URLs returned after social sign-in and email confirmation, and permitted origins for Web Auth, as well as forwarded headers middleware in ASP.NET Core.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs:34

  • Consider adding unit or integration tests to cover merging of TrustedOrigins into ForwardedHeadersOptions.AllowedHosts and verifying UseForwardedHeaders behavior under different environments.
var forwardedHeadersOptions = settings.ForwardedHeaders;

ysmoradi and others added 6 commits June 4, 2025 22:00
…te.Server.Web/Program.Middlewares.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Yaser Moradi <ysmoradi@outlook.com>
…te.Server.Api/Program.Middlewares.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Yaser Moradi <ysmoradi@outlook.com>
Signed-off-by: Yaser Moradi <ysmoradi@outlook.com>
Signed-off-by: Yaser Moradi <ysmoradi@outlook.com>
Signed-off-by: Yaser Moradi <ysmoradi@outlook.com>
@ysmoradi ysmoradi merged commit fea8102 into bitfoundation:develop Jun 5, 2025
3 checks passed
@ysmoradi ysmoradi deleted the 10916 branch June 5, 2025 08:06
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