Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

HTTP engine has no partial-content/timeout handling for streaming (chunked/SSE) responses

Open NSK-394 opened this issue 3 months ago • 1 comments

Context: Found while developing a new vulnerability detection module (#1653) for CVE-2026-33017, which needs to check a Langflow NDJSON event-stream endpoint.

Related: #1654 (a separate bug where per-step timeout values get overwritten by the global CLI default) — discovered during the same investigation, but this is a distinct issue: even with correct per-step timeout handling, no finite timeout value solves a genuinely non-terminating stream.

Also related but distinct: #1356, which covers a different failure mode (empty {} results from concurrent async substeps overwriting valid ones) in the same general area of the event-write/response-handling pipeline.

Problem

Nettacker's HTTP engine cannot safely check streaming/chunked-response endpoints (Server-Sent Events, NDJSON streams, etc.) because the current request-handling architecture has no mechanism to read partial content on timeout.

Root Cause

File: nettacker/core/lib/http.py, function perform_request_action() (lines 23-33)

async def perform_request_action(action, request_options): start_time = time.time() async with action(**request_options) as response: return { "reason": response.reason, "url": str(response.url), "status_code": str(response.status), "content": await response.content.read(), # blocks until full body "headers": dict(response.headers), "responsetime": time.time() - start_time, }

The call to await response.content.read() on line 30 waits for the complete response body before returning. There is no streaming/chunked-read path and no timeout-aware partial-content handling. When a timeout fires during the read:

  1. An exception is raised (asyncio.TimeoutError or aiohttp.ClientError)
  2. The exception propagates to HttpEngine.run() (line 183), which catches it with a bare except Exception
  3. The response is discarded entirely: response = [] (line 184)
  4. Any data that had already arrived is permanently lost
  5. Condition matching fails with an empty response object
  6. The step produces no detection signal, even though the server responded with useful partial data

Real-World Evidence

Tested against a real Langflow 1.8.2 instance (remote VPS, not local Docker) with a streaming endpoint (/api/v1/build/{job_id}/events):

  • Connection opens successfully (HTTP 200, chunked transfer-encoding)
  • First 3-5 seconds: partial data arrives containing detection signals (an error traceback referencing our injected content)
  • After 30-60 seconds: connection remains open with no terminating response
  • Setting any finite timeout (3s, 5s, 10s, 30s, 60s) eventually times out if the stream doesn't close on its own

This proves no timeout value can reliably handle indefinite streams — the connection itself is valid, the stream simply doesn't terminate.

Impact

Not limited to one module. Any future vulnerability check against a streaming endpoint hits this same wall: SSE endpoints, NDJSON event streams, WebSocket-upgraded streaming responses, long-polling build/deploy status endpoints.

Current workaround: set timeout to an arbitrary "high enough" value and hope the stream terminates before that — unreliable, and impractical for mass scanning (30-60s per target per check).

Why Timeout Values Alone Don't Solve This

Setting timeout: 60 doesn't mean "read the first chunk and stop after 60s." It means response.content.read() blocks for up to 60 seconds waiting for the FULL response, then fails entirely, discarding everything already received. The architecture conflates two separate concerns: connection timeout (how long to wait for a response to start) and streaming timeout (how to handle a response that's valid but never fully terminates) — only the first is currently handled.

Suggested Fix Direction (not implemented, flagging for maintainer input)

Replace response.content.read() with a streaming/chunked-read approach that reads chunks incrementally, applies timeout to chunk arrival rather than full completion, and returns partial content + an "incomplete" flag on timeout instead of raising and discarding.

Happy to help test/validate a fix once direction is agreed, per the core- change contribution guidelines.

NSK-394 avatar Aug 08 '26 15:08 NSK-394

Hi, I’d like to work on this. I’ll wait for maintainer agreement on the approach and assignment before starting.

Ehtasham-Yasin avatar Aug 25 '26 14:08 Ehtasham-Yasin