Skip to content

RFC 854 Telnet command parsing, line buffering, and input length caps (fixes #4) - #13

Open
KingUdo wants to merge 4 commits into
mainfrom
issue-4-telnet-protocol-and-buffering
Open

KingUdo wants to merge 4 commits into
mainfrom
issue-4-telnet-protocol-and-buffering

Conversation

@KingUdo

@KingUdo KingUdo commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Implemented RFC 854 state-aware IAC parser (filter_telnet_iac) that properly handles:
    • 3-byte option negotiations (WILL, WONT, DO, DONT)
    • Variable-length subnegotiations (IAC SB ... IAC SE)
    • Escaped byte sequences (IAC IAC -> 0xFF)
    • 2-byte commands (NOP, BREAK, etc.)
    • Split packets / trailing incomplete IAC bytes across socket reads.
  • Replaced single recv with buffered line reading in telnet_read_filtered_input so input chunks are accumulated until newline (\r or \n) is encountered.
  • Added MAX_INPUT_LENGTH (default: 256 chars, configurable via environment variable) to cap username and password inputs, preventing memory exhaustion attacks from oversized payloads.
  • Added comprehensive unit tests in test_additional.py verifying RFC 854 command parsing, fragmented stream assembly, and length capping.
  • Fixes Telnet protocol byte desynchronization and lack of line buffering/length caps #4.

Test Results

============================== 21 passed in 3.17s ==============================

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.

Telnet protocol byte desynchronization and lack of line buffering/length caps

1 participant