Skip to content

feat: make TEXT_MIME_ALLOWLIST configurable via env var - #2511

Open
revanth-045 wants to merge 3 commits into
huggingface:mainfrom
revanth-045:fix/text-mime-allowlist-env-var
Open

feat: make TEXT_MIME_ALLOWLIST configurable via env var#2511
revanth-045 wants to merge 3 commits into
huggingface:mainfrom
revanth-045:fix/text-mime-allowlist-env-var

Conversation

@revanth-045

@revanth-045 revanth-045 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

TEXT_MIME_ALLOWLIST in src/lib/constants/mime.ts is hardcoded, so self-hosting this means forking the repo just to accept one extra file type — dropping in a .py or .yaml file currently fails with "Some file type not supported".

This adds an optional PUBLIC_TEXT_MIME_ALLOWLIST env var: a comma-separated list of MIME types or patterns that gets appended to the existing defaults (kept as TEXT_MIME_ALLOWLIST_DEFAULT).

PUBLIC_TEXT_MIME_ALLOWLIST=text/x-typescript,text/x-python

It ships empty, and when it's unset the allowlist is exactly what it is today, so nothing changes for existing deployments. Documented in .env.

Happy to flip it to replace-instead-of-append, or rename the variable, if you'd rather have it work differently — the issue left that open.

This should be complementary to #2189 rather than overlapping with it: that one lets an individual model declare the mimetypes it accepts, whereas this is a deployment-wide default for what counts as a text file in the first place.

Closes #2194

Checks

npm run check, npm run lint and npm run build all pass. Added src/lib/constants/mime.spec.ts covering the unset/empty fallback, appending, whitespace handling and wildcard patterns.

One known limitation

.ts uploads work when the browser reports a sensible MIME type, but some OS/browser combinations report .ts as video/mp2t instead, so those won't be picked up as text even with the type allowlisted. That's a pre-existing MIME-sniffing quirk rather than something this PR introduces — fixing it properly would need content sniffing (one of the alternatives floated in #2194), which felt like a separate change.

…WLIST

Allows self-hosted deployments to extend the default text MIME allowlist
via an env var instead of forking the code. The variable takes a
comma-separated list of MIME types or patterns (e.g. "text/x-typescript")
which is appended to the built-in defaults, so existing behaviour is
unchanged when it is unset.

Closes huggingface#2194

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cbd3ea75d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/lib/constants/mime.ts Outdated
if (!value) return [];
return value
.split(",")
.map((entry) => entry.trim())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize configured MIME types for client matching

When an operator supplies a MIME type with uppercase characters, such as Application/X-Yaml, server processing accepts it because prepareFiles lowercases each allowlist entry, but mimeMatchesAllowlist compares the configured entry and browser-provided file.type case-sensitively. Consequently, drag-and-drop, paste, and programmatic attachments are rejected even though the server considers the type allowed; normalize entries to lowercase while parsing them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed in dd608e4.

Entries are now lowercased in parseExtraMimeTypes, so Application/X-Yaml normalises to application/x-yaml and the client matcher agrees with the server. Added a test covering it.

Worth noting the underlying inconsistency is wider than this PR: mimeMatchesAllowlist lowercases neither side, while prepareFiles and UploadedFile's matchesAllowed both lowercase both sides. Normalising at parse time keeps this PR scoped, but making mimeMatchesAllowlist case-insensitive would be a sensible follow-up.

…he server

`prepareFiles` lowercases each allowlist entry before comparing, but
`mimeMatchesAllowlist` — used by drag-and-drop, paste and programmatic
attachments — compares case-sensitively. An operator writing
`Application/X-Yaml` would have the file accepted server-side and rejected in
the browser. MIME types are case-insensitive, so normalise entries at parse
time.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@revanth-045

Copy link
Copy Markdown
Contributor Author

Addressed the Codex review in dd608e4 — configured MIME types are lowercased at parse time so the case-sensitive client matcher agrees with the server, with a test for it.

npm test (633 tests), npm run check and npm run lint all pass locally. CI here is still sitting at action_required, so the checks have not run — if someone can approve the workflows they should go green the same way they did on #2515.

@revanth-045

Copy link
Copy Markdown
Contributor Author

Checking in — this has been open a few weeks with CI green and the Codex feedback addressed (dd608e4). Happy to make any further changes if there's a preferred direction; let me know if anything's blocking a look.

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.

Make TEXT_MIME_ALLOWLIST configurable via an environment variable

1 participant