Files
cleveragents-core/features/lsp_header_injection_security.feature
HAL9000 89d8b9e751 fix(lsp): prevent header injection in LSP transport ASCII decoding
Security: Added strict ASCII validation to _read_one_message() header parsing
to enforce LSP specification requirements. Non-ASCII bytes in headers now raise
LspError. Printable-ASCII guard rejects characters outside 0x20–0x7E range.

- Removed redundant inline LspError imports from start() exception handlers
  (top-level import added instead)
- Updated _read_one_message() docstring with ASCII enforcement documentation
- Created BDD test suite for LSP header injection security scenarios
- Fixed Gherkin feature file tag placement and whitespace
- Fixed select.select() 3-tuple return in patched mock to match API contract
- Cleaned up CHANGELOG.md bullet formatting and CONTRIBUTORS.md entries

Closes #7112

Signed-off-by: HAL9000 <hal9000@cleverthis.com>
2026-06-13 04:39:01 -04:00

39 lines
1.8 KiB
Gherkin

@tdd_issue
@tdd_issue_7112
Feature: LSP transport header injection security
The ``_read_one_message()`` method in the LSP stdio transport must strictly
enforce ASCII-only headers. Non-ASCII bytes silently replaced by the
old ``errors="replace"`` path could be used to manipulate message
boundaries and desynchronise the protocol.
@tdd_issue_7112
Scenario: Non-ASCII byte in Content-Length value raises LspError
Given a Transport mock with BytesIO stream containing b"Content-Length: 10\xc0\r\n\r\nhello\x00world"
When _read_one_message() is invoked
Then it should raise an LspError exception
And the error message must contain "non-ASCII"
@tdd_issue_7112
Scenario: Non-ASCII byte in a valid Content-Length name raises LspError
Given a Transport mock with BytesIO stream containing b"Content-Length\xef\x08: 99\r\n\r\n{\"jsonrpc\":\"2.0\"}"
When _read_one_message() is invoked
Then it should raise an LspError exception
And the error message must contain "non-ASCII"
@tdd_issue_7112
Scenario: Non-ASCII byte in an unrecognized header raises LspError
Given a Transport mock with BytesIO stream containing b"Cache-Control\xef\x08: no-cache\r\nContent-Length: 5\r\n\r\n{\"id\":1}"
When _read_one_message() is invoked
Then it should raise an LspError exception
And the error message must contain "non-ASCII"
@tdd_issue_7112
Scenario: Valid ASCII headers are processed correctly
Given a Transport mock with BytesIO stream containing b"Content-Length: 43\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"success\"}"
When _read_one_message() is invoked
Then it should return a parsed JSON dict
And the result must contain "jsonrpc" == "2.0"
And the result must contain "id" == 1
And the result must contain "result" == "success"