Skip to content

📏 refactor: Add File Size Limits to Conversation Imports#12221

Merged
danny-avila merged 10 commits into
devfrom
fix/sec-multer-import
Mar 14, 2026
Merged

📏 refactor: Add File Size Limits to Conversation Imports#12221
danny-avila merged 10 commits into
devfrom
fix/sec-multer-import

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 14, 2026 01:57

Copilot AI 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.

Pull request overview

Adds a configurable file-size cap for conversation JSON imports to prevent oversized uploads from being accepted/processed.

Changes:

  • Add a default max import size (250 MiB) and parse CONVERSATION_IMPORT_MAX_FILE_SIZE_BYTES for server-side import size checks.
  • Configure the /api/convos/import multer instance with limits.fileSize.
  • Add a new Jest spec covering max-size resolution and multer behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
api/server/utils/import/importConversations.js Adds default + env-based max-size enforcement before reading/parsing import files.
api/server/routes/convos.js Adds multer limits.fileSize for the conversation import upload middleware.
api/server/routes/tests/convos-import.spec.js Introduces tests around max-size resolution and multer file-size rejection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread api/server/utils/import/importConversations.js Outdated
Comment thread api/server/routes/convos.js Outdated
Comment thread api/server/routes/convos.js
Comment thread api/server/routes/__tests__/convos-import.spec.js Outdated
Comment thread api/server/routes/__tests__/convos-import.spec.js Outdated
…eMapper

The global @librechat/data-schemas mock in jest.config.js only provided
logger, breaking all tests that depend on createModels from the same
package. Replace with a virtual jest.mock scoped to the import spec file.
New backend logic belongs in packages/api as TypeScript. Delete the
api/server/utils/import/limits.js wrapper and import directly from
@librechat/api in convos.js and importConversations.js. Resolver unit
tests move to packages/api; the api/ spec retains only multer behavior
tests.
Update typeof import path from '../importLimits' to '../import' after
the rename. Clear mockLogger.warn in beforeEach to prevent cross-test
accumulation.
@danny-avila danny-avila changed the title fix: add file size limits to conversation import multer instance 📏 refactor: Add File Size Limits to Conversation Imports Mar 14, 2026
@danny-avila danny-avila force-pushed the fix/sec-multer-import branch from 6c83812 to dd25085 Compare March 14, 2026 06:25
jest.mock factories are hoisted above const declarations, so the
mockLogger reference was undefined at factory evaluation time. Use a
direct import of the mocked logger module instead.
@danny-avila danny-avila force-pushed the fix/sec-multer-import branch from 4720220 to 98fd582 Compare March 14, 2026 06:39
virtual: true prevents the mock from intercepting the real module in
CI where @librechat/data-schemas is built, causing import.ts to use
the real logger while the test asserts against the mock.
@danny-avila danny-avila merged commit 35a35dc into dev Mar 14, 2026
9 checks passed
@danny-avila danny-avila deleted the fix/sec-multer-import branch March 14, 2026 07:06
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
…#12221)

* fix: add file size limits to conversation import multer instance

* fix: address review findings for conversation import file size limits

* fix: use local jest.mock for data-schemas instead of global moduleNameMapper

The global @librechat/data-schemas mock in jest.config.js only provided
logger, breaking all tests that depend on createModels from the same
package. Replace with a virtual jest.mock scoped to the import spec file.

* fix: move import to top of file, pre-compute upload middleware, assert logger.warn in tests

* refactor: move resolveImportMaxFileSize to packages/api

New backend logic belongs in packages/api as TypeScript. Delete the
api/server/utils/import/limits.js wrapper and import directly from
@librechat/api in convos.js and importConversations.js. Resolver unit
tests move to packages/api; the api/ spec retains only multer behavior
tests.

* chore: rename importLimits to import

* fix: stale type reference and mock isolation in import tests

Update typeof import path from '../importLimits' to '../import' after
the rename. Clear mockLogger.warn in beforeEach to prevent cross-test
accumulation.

* fix: add resolveImportMaxFileSize to @librechat/api mock in convos.spec.js

* fix: resolve jest.mock hoisting issue in import tests

jest.mock factories are hoisted above const declarations, so the
mockLogger reference was undefined at factory evaluation time. Use a
direct import of the mocked logger module instead.

* fix: remove virtual flag from data-schemas mock for CI compatibility

virtual: true prevents the mock from intercepting the real module in
CI where @librechat/data-schemas is built, causing import.ts to use
the real logger while the test asserts against the mock.
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.

2 participants