fix: file upload signed URL not falling back to default expiry when value is below threshold#40456
Conversation
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: bf0d591 The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 packages
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 |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 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). (3)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
**/*.spec.ts📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (5)📚 Learning: 2026-02-24T19:22:48.358ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-03-06T18:10:15.268ZApplied to files:
📚 Learning: 2026-05-06T12:21:44.083ZApplied to files:
🔇 Additional comments (3)
WalkthroughEnforce a 5-second minimum for signed URL expirations (900s fallback), add shared helper ChangesSigned URL Expiry Enforcement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@apps/meteor/app/file-upload/ufs/AmazonS3/server.ts`:
- Line 25: The inline trailing comment on the constant
S3_FALLBACK_EXPIRY_SECONDS should be removed to comply with coding guidelines;
edit the declaration of S3_FALLBACK_EXPIRY_SECONDS to eliminate the "// 15
minutes" comment and, if needed for clarity, expand the constant name (e.g.,
S3_FALLBACK_EXPIRY_SECONDS_15_MIN) or add a nearby module-level documentation
block (not an inline comment) to explain the value.
In `@apps/meteor/app/file-upload/ufs/GoogleStorage/server.ts`:
- Line 14: Remove the inline comment from the constant declaration for
GCS_FALLBACK_EXPIRY_SECONDS in server.ts; locate the constant named
GCS_FALLBACK_EXPIRY_SECONDS and delete the trailing "// 15 minutes" comment so
the line only declares the constant without any inline comment.
🪄 Autofix (Beta)
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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 683dde9a-613d-4186-a0c8-d3f80dc1efb0
📒 Files selected for processing (6)
.changeset/orange-bottles-glow.mdapps/meteor/app/file-upload/server/config/GoogleStorage.tsapps/meteor/app/file-upload/ufs/AmazonS3/server.tsapps/meteor/app/file-upload/ufs/GoogleStorage/server.tsapps/meteor/server/settings/file-upload.tspackages/i18n/src/locales/en.i18n.json
📜 Review details
🧰 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/GoogleStorage.tsapps/meteor/server/settings/file-upload.tsapps/meteor/app/file-upload/ufs/AmazonS3/server.tsapps/meteor/app/file-upload/ufs/GoogleStorage/server.ts
🧠 Learnings (4)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.
Applied to files:
.changeset/orange-bottles-glow.md
📚 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/GoogleStorage.tsapps/meteor/server/settings/file-upload.tsapps/meteor/app/file-upload/ufs/AmazonS3/server.tsapps/meteor/app/file-upload/ufs/GoogleStorage/server.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/GoogleStorage.tsapps/meteor/server/settings/file-upload.tsapps/meteor/app/file-upload/ufs/AmazonS3/server.tsapps/meteor/app/file-upload/ufs/GoogleStorage/server.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/app/file-upload/server/config/GoogleStorage.tsapps/meteor/server/settings/file-upload.tsapps/meteor/app/file-upload/ufs/AmazonS3/server.tsapps/meteor/app/file-upload/ufs/GoogleStorage/server.ts
🔇 Additional comments (7)
.changeset/orange-bottles-glow.md (1)
1-7: Changeset looks accurate and appropriately scoped.The patch bumps and description match the PR’s bug-fix behavior (expiry fallback + dedicated GCS setting) without overstating impact.
packages/i18n/src/locales/en.i18n.json (1)
2320-2321: Localization updates align with the signed URL expiry fallback behavior.The new GCS keys and updated S3 description clearly communicate the
< 5 seconds => default 15 minutesbehavior and match the PR intent.Also applies to: 2365-2365
apps/meteor/server/settings/file-upload.ts (1)
255-262: LGTM — the new GCS expiry setting is correctly wired.Mirrors the S3 counterpart exactly (
type: 'int', default120,enableQuerytoGoogleCloudStorage,i18nDescription), and falls within thewatchByRegex(/^FileUpload_GoogleStorage_/)watch automatically.apps/meteor/app/file-upload/ufs/GoogleStorage/server.ts (2)
63-70:version: 'v2'withDate.now()millisecond-basedexpiresis correct here.The
responseDispositionfield is known to causeSignatureDoesNotMatcherrors withversion: 'v4'(upstream issue googleapis/nodejs-storage#1073), so pinning to v2 is the right call. This matches a confirmed upstream bug whereresponseDispositioncombined withversion: 'v4'causes signature validation failures, and switching to v2 resolves it. Theexpires: Date.now() + expirySeconds * 1000format (milliseconds since epoch) is also consistent with the official@google-cloud/storagev2 examples.
76-78: LGTM —getUrlExpiryTimeSpanis consistent with the S3 implementation.Returns the configured value when ≥
MIN_URL_EXPIRY_TIME_SPAN_SECONDS, otherwisenull, cleanly signalling "disabled" to callers without affectinggetRedirectURL(which always uses the fallback).apps/meteor/app/file-upload/server/config/GoogleStorage.ts (1)
71-71: LGTM — correct decoupling from the S3 setting key.
FileUpload_GoogleStorage_URLExpiryTimeSpanis covered bywatchByRegex(/^FileUpload_GoogleStorage_/), so the configure callback will fire correctly when this setting changes.apps/meteor/app/file-upload/ufs/AmazonS3/server.ts (1)
88-89: LGTM — floor logic andgetUrlExpiryTimeSpanare correct.
expiresInis passed in seconds to@aws-sdk/s3-request-presigner(which expects seconds), andgetUrlExpiryTimeSpanconsistently returnsnullfor below-threshold values in both providers.Also applies to: 97-97, 210-212
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #40456 +/- ##
===========================================
+ Coverage 69.57% 69.62% +0.04%
===========================================
Files 3317 3328 +11
Lines 121867 122695 +828
Branches 21801 21931 +130
===========================================
+ Hits 84794 85421 +627
- Misses 33740 33927 +187
- Partials 3333 3347 +14
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
you could add unit tests too |
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
In order to prevent heavy mocking, extracted the logic into separate function to implement unit tests. |
Proposed changes (including videos or screenshots)
When
FileUpload_S3_URLExpiryTimeSpanis set to0(or any value below 5), the raw value was passed directly to the signed URL generation, resulting in immediately-expired URLs and 403 errors on file previews (especially on MinIO).This PR:
FileUpload_GoogleStorage_URLExpiryTimeSpansetting for Google Cloud Storage, which was previously (incorrectly) reusing the AWS S3 expiry setting — a setting that wasn't even visible when GCS was the active storage type.v2and passes a fallback expiry when the setting is disabled (sinceexpiresis a required parameter for GCS).Issue(s)
Steps to test or reproduce
FileUpload_S3_URLExpiryTimeSpanto0For Google Cloud Storage:
0— file previews still work (15-minute fallback)120— URLs expire after 2 minutes as expectedFurther comments
SUP-1026
Summary by CodeRabbit
Bug Fixes
New Features
Documentation
Tests