Skip to content

🚦 fix: Add Rate Limiting to Conversation Duplicate Endpoint#12218

Merged
danny-avila merged 5 commits into
devfrom
fix/sec-convos-ratelimit
Mar 14, 2026
Merged

🚦 fix: Add Rate Limiting to Conversation Duplicate Endpoint#12218
danny-avila merged 5 commits into
devfrom
fix/sec-convos-ratelimit

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

No description provided.

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

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 rate limiting to the conversation “duplicate” endpoint to align it with the existing “fork” protections and prevent abuse.

Changes:

  • Apply existing forkIpLimiter and forkUserLimiter middleware to POST /api/convos/duplicate.
  • Add a Jest/Supertest suite to verify duplicate-route rate limiting behavior (429 after exceeding limits).

Reviewed changes

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

File Description
api/server/routes/convos.js Adds fork IP/user rate limiting middleware to the /duplicate route.
api/server/routes/__tests__/convos-duplicate-ratelimit.spec.js Introduces tests asserting rate limiting is active and enforced on /duplicate.

💡 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.

@@ -280,7 +280,7 @@ router.post('/fork', forkIpLimiter, forkUserLimiter, async (req, res) => {
}
});

router.post('/duplicate', async (req, res) => {
router.post('/duplicate', forkIpLimiter, forkUserLimiter, async (req, res) => {
Comment on lines +3 to +8

process.env.FORK_USER_MAX = '2';
process.env.FORK_USER_WINDOW = '1';
process.env.FORK_IP_MAX = '100';
process.env.FORK_IP_WINDOW = '1';

Comment on lines +131 to +140
it('should have rate limiting middleware on the /duplicate route', () => {
const convosRouter = require('../convos');
const duplicateLayer = convosRouter.stack.find(
(layer) => layer.route?.path === '/duplicate' && layer.route?.methods?.post,
);

expect(duplicateLayer).toBeDefined();
expect(duplicateLayer.route.stack.length).toBeGreaterThanOrEqual(3);
});

@danny-avila
danny-avila force-pushed the fix/sec-convos-ratelimit branch from 2fcc476 to 0881320 Compare March 14, 2026 01:57
- Consolidated mock implementations into a dedicated `convos-route-mocks.js` file to enhance maintainability and readability of test files.
- Updated tests in `convos-duplicate-ratelimit.spec.js` and `convos.spec.js` to utilize the new mock structure, improving clarity and reducing redundancy.
- Enhanced the `duplicateConversation` function to accept an optional title parameter for better flexibility in conversation duplication.
@danny-avila danny-avila changed the title fix: add rate limiting to conversation duplicate endpoint 🚦 fix: Add Rate Limiting to Conversation Duplicate Endpoint Mar 14, 2026
@danny-avila
danny-avila merged commit ca79a03 into dev Mar 14, 2026
9 checks passed
@danny-avila
danny-avila deleted the fix/sec-convos-ratelimit branch March 14, 2026 03:40
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
…ila#12218)

* fix: add rate limiting to conversation duplicate endpoint

* chore: linter

* fix: address review findings for conversation duplicate rate limiting

* refactor: streamline test mocks for conversation routes

- Consolidated mock implementations into a dedicated `convos-route-mocks.js` file to enhance maintainability and readability of test files.
- Updated tests in `convos-duplicate-ratelimit.spec.js` and `convos.spec.js` to utilize the new mock structure, improving clarity and reducing redundancy.
- Enhanced the `duplicateConversation` function to accept an optional title parameter for better flexibility in conversation duplication.

* chore: rename files
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
…ila#12218)

* fix: add rate limiting to conversation duplicate endpoint

* chore: linter

* fix: address review findings for conversation duplicate rate limiting

* refactor: streamline test mocks for conversation routes

- Consolidated mock implementations into a dedicated `convos-route-mocks.js` file to enhance maintainability and readability of test files.
- Updated tests in `convos-duplicate-ratelimit.spec.js` and `convos.spec.js` to utilize the new mock structure, improving clarity and reducing redundancy.
- Enhanced the `duplicateConversation` function to accept an optional title parameter for better flexibility in conversation duplication.

* chore: rename files
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