Skip to content

Escape IAC bytes in telnet server output - #2175

Open
neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:telnet-escape-iac
Open

neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:telnet-escape-iac

Conversation

@neeraj1235476

Copy link
Copy Markdown
Contributor

_ConnectionStdout.write in contrib/telnet/server.py encodes the output and sends the bytes as is, but RFC 854 requires a 0xFF data byte to be sent as IAC IAC. With a single-byte encoding (TelnetServer(encoding="latin-1"), cp1252, ...) a "ÿ" in printed text goes out as a bare IAC, so the client parses it and the following bytes as a telnet command. For example, a chat message containing "ÿü�" broadcast with send_above_prompt reaches other clients as IAC WONT ECHO. They switch to local echo, so a later is_password prompt shows what they type.

Double IAC in the encoded bytes inside _ConnectionStdout.write, which every Vt100_Output of a connection writes through, so callers printing untrusted text don't need to know about telnet framing. The negotiation commands in _initialize_telnet go straight to the socket and are unaffected. tests/test_telnet.py covers it (fails before, passes after).

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.

1 participant