Skip to content

fix: normalize MIME type to lowercase before upload validation#7147

Open
deepak0x wants to merge 2 commits intoRocketChat:developfrom
deepak0x:fix/case-insensitive-mime-type-validation
Open

fix: normalize MIME type to lowercase before upload validation#7147
deepak0x wants to merge 2 commits intoRocketChat:developfrom
deepak0x:fix/case-insensitive-mime-type-validation

Conversation

@deepak0x
Copy link
Copy Markdown
Contributor

@deepak0x deepak0x commented Apr 13, 2026

File uploads fail when the phone language is set to Turkish. The root cause is the Turkish 'I' problem — in Turkish locale, 'I'.toLowerCase() returns 'ı' (dotless i) instead of 'i', and MIME types returned by the OS can have unexpected casing. The canUploadFile function in media.ts compares MIME types case-sensitively against the server's allowlist, so a MIME type like 'IMAGE/JPEG' won't match 'image/jpeg' and the upload gets rejected as an invalid file type.

Added .toLowerCase() on the file's MIME type before both the exact match and wildcard match comparisons.

Issue(s)

Closes #3040

How to test or reproduce

  1. Set the device language to Turkish
  2. Try uploading a photo or video in any chat
  3. Before fix: "invalid file type" error, upload blocked
  4. After fix: upload works normally

Screenshots

N/A — validation logic change, no UI impact.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Bug Fixes
    • Improved file upload validation to correctly handle MIME types regardless of letter casing, preventing valid files from being rejected.
    • Fixed matching of wildcard MIME entries (e.g., image/*) so uploads that should be allowed are now recognized consistently.

On devices with Turkish locale, string casing behaves differently —
'I'.toLowerCase() returns 'ı' instead of 'i'. MIME types returned
by the OS can have unexpected casing, which breaks the allowlist
check in canUploadFile and blocks valid file uploads.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

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: 09cedfe4-3a35-4fd3-9940-5245c5cbf952

📥 Commits

Reviewing files that changed from the base of the PR and between 3e2e795 and 2067983.

📒 Files selected for processing (1)
  • app/lib/methods/helpers/media.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/lib/methods/helpers/media.ts

Walkthrough

canUploadFile now normalizes MIME types to lowercase before comparing against allow-list entries and wildcard patterns, making MIME checks case-insensitive.

Changes

Cohort / File(s) Summary
MIME-type validation
app/lib/methods/helpers/media.ts
Normalize file.mime to lowercase (.toLowerCase()) for direct allow-list checks and wildcard (type/*) comparisons; replaced raw file.mime comparisons with guarded, lowercase comparisons.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 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 and concisely describes the main change: normalizing MIME types to lowercase for upload validation, which directly addresses the Turkish locale issue.
Linked Issues check ✅ Passed The code change directly addresses issue #3040 by normalizing MIME types to lowercase before comparison, making validation locale-independent and resilient to Turkish locale casing issues.
Out of Scope Changes check ✅ Passed The changes are limited to MIME type normalization in the canUploadFile function and remain fully aligned with the stated objective to fix Turkish locale upload failures.
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.


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/lib/methods/helpers/media.ts`:
- Around line 28-33: The code dangerously uses file.mime! without a runtime
guard; normalize the MIME once into a local variable (e.g., const normalizedMime
= file.mime?.toLowerCase().trim()) and use that for all checks in the helper
(replace the non-null assertion in the allowedMime includes check and the
wildCards comparison), early-return failure if normalizedMime is falsy, compute
wildCards from allowedMime as before and compare using
normalizedMime.replace(/(\/.*)$/, wildCardGlob) for the wildcard match; update
the logic in the helper so both the direct includes and wildcard check use
normalizedMime and never dereference file.mime directly.
🪄 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: aa1356ad-a246-4e82-99d3-94d557efbef8

📥 Commits

Reviewing files that changed from the base of the PR and between e3bb5e8 and 3e2e795.

📒 Files selected for processing (1)
  • app/lib/methods/helpers/media.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (CLAUDE.md)

Configure Prettier with tabs, single quotes, 130 character width, no trailing commas, arrow parens avoid, and bracket same line

Files:

  • app/lib/methods/helpers/media.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use ESLint with @rocket.chat/eslint-config base configuration including React, React Native, TypeScript, and Jest plugins

Files:

  • app/lib/methods/helpers/media.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use TypeScript with strict mode enabled and configure baseUrl to app/ for import resolution

**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers

Files:

  • app/lib/methods/helpers/media.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions

Files:

  • app/lib/methods/helpers/media.ts

Comment thread app/lib/methods/helpers/media.ts Outdated
Extracted file.mime?.toLowerCase() into a normalizedMime variable
to avoid the unsafe non-null assertion on the optional mime property
and reuse the normalized value for both the exact and wildcard checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upload not working when phone language set to Turkish

1 participant