Skip to content

regression: prevent S3 region empty string from blocking env var fallback - #39711

Merged
dionisio-bot[bot] merged 1 commit into
developfrom
fix/s3-region-empty-string
Mar 18, 2026
Merged

regression: prevent S3 region empty string from blocking env var fallback#39711
dionisio-bot[bot] merged 1 commit into
developfrom
fix/s3-region-empty-string

Conversation

@ricardogarim

@ricardogarim ricardogarim commented Mar 18, 2026

Copy link
Copy Markdown
Member

This PR fixes a regression introduced in #36659 (AWS SDK v3 upgrade) where users configuring S3 file storage without explicitly setting a region in Rocket.Chat settings would see an uncaught exception:

UnCaughtException
Error: Region is missing
    at Object.resolveRegionConfig (@smithy/config-resolver/dist-cjs/index.js:103:15)
    at new S3Client (@aws-sdk/client-s3/dist-cjs/index.js:128:42)
    at new AmazonS3Store (app/file-upload/ufs/AmazonS3/server.ts:59:14)

Root cause

The FileUpload_S3_Region setting defaults to an empty string (''). Previously, AWS SDK v2 handled this gracefully by defaulting to us-east-1:

if (!this.config.region) this.config.region = 'us-east-1';

However, AWS SDK v3 throws an error when region is falsy:

if (!region) {
    throw new Error("Region is missing");
}

The key difference is that SDK v3 still accepts undefined (falling back to AWS_REGION env var), but rejects empty string ''.

Proposed changes (including videos or screenshots)

Align region handling with the existing pattern used for credentials and endpoint - only pass to SDK when value is truthy. This allows users to either:

  • Set region via Rocket.Chat admin settings
  • Use AWS_REGION environment variable (SDK fallback)

Issue(s)

Steps to test or reproduce

Before fix:

  1. Configure S3 storage in Admin > File Upload > Storage Type > Amazon S3
  2. Set Bucket name but leave Region empty
  3. Set AWS_REGION=us-east-1 environment variable
  4. Upload a file
  5. See "Region is missing" error in console

After fix:

  1. Same setup as above
  2. Upload a file
  3. File uploads successfully using AWS_REGION from environment

Further comments

Didn’t add a changeset since the fix is within the same release window as the bug that introduced it.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced AWS S3 region configuration handling to conditionally apply region settings, providing better flexibility in file upload setup.

@dionisio-bot

dionisio-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

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

@changeset-bot

changeset-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7073215

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b3ab71c3-ba3d-418c-a231-acbfb2e970e8

📥 Commits

Reviewing files that changed from the base of the PR and between eb1cd8f and 7073215.

📒 Files selected for processing (1)
  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/file-upload/server/config/AmazonS3.ts
🔇 Additional comments (1)
apps/meteor/app/file-upload/server/config/AmazonS3.ts (1)

93-95: Conditionally setting region here is the correct fix.

Good change. Not passing config.connection.region when the setting is '' prevents the AWS SDK v3 “Region is missing” failure and preserves AWS_REGION fallback behavior.


Walkthrough

The Amazon S3 configuration file was refactored to conditionally assign the region property only when a Region value is provided, rather than unconditionally including it in the connection configuration.

Changes

Cohort / File(s) Summary
AWS S3 Configuration
apps/meteor/app/file-upload/server/config/AmazonS3.ts
Region setting changed from unconditional static config to conditional assignment that only appends region to connection when Region has a truthy value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: preventing an empty S3 region string from blocking environment variable fallback, which directly addresses the regression in the changeset.
Linked Issues check ✅ Passed The PR addresses the AWS SDK v3 upgrade objective by fixing a regression in region handling that arose from the v2-to-v3 migration, ensuring compatibility and correcting SDK upgrade-related issues.
Out of Scope Changes check ✅ Passed The change is narrowly focused on fixing S3 region configuration handling in AmazonS3.ts, which is directly scoped to resolving the AWS SDK v3 upgrade regression without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@codecov

codecov Bot commented Mar 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.86%. Comparing base (4f88165) to head (7073215).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #39711      +/-   ##
===========================================
- Coverage    70.91%   70.86%   -0.06%     
===========================================
  Files         3209     3209              
  Lines       113893   113893              
  Branches     20689    20636      -53     
===========================================
- Hits         80765    80708      -57     
- Misses       31071    31129      +58     
+ Partials      2057     2056       -1     
Flag Coverage Δ
e2e 60.36% <ø> (-0.05%) ⬇️
e2e-api 48.17% <ø> (-0.06%) ⬇️
unit 71.53% <ø> (-0.06%) ⬇️

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.

@ricardogarim ricardogarim added this to the 8.3.0 milestone Mar 18, 2026
@ricardogarim
ricardogarim marked this pull request as ready for review March 18, 2026 16:48
@ricardogarim
ricardogarim requested a review from a team as a code owner March 18, 2026 16:48
@ricardogarim ricardogarim changed the title fix: prevent S3 region empty string from blocking env var fallback regression: prevent S3 region empty string from blocking env var fallback Mar 18, 2026

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 1 file

@KevLehman

Copy link
Copy Markdown
Member

is there any way to test this?

@ricardogarim ricardogarim added the stat: QA assured Means it has been tested and approved by a company insider label Mar 18, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Mar 18, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Mar 18, 2026
Merged via the queue into develop with commit 9d78ba3 Mar 18, 2026
46 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/s3-region-empty-string branch March 18, 2026 18:10
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 type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants