Skip to content

fix: enforce NEW-ENVIRON variable limit across frames to prevent memory exhaustion - #2415

Merged
gnodet merged 2 commits into
jline:masterfrom
gnodet:fix/telnet-environ-limit
Nov 4, 2026
Merged

gnodet merged 2 commits into
jline:masterfrom
gnodet:fix/telnet-environ-limit

Conversation

@gnodet

@gnodet gnodet commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes GHSA-7qh2-r6cc-r47w — Uncontrolled Resource Consumption in org.jline:jline-remote-telnet.

CVE-2026-56740 introduced a per-frame varCount counter capped at NE_VAR_COUNT_MAX (100) in TelnetIO.readNEVariables(). However, the counter reset to 0 on every subnegotiation call, so an attacker could send N frames × 100 variables each and accumulate N×100 entries in the persistent environment map — a complete bypass of the original fix.

Fix

Add a persistent-map size check in addition to the per-frame counter: reject new variable names when env.size() >= NE_VAR_COUNT_MAX and the name is not already present in the map. Updates to existing variable names are still allowed (so a client can legitimately correct a previously-sent value).

Tests

Four regression tests in TelnetIONewEnvLimitTest:

  • Single frame at the limit fills exactly NE_VAR_COUNT_MAX entries
  • Single frame over the limit is truncated (existing per-frame guard)
  • Multi-frame bypass is blocked (the actual regression)
  • Updating an existing variable at capacity succeeds

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Telnet environment variables when many variables are supplied. New variables are limited to 100, while existing variables can still be updated at the limit. Responses that exceed the limit are safely skipped.

@gnodet gnodet added the bug label Nov 4, 2026
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

readNEVariables() now enforces the environment-size limit for new variables while allowing existing variables to be updated at capacity. Regression tests cover both limits and update behavior.

Changes: NEW-ENVIRON variable limits

Layer / File(s) Summary
Enforce limits and verify updates
remote-telnet/src/main/java/org/jline/builtins/telnet/TelnetIO.java, remote-telnet/src/test/java/org/jline/builtins/telnet/TelnetIONewEnvLimitTest.java
readNEVariables() rejects new names when the environment reaches its limit and allows existing names to proceed to value parsing. Tests cover at-limit and oversized frames, distinct names across frames, and updates to existing names at capacity.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to da31b

The reviewed change has no identified issue that needs to be resolved before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: enforcing the NEW-ENVIRON variable limit across frames to prevent memory exhaustion.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bbcb5951-5ace-474c-8d80-892c5c780e88
Commits

Reviewing files that changed from the base of the PR and between e720d5d and da31bf0.

Files selected for processing: 2
  • remote-telnet/src/main/java/org/jline/builtins/telnet/TelnetIO.java
  • remote-telnet/src/test/java/org/jline/builtins/telnet/TelnetIONewEnvLimitTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@gnodet
gnodet merged commit c8ecc11 into jline:master Nov 4, 2026
30 checks passed

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The multi-frame bypass is real and the fix is correct — verified: multiFrameBypassIsBlocked fails without the persistent-map size check (200 entries vs the expected 100 cap), passes with the fix applied. The guard handles all three cases correctly.

One low-severity nit: the test mirrors NE_VAR_COUNT_MAX = 100 as a local constant (line 92) rather than referencing TelnetIO.NE_VAR_COUNT_MAX directly. Since the test is in the same package (org.jline.builtins.telnet), it can reference the protected static final production constant, eliminating the risk of silent divergence if the value is ever changed.

Backport needed: jline-3.x has the original CVE-2026-56740 per-frame guard but NOT this cross-frame bypass fix. This security fix should be cherry-picked to jline-3.x.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

buf.write(IAC);
buf.write(SE);
return buf.toByteArray();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔧 Nit: TelnetIO.NE_VAR_COUNT_MAX is protected static final in the same package — the test can reference it directly instead of duplicating the value. If the production constant is ever changed, this copy will silently diverge.

Suggested change
}
private static final int NE_VAR_COUNT_MAX = TelnetIO.NE_VAR_COUNT_MAX;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants