Skip to content

feat: make output file allow-list and MIME types configurable via env - #412

Open
alfo-dev wants to merge 1 commit into
LibreChat-AI:mainfrom
alfo-dev:main
Open

alfo-dev wants to merge 1 commit into
LibreChat-AI:mainfrom
alfo-dev:main

Conversation

@alfo-dev

Copy link
Copy Markdown

Summary

Output files are only returned from the sandbox if their extension is in the hardcoded SUPPORTED_EXTENSIONS set in api/src/job.ts. Anything else is silently dropped, with no error and no log line. The only way to change the list was to patch the source and rebuild. For example, .mp4 and .mp3 have MIME entries but are not in the allow-list, and operators who want to restrict outputs (for example to text and Office files) have no option short of forking.

This PR lets operators override both lists through environment variables. Defaults are unchanged.

Changes

  • Add CODEAPI_SUPPORTED_EXTENSIONS. Comma- or space-separated, leading dot optional, case-insensitive. When set, it replaces the built-in allow-list. Unset or blank falls back to the built-in list.
  • Add CODEAPI_MIME_TYPES. ext=type pairs, comma- or space-separated (for example .epub=application/epub+zip,mp4=video/mp4). Entries are added to MIME_TYPE_BY_EXTENSION and override existing entries on conflict. Malformed pairs are skipped.
  • Add two small helpers, parseEnvExtensions and parseEnvMimeTypes, each placed directly above the constant it feeds.
  • Document both variables in env.example, with defaults copied from the current built-in values.

isSupportedOutputFilename and mimeTypeFor are untouched. All three call sites of the filter pick up the change automatically.

Why two variables

The allow-list and the MIME map are independent. An extension that is allowed but has no MIME entry is still delivered, but as application/octet-stream. Many built-in extensions (.rtf, .scss, .tex, .json5, and others) already behave this way. Making the MIME map configurable means anything added to the allow-list can be given a correct type.

Behavior notes

  • Default behavior is unchanged when neither variable is set.
  • Both variables are read once at startup, so a restart is needed after changing them. They must be set on the container that runs job.ts (the worker).
  • CODEAPI_SUPPORTED_EXTENSIONS is a full replacement, not a merge. Archive extensions (.zip, .tar, and so on) should be left out when restricting file types, since they let sandbox code bypass the filter.
  • Entries are not validated. An invalid entry such as *.bad is kept as written and never matches a file.
  • The defaults in env.example match the built-ins today. Copying them into a .env pins the list, so later additions to the built-in list will not apply unless the variable is removed or updated.

Testing

  • Ran both parsing helpers in isolation, covering: unset and blank input, mixed case, optional leading dot, separators, malformed pairs, and an override of an existing MIME entry.
  • Not yet done: a full compile and an end-to-end run in Docker.

Suggested manual check: set CODEAPI_SUPPORTED_EXTENSIONS=.txt .docx, write a.txt, b.docx, c.png, and d.py to /mnt/data, and confirm that only a.txt and b.docx are returned.

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.

1 participant