Skip to content

Conversation

@sampaiodiego
Copy link
Member

@sampaiodiego sampaiodiego commented May 26, 2025

This pull request addresses an issue with CORS (Cross-Origin Resource Sharing) headers not being properly sent for GET requests in the Rocket.Chat API. It includes changes to the middleware logic and updates to the associated test cases to reflect the new behavior.

Fixes and Enhancements to CORS Handling:

Test Updates for CORS Behavior:

  • apps/meteor/app/api/server/middlewares/cors.spec.ts:
    • Modified test descriptions and assertions to validate that the Access-Control-Allow-Origin header is included for GET requests, both when CORS is enabled and disabled. [1] [2] [3]

Proposed changes (including videos or screenshots)

Issue(s)

Fix #36054

Steps to test or reproduce

Further comments

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented May 26, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented May 26, 2025

🦋 Changeset detected

Latest commit: b87939a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sampaiodiego sampaiodiego changed the base branch from develop to release-7.7.0 May 26, 2025 22:40
@sampaiodiego sampaiodiego added this to the 7.7.0 milestone May 26, 2025
@github-actions
Copy link
Contributor

github-actions bot commented May 26, 2025

PR Preview Action v1.6.1

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-36085/

Built to branch gh-pages at 2025-05-27 16:23 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov
Copy link

codecov bot commented May 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.75%. Comparing base (93eb903) to head (b87939a).
Report is 2 commits behind head on release-7.7.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-7.7.0   #36085      +/-   ##
=================================================
+ Coverage          64.20%   64.75%   +0.55%     
=================================================
  Files               3018     3110      +92     
  Lines              91839    93196    +1357     
  Branches           17433    17741     +308     
=================================================
+ Hits               58967    60351    +1384     
+ Misses             30185    30057     -128     
- Partials            2687     2788     +101     
Flag Coverage Δ
e2e 58.41% <ø> (+1.74%) ⬆️
unit 71.52% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo ggazzo marked this pull request as ready for review May 27, 2025 15:54
Copilot AI review requested due to automatic review settings May 27, 2025 15:54
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@ggazzo ggazzo requested a review from Copilot May 27, 2025 15:56
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

This PR fixes the issue with CORS headers not being correctly sent for GET requests in the Rocket.Chat API. It ensures that the Access-Control-Allow-Origin header is always set to "*" for GET requests and updates the test cases to validate this behavior.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/meteor/app/api/server/middlewares/cors.ts Removes the conditional check and now always sets the allow-origin header for GET requests.
apps/meteor/app/api/server/middlewares/cors.spec.ts Updates test cases to expect the Access-Control-Allow-Origin header and remove expectations for other CORS headers.
.changeset/fuzzy-bottles-unite.md Updates changeset documentation to reflect the fix for GET CORS headers.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ggazzo ggazzo requested a review from Copilot May 27, 2025 15:57
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

This PR fixes an issue with CORS headers for GET requests in the Rocket.Chat API by always setting the Access-Control-Allow-Origin header to "*" regardless of the CORS settings.

  • Updated the CORS middleware to always send the allow-origin header for GET requests.
  • Modified test cases to validate that the allow-origin header is always present for GET requests, and removed assertions for other CORS headers.
  • Added a changeset file for the patch release.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/meteor/app/api/server/middlewares/cors.ts Updated middleware to always set the Access-Control-Allow-Origin header for GET requests.
apps/meteor/app/api/server/middlewares/cors.spec.ts Revised tests reflecting the new CORS header behavior for GET requests.
.changeset/fuzzy-bottles-unite.md Included changeset documentation for the patch update.

res.headers.set('Access-Control-Allow-Methods', defaultHeaders['Access-Control-Allow-Methods']);
res.headers.set('Access-Control-Allow-Headers', defaultHeaders['Access-Control-Allow-Headers']);
}
res.headers.set('Access-Control-Allow-Origin', '*');
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Consider adding an inline comment explaining that the Access-Control-Allow-Origin header is always set for GET requests, clarifying that this behavior is intentional as part of the fix.

Copilot uses AI. Check for mistakes.
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label May 27, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label May 27, 2025
@ggazzo ggazzo merged commit 2f38213 into release-7.7.0 May 27, 2025
44 checks passed
@ggazzo ggazzo deleted the fix-cors-headers branch May 27, 2025 17:42
@sampaiodiego
Copy link
Member Author

/backport 7.6.3

dionisio-bot bot pushed a commit that referenced this pull request Jun 3, 2025
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jun 3, 2025

Pull request #36139 added to Project: "Patch 7.6.3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

From v7.6.0: Client request via REST API - CORS Missing Allow Origin responds

3 participants