Skip to content

fix(security): Add VLLM_MAX_N_SEQUENCES environment variable and enforce limit#37952

Merged
russellb merged 3 commits intovllm-project:mainfrom
jperezdealgaba:fix/max-n-sequences-limit
Mar 27, 2026
Merged

fix(security): Add VLLM_MAX_N_SEQUENCES environment variable and enforce limit#37952
russellb merged 3 commits intovllm-project:mainfrom
jperezdealgaba:fix/max-n-sequences-limit

Conversation

@jperezdealgaba
Copy link
Copy Markdown
Contributor

MR assissted with: claude-4.6-opus.max
This commit introduces a new environment variable, VLLM_MAX_N_SEQUENCES, which sets the maximum allowed number of output sequences per request to prevent excessive resource consumption. The SamplingParams class has been updated to validate the 'n' parameter against this new limit, raising an error if exceeded.

Purpose
The goal of this MR is to introduce the VLLM_MAX_N_SEQUENCES environment variable to prevent highly large n sequences blocking the main thread and causing denial of service attacks.

Test Plan
We added tests for making sure the upper limits works. To test it:

python -m pytest tests/test_envs.py::TestVllmMaxNSequences

Test Result
=============================== warnings summary ===============================
:488
:488: DeprecationWarning: builtin type SwigPyPacked has no module attribute

:488
:488: DeprecationWarning: builtin type SwigPyObject has no module attribute

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================== 50 passed, 2 warnings in 4.92s ========================

@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 24, 2026

Documentation preview: https://vllm--37952.org.readthedocs.build/en/37952/

@mergify mergify bot added the documentation Improvements or additions to documentation label Mar 24, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a security enhancement by adding the VLLM_MAX_N_SEQUENCES environment variable to limit the number of sequences per request, preventing potential resource exhaustion attacks. The changes include updates to SamplingParams to enforce this limit, corresponding documentation, and new tests.

My review found an issue in the newly added tests. The tests do not correctly handle the caching mechanism of vllm.envs, which could lead to flaky and unreliable test results. I've provided a suggestion to fix this to ensure test isolation and correctness.

@jperezdealgaba jperezdealgaba force-pushed the fix/max-n-sequences-limit branch from 9953ff7 to 81a735e Compare March 24, 2026 03:11
Signed-off-by: jperezde <jperezde@redhat.com>
@jperezdealgaba jperezdealgaba force-pushed the fix/max-n-sequences-limit branch from c66562d to af70c62 Compare March 24, 2026 03:19
@russellb russellb added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 24, 2026
@mergify
Copy link
Copy Markdown

mergify bot commented Mar 24, 2026

Hi @jperezdealgaba, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy failing?
mypy is run differently in CI. If the failure is related to this check, please use the following command to run it locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10

Signed-off-by: Russell Bryant <rbryant@redhat.com>
@jperezdealgaba
Copy link
Copy Markdown
Contributor Author

Is the readthedocs error an error on our side?

ERROR - mkdocstrings: Couldn't load inventory https://psutil.readthedocs.io/en/stable/objects.inv through handler 'python': HTTP Error 404: Not Found

It really doesn't seem the case

Copy link
Copy Markdown
Member

@russellb russellb left a comment

Choose a reason for hiding this comment

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

lgtm, thank you!

@jperezdealgaba
Copy link
Copy Markdown
Contributor Author

Thanks! Will wait for the merge!

@russellb russellb merged commit b111f8a into vllm-project:main Mar 27, 2026
53 checks passed
Monishver11 pushed a commit to Monishver11/vllm that referenced this pull request Mar 27, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Monishver Chandrasekaran <monishverchandrasekaran@gmail.com>
nithinvc pushed a commit to nithinvc/vllm that referenced this pull request Mar 27, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>

Signed-off-by: Nithin Chalapathi <nithin.ch10@gmail.com>
JiantaoXu pushed a commit to JiantaoXu/vllm that referenced this pull request Mar 28, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
vrdn-23 pushed a commit to vrdn-23/vllm that referenced this pull request Mar 30, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Vinay Damodaran <vrdn@hey.com>
benenzhu pushed a commit to benenzhu/vllm that referenced this pull request Mar 31, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: zhutaoyu <zhutaoyu97@gmail.com>
neweyes pushed a commit to neweyes/vllm that referenced this pull request Mar 31, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: neweyes <328719365@qq.com>
EricccYang pushed a commit to EricccYang/vllm that referenced this pull request Apr 1, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: EricccYang <yangyang4991@gmail.com>
bhargav-patel-29 pushed a commit to Bharatgen-Tech/vllm that referenced this pull request Apr 1, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: bhargav-patel-29 <bhargav.patel@tihiitb.org>
liuchenbing2026 pushed a commit to liuchenbing2026/vllm that referenced this pull request Apr 4, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
rishitdholakia13 pushed a commit to rishitdholakia13/vllm that referenced this pull request Apr 7, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: rishitdholakia13 <rishit+github@cohere.com>
puririshi98 pushed a commit to puririshi98/vllm that referenced this pull request Apr 7, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Rishi Puri <riship@nvidia.com>
big-yellow-duck pushed a commit to EmbeddedLLM/vllm that referenced this pull request Apr 8, 2026
…rce limit (vllm-project#37952)

Signed-off-by: jperezde <jperezde@redhat.com>
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants