Skip to content

A fast, keyboard-driven TUI API client & webhook inspector. No cloud, no Electron, 100% local-first.

fix: strict Content-Length RFC 9112 validation, disallow duplicate chunked, and restore Ctrl+T TLS toggle (v0.1.8)

4yk54b7fc9fef21f
diff --git a/app.py b/app.py
index b5203f1..6719cf1 100644
--- a/app.py
+++ b/app.py
@@ -255,6 +255,7 @@ TextArea, TextArea:focus, #body-input, #body-input:focus, #headers-input, #heade
BINDINGS = [
Binding("ctrl+s", "send_request", "Send Request", priority=True),
Binding("ctrl+w", "toggle_webhook", "Toggle Webhook Server", priority=True),
+ Binding("ctrl+t", "toggle_ssl", "Toggle TLS Verify", priority=True),
Binding("ctrl+n", "new_request", "New Request", priority=True),
Binding("ctrl+k", "save_request", "Save Request", priority=True),
Binding("ctrl+q", "quit", "Quit", priority=True)
@@ -270,7 +271,8 @@ TextArea, TextArea:focus, #body-input, #body-input:focus, #headers-input, #heade
def __init__(self):
super().__init__()
- self.network = NetworkEngine()
+ self.verify_ssl: bool = True
+ self.network = NetworkEngine(verify_ssl=True)
self.storage = StorageManager()
self.collections = self.storage.load_collections()
self.webhook_server = WebhookServer(
@@ -442,6 +444,14 @@ TextArea, TextArea:focus, #body-input, #body-input:focus, #headers-input, #heade
self.query_one("#url-input", Input).focus()
self.notify("New request ready")
+ def action_toggle_ssl(self):
+ """Toggle SSL/TLS Certificate Verification (Ctrl+T)"""
+ self.verify_ssl = not self.verify_ssl
+ if self.verify_ssl:
+ self.notify("TLS Certificate Verification ENABLED (Secure)", timeout=3)
+ else:
+ self.notify("TLS Certificate Verification DISABLED (Insecure)", severity="warning", timeout=3)
+
async def on_button_pressed(self, event: Button.Pressed):
btn_id = event.button.id
if btn_id == "send-btn":
@@ -525,12 +535,13 @@ TextArea, TextArea:focus, #body-input, #body-input:focus, #headers-input, #heade
req_body = body if method in ["POST", "PUT", "PATCH", "DELETE"] else None
- # Execute with full headers
+ # Execute with full headers and TLS verification mode
res = await self.network.execute_request(
method=method,
url=url,
headers=req_headers,
- body=req_body
+ body=req_body,
+ verify_ssl=self.verify_ssl
)
if res["success"]:
diff --git a/network.py b/network.py
index 14d564b..e2a523a 100644
--- a/network.py
+++ b/network.py
@@ -23,7 +23,7 @@ class NetworkEngine:
headers = dict(headers) if headers else {}
if not any(k.lower() == "user-agent" for k in headers):
- headers["User-Agent"] = "Ghostman/0.1.7"
+ headers["User-Agent"] = "Ghostman/0.1.8"
if body and not any(k.lower() == "content-type" for k in headers):
try:
diff --git a/pyproject.toml b/pyproject.toml
index 63b2c67..ef9e554 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ghostman"
-version = "0.1.7"
+version = "0.1.8"
description = "A fast, keyboard-driven terminal API client and webhook inspector"
readme = "README.md"
authors = [{ name = "4yk5" }]
diff --git a/tests/test_vulnerabilities_fixed.py b/tests/test_vulnerabilities_fixed.py
index cfe60bf..6c0ba41 100644
--- a/tests/test_vulnerabilities_fixed.py
+++ b/tests/test_vulnerabilities_fixed.py
@@ -379,7 +379,7 @@ async def test_chunked_transfer_encoding_webhook():
resp_to = await reader_to.read(1024)
writer_to.close()
await writer_to.wait_closed()
- assert b"408 Request Timeout" in resp_to or len(resp_to) == 0
+ assert b"408 Request Timeout" in resp_to, f"Expected 408 Request Timeout, got: {resp_to[:100]}"
assert len(ws_timeout.captured_hooks) == 0
finally:
await ws_timeout.stop()
@@ -399,8 +399,11 @@ async def test_chunked_transfer_encoding_webhook():
reader7, writer7 = await asyncio.open_connection("127.0.0.1", 9096)
writer7.write(premature_trailer_eof)
await writer7.drain()
+ writer7.write_eof()
+ resp7 = await reader7.read(1024)
writer7.close()
await writer7.wait_closed()
+ assert b"400 Bad Request" in resp7, f"Expected 400 Bad Request on premature trailer EOF, got: {resp7[:100]}"
await asyncio.sleep(0.1)
assert len(received_hooks) == 2, "VULNERABILITY: Unterminated trailer EOF was accepted into captured_hooks!"
@@ -468,6 +471,100 @@ async def test_chunked_transfer_encoding_webhook():
await asyncio.sleep(0.1)
assert len(received_hooks) == 2, "VULNERABILITY: Unsupported Transfer-Encoding was accepted into captured_hooks!"
+ # M) Multiple chunked encodings (RFC 9112 §6.1) MUST return 400 Bad Request
+ dup_chunked_http = (
+ b"POST /dup-chunked HTTP/1.1\r\n"
+ b"Host: 127.0.0.1:9096\r\n"
+ b"Transfer-Encoding: chunked, chunked\r\n"
+ b"Connection: close\r\n"
+ b"\r\n"
+ b"0\r\n\r\n"
+ )
+ reader_m, writer_m = await asyncio.open_connection("127.0.0.1", 9096)
+ writer_m.write(dup_chunked_http)
+ await writer_m.drain()
+ resp_m = await reader_m.read(1024)
+ writer_m.close()
+ await writer_m.wait_closed()
+ assert b"400 Bad Request" in resp_m, f"Expected 400 on duplicate chunked encoding, got: {resp_m[:100]}"
+ await asyncio.sleep(0.1)
+ assert len(received_hooks) == 2, "VULNERABILITY: Multiple chunked encoding was accepted into captured_hooks!"
+
+ # N) Content-Length: Non-digit (RFC 9110 §8.6) MUST return 400 Bad Request
+ cl_alpha_http = (
+ b"POST /cl-alpha HTTP/1.1\r\n"
+ b"Host: 127.0.0.1:9096\r\n"
+ b"Content-Length: abc\r\n"
+ b"Connection: close\r\n"
+ b"\r\n"
+ )
+ reader_n, writer_n = await asyncio.open_connection("127.0.0.1", 9096)
+ writer_n.write(cl_alpha_http)
+ await writer_n.drain()
+ resp_n = await reader_n.read(1024)
+ writer_n.close()
+ await writer_n.wait_closed()
+ assert b"400 Bad Request" in resp_n, f"Expected 400 on non-digit Content-Length, got: {resp_n[:100]}"
+ await asyncio.sleep(0.1)
+ assert len(received_hooks) == 2, "VULNERABILITY: Non-digit Content-Length was accepted into captured_hooks!"
+
+ # O) Content-Length: Negative value MUST return 400 Bad Request
+ cl_neg_http = (
+ b"POST /cl-neg HTTP/1.1\r\n"
+ b"Host: 127.0.0.1:9096\r\n"
+ b"Content-Length: -10\r\n"
+ b"Connection: close\r\n"
+ b"\r\n"
+ )
+ reader_o, writer_o = await asyncio.open_connection("127.0.0.1", 9096)
+ writer_o.write(cl_neg_http)
+ await writer_o.drain()
+ resp_o = await reader_o.read(1024)
+ writer_o.close()
+ await writer_o.wait_closed()
+ assert b"400 Bad Request" in resp_o, f"Expected 400 on negative Content-Length, got: {resp_o[:100]}"
+ await asyncio.sleep(0.1)
+ assert len(received_hooks) == 2, "VULNERABILITY: Negative Content-Length was accepted into captured_hooks!"
+
+ # P) Content-Length: Conflicting multiple values (RFC 9112 §6.3) MUST return 400 Bad Request
+ cl_conflict_http = (
+ b"POST /cl-conflict HTTP/1.1\r\n"
+ b"Host: 127.0.0.1:9096\r\n"
+ b"Content-Length: 10\r\n"
+ b"Content-Length: 20\r\n"
+ b"Connection: close\r\n"
+ b"\r\n"
+ )
+ reader_p, writer_p = await asyncio.open_connection("127.0.0.1", 9096)
+ writer_p.write(cl_conflict_http)
+ await writer_p.drain()
+ resp_p = await reader_p.read(1024)
+ writer_p.close()
+ await writer_p.wait_closed()
+ assert b"400 Bad Request" in resp_p, f"Expected 400 on conflicting Content-Length, got: {resp_p[:100]}"
+ await asyncio.sleep(0.1)
+ assert len(received_hooks) == 2, "VULNERABILITY: Conflicting Content-Length values were accepted into captured_hooks!"
+
+ # Q) Content-Length: Identical multiple values (RFC 9112 §6.3) MUST be accepted as 200 OK
+ cl_identical_http = (
+ b"POST /cl-identical HTTP/1.1\r\n"
+ b"Host: 127.0.0.1:9096\r\n"
+ b"Content-Length: 5, 5\r\n"
+ b"Connection: close\r\n"
+ b"\r\n"
+ b"hello"
+ )
+ reader_q, writer_q = await asyncio.open_connection("127.0.0.1", 9096)
+ writer_q.write(cl_identical_http)
+ await writer_q.drain()
+ resp_q = await reader_q.read(1024)
+ writer_q.close()
+ await writer_q.wait_closed()
+ assert b"200 OK" in resp_q, f"Expected 200 OK on identical multiple Content-Length, got: {resp_q[:100]}"
+ await asyncio.sleep(0.1)
+ assert len(received_hooks) == 3, "WebhookServer did not capture valid identical Content-Length request!"
+ assert received_hooks[2]["raw_body"] == "hello"
+
finally:
await ws.stop()
@@ -515,12 +612,21 @@ async def test_tui_headers_and_gui_state():
await pilot.pause(0.1)
assert app.query_one("#headers-input", TextArea).text == ""
+ # Test TLS Toggle action via hotkey (Ctrl+T)
+ assert app.verify_ssl is True
+ await pilot.press("ctrl+t")
+ await pilot.pause(0.1)
+ assert app.verify_ssl is False
+ await pilot.press("ctrl+t")
+ await pilot.pause(0.1)
+ assert app.verify_ssl is True
+
print(" [+] TUI Headers & GUI State: PASS")
async def main():
print("\n" + "=" * 60)
- print("RUNNING GHOSTMAN AUDIT VULNERABILITY VERIFICATION (v0.1.7)")
+ print("RUNNING GHOSTMAN AUDIT VULNERABILITY VERIFICATION (v0.1.8)")
print("=" * 60)
await test_tls_verification_default_and_toggle()
diff --git a/webhook_server.py b/webhook_server.py
index dd98d2c..0ce1df6 100644
--- a/webhook_server.py
+++ b/webhook_server.py
@@ -90,7 +90,7 @@ class WebhookServer:
path = parts[1] if len(parts) > 1 else "/"
headers = {}
- content_length = 0
+ content_length_values = []
transfer_encodings = []
while True:
try:
@@ -109,15 +109,42 @@ class WebhookServer:
headers[k_clean] = v_clean
lower_k = k_clean.lower()
if lower_k == "content-length":
- try:
- content_length = int(v_clean)
- except ValueError:
- content_length = 0
+ # Content-Length may be sent multiple times or comma-separated
+ parts = [p.strip() for p in v_clean.split(",") if p.strip()]
+ if not parts:
+ await self._send_error_response(writer, b"400 Bad Request", "Empty Content-Length header")
+ return
+ content_length_values.extend(parts)
elif lower_k == "transfer-encoding":
# Multiple transfer encodings can be comma-separated or repeated
parts = [p.strip().lower() for p in v_clean.split(",") if p.strip()]
transfer_encodings.extend(parts)
+ # Validate Content-Length (RFC 9112 §6.3, RFC 9110 §8.6)
+ content_length = 0
+ if content_length_values:
+ for val_str in content_length_values:
+ # Content-Length must consist strictly of 1*DIGIT (no sign, letters, whitespace)
+ if not val_str.isdigit():
+ await self._send_error_response(
+ writer,
+ b"400 Bad Request",
+ f"Invalid Content-Length header value: {val_str}"
+ )
+ return
+
+ int_values = [int(v) for v in content_length_values]
+ # All values must be identical; conflicting lengths indicate framing error / smuggling
+ if len(set(int_values)) > 1:
+ await self._send_error_response(
+ writer,
+ b"400 Bad Request",
+ "Conflicting multiple Content-Length values (RFC 9112 §6.3)"
+ )
+ return
+
+ content_length = int_values[0]
+
# Validate Transfer-Encoding (RFC 9112 §6.1, §6.3)
if transfer_encodings:
unsupported = [enc for enc in transfer_encodings if enc != "chunked"]
@@ -130,6 +157,15 @@ class WebhookServer:
)
return
+ # RFC 9112 §6.1: chunked transfer coding MUST NOT be applied more than once
+ if transfer_encodings.count("chunked") > 1:
+ await self._send_error_response(
+ writer,
+ b"400 Bad Request",
+ "Multiple chunked transfer codings are forbidden (RFC 9112 §6.1)"
+ )
+ return
+
if transfer_encodings[-1] != "chunked":
await self._send_error_response(
writer,