Skip to content

Allow preflight requests for cloud template endpoints#1709

Merged
MarceloRGonc merged 19 commits intomainfrom
mg/cors
Dec 4, 2025
Merged

Allow preflight requests for cloud template endpoints#1709
MarceloRGonc merged 19 commits intomainfrom
mg/cors

Conversation

@MarceloRGonc
Copy link
Copy Markdown
Contributor

@MarceloRGonc MarceloRGonc commented Dec 2, 2025

Fixes OPS-3165.

image

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 2, 2025

Important

Review skipped

Auto 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.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mg/cors

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

Comment thread packages/server/api/src/app/user-info/user-info.module.ts Fixed
@linear
Copy link
Copy Markdown

linear Bot commented Dec 2, 2025

@MarceloRGonc MarceloRGonc changed the title Doing some cors tests Bypass CORS plugin for cloud template endpoints Dec 2, 2025
@MarceloRGonc MarceloRGonc marked this pull request as ready for review December 2, 2025 15:35
Copilot AI review requested due to automatic review settings December 2, 2025 15:35
Copy link
Copy Markdown
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

This PR disables CORS handling for cloud template endpoints and user info endpoints by adding cors: false configuration. The changes ensure that these publicly accessible endpoints bypass the default CORS plugin, likely to allow direct access from various origins without preflight request complications.

Key Changes

  • Added cors: false configuration to cloud template endpoints (list and get by slug)
  • Added cors: false configuration to user info endpoint

Reviewed changes

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

File Description
packages/server/api/src/app/flow-template/cloud-template.controller.ts Disables CORS for two cloud template endpoints that already skip authentication
packages/server/api/src/app/user-info/user-info.module.ts Disables CORS for user info endpoint that already skips authentication

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

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Dec 2, 2025

Greptile Overview

Greptile Summary

Added cors: false configuration to three endpoints (cloud-template.controller.ts:35, cloud-template.controller.ts:77, user-info.module.ts:33) to bypass CORS plugin for cloud template and user info routes.

Critical Issue: The cors property is not defined in the FastifyContextConfig interface (packages/server/api/types/fastify.d.ts:22) and no handler in the codebase checks for config.cors. This means these changes will have no effect - the global @fastify/cors plugin registered in packages/server/api/src/app/app.ts:140 will still process these routes.

The routes already use allowAllOriginsHookHandler (line 27 in both files) which manually sets CORS headers for all origins. To bypass the CORS plugin, you need to either:

  1. Add the cors property to FastifyContextConfig type definition and implement a handler (similar to the bypassCorsPlugin approach from commit a619a57)
  2. Use a different mechanism to exclude these routes from the CORS plugin

Confidence Score: 0/5

  • This PR cannot achieve its intended purpose and should not be merged
  • The cors: false configuration has no implementation - it's not defined in the type system and no handler reads this property. The changes are effectively dead code that won't bypass the CORS plugin as intended. This means OPS-3165 will not be fixed by this PR.
  • All files need attention - the implementation is incomplete. Additionally, packages/server/api/types/fastify.d.ts and packages/server/api/src/app/app.ts need modifications to implement the cors config handling.

Important Files Changed

File Analysis

Filename Score Overview
packages/server/api/src/app/flow-template/cloud-template.controller.ts 1/5 Added cors: false config to two endpoints, but this property is not defined in types and has no handler implementation
packages/server/api/src/app/user-info/user-info.module.ts 1/5 Added cors: false config to endpoint, but this property is not defined in types and has no handler implementation

Sequence Diagram

sequenceDiagram
    participant Client
    participant Fastify
    participant CORSPlugin as @fastify/cors Plugin
    participant OnRequestHook as allowAllOriginsHookHandler
    participant Route as Cloud Template Route

    Client->>Fastify: GET /v1/cloud-templates
    Note over Fastify: Check route config {cors: false}
    Note over Fastify: ⚠️ No handler reads config.cors
    Fastify->>CORSPlugin: Process CORS (lines 140-165 in app.ts)
    CORSPlugin->>CORSPlugin: Check origin against allowed list
    Note over CORSPlugin: Will reject if not in allowed domains
    Fastify->>OnRequestHook: Execute hook (line 27 in controller)
    OnRequestHook->>OnRequestHook: Set Access-Control-Allow-Origin: *
    Note over OnRequestHook: Manually adds CORS headers
    Fastify->>Route: Execute route handler
    Route-->>Client: Response with conflicting CORS headers
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment thread packages/server/api/src/app/flow-template/cloud-template.controller.ts Outdated
Comment thread packages/server/api/src/app/flow-template/cloud-template.controller.ts Outdated
Comment thread packages/server/api/src/app/user-info/user-info.module.ts Outdated
Comment thread packages/server/api/src/app/user-info/user-info.module.ts Fixed
@MarceloRGonc MarceloRGonc changed the title Bypass CORS plugin for cloud template endpoints Allow preflight requests for cloud template endpoints Dec 2, 2025
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 4, 2025

@MarceloRGonc MarceloRGonc merged commit 63804fb into main Dec 4, 2025
24 checks passed
@MarceloRGonc MarceloRGonc deleted the mg/cors branch December 4, 2025 09:03
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.

3 participants