BUG: HTTPTarget sends conflicting Content-Length and Transfer-Encoding headers
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start in parse_raw_http_request in pyrit/prompt_target/http_target/http_target.py, where only content-length is popped from the parsed headers. Check open PR #3008 first, since it already touches this branch and may overlap. Done means neither framing header survives parsing and the body is sent intact, which the suggested MockTransport test in tests/unit/prompt_target/target/test_request_tracing.py can pin.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
HTTPTarget.parse_raw_http_request strips content-length from the parsed header dict so that httpx can compute the correct value for the (possibly converter-modified) body:
if "content-length" in headers_dict:
del headers_dict["content-length"]
transfer-encoding is not stripped. When a raw request contains Transfer-Encoding: chunked (common when pasting from Burp), that header survives into the request, httpx/h11 chunk-frames the body, and httpx still adds its own Content-Length. Both framing headers ship on the same request.
RFC 9112 §6.1 states a sender MUST NOT send Content-Length in any message that contains a Transfer-Encoding header field. §6.3 requires recipients that receive both to treat the message as unrecoverable, and recommends intermediaries forwarding such a message strip Content-Length.
Two concrete impacts:
- Silent truncation / mojibake. The chunk-framed body is 20 bytes on the wire but
Content-Lengthadvertises 11 (the decoded length). Any intermediary or server that honorsContent-Lengthreads a prefix of the chunked framing. With multibyte content this truncates mid-UTF-8 and the operator sees corrupted text rather than an error. - Request smuggling shape. This is textbook CL.TE desync. PyRIT emits it with no warning, so an operator cannot tell whether an anomalous target response is a finding or a PyRIT framing artifact. For a tool whose output is security evidence, that ambiguity is the real cost.
This is pre-existing on main and unrelated to any open PR; I confirmed it reproduces both on main and on the branch in #3008.
Steps/Code to Reproduce
import asyncio, socket, threading
from pyrit.executor.attack import PromptSendingAttack
from pyrit.prompt_target import HTTPTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit_async
captured = []
srv = socket.socket(); srv.bind(("127.0.0.1", 0)); srv.listen(1)
port = srv.getsockname()[1]
def serve():
conn, _ = srv.accept()
buf = b""
while b"0\r\n\r\n" not in buf:
chunk = conn.recv(65535)
if not chunk:
break
buf += chunk
captured.append(buf)
conn.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok")
conn.close()
threading.Thread(target=serve, daemon=True).start()
raw = (
"POST / HTTP/1.1\r\n"
f"Host: 127.0.0.1:{port}\r\n"
"Transfer-Encoding: chunked\r\n"
"Content-Length: 11\r\n"
"\r\n"
"{PROMPT}"
)
async def main():
await initialize_pyrit_async(memory_db_type=IN_MEMORY)
target = HTTPTarget(http_request=raw, prompt_regex_string="{PROMPT}", use_tls=False)
await PromptSendingAttack(objective_target=target, max_attempts_on_failure=0).execute_async(
objective="hello world"
)
print(captured[0].decode())
asyncio.run(main())
Expected Results
Exactly one framing header on the wire. Either transfer-encoding is stripped alongside content-length so httpx owns framing, or chunked framing is honored and no Content-Length is emitted.
Actual Results
Both framing headers are sent, and the Content-Length value does not describe the bytes actually transmitted:
POST / HTTP/1.1
host: 127.0.0.1:49678
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
User-Agent: python-httpx/0.28.1
transfer-encoding: chunked
content-length: 11
b
hello world
0
Body is chunk-framed (b\r\nhello world\r\n0\r\n\r\n, 20 bytes) while content-length: 11 describes the decoded length. No warning or error is raised.
Suggested fix
Strip both hop-by-hop framing headers in parse_raw_http_request and let httpx own framing, consistent with the existing intent for content-length:
for framing_header in ("content-length", "transfer-encoding"):
headers_dict.pop(framing_header, None)
A regression test using httpx.MockTransport (matching the pattern in tests/unit/prompt_target/target/test_request_tracing.py) can pin that neither header survives parsing and that the body is sent intact.
If preserving operator-supplied chunked framing is considered in scope, that is a larger change and should be explicit rather than the current accidental middle state.
Screenshots
N/A
Versions
- OS: Windows
- Python version: 3.14
- PyRIT version: installed from
mainin editable mode (1.2.0.dev0) - httpx: 0.28.1
- Ngôn ngữ chính
- Python
- Star
- 4.6k
- Fork
- 944
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 350
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/PyRIT
-
BUG: label queries only return the final conversation of an attackCó thể đã có người làm @u7k4rs6 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microsoft/PyRIT#3095 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG Configuration keeps runtime-status errors after polling recoversCó thể đã có người làm @joeyvictorino đã nhận 5 ngày trước. Đang mởBug: triage GUI help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
microsoft/PyRIT#2868 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Crescendo backtracking keeps the refused prompt when the objective target made a tool callCó thể đã có người làm @RachelWanggg đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG BinAsciiConverter UUencode output cannot be decoded when all words are convertedCó thể đã có người làm @barkha1research-ai đã nhận hôm nay. Đang mởBug: triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 2 ngày
-
FEAT Proposal: red-team decision models as targets (decision flip-rate testing)Có thể đã có người làm @shashank03-dev đã nhận hôm nay. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
microsoft/PyRIT#3246 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/PyRIT
Issue tương tự
-
mermaid_extract.py silently discards single-line state-diagram notes; sequence notes are keptĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cathrynlavery/diagram-design#441 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Cleanup] Include the public header in work_split.cppCó thể đã có người làm @blozano-tt đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tenstorrent/tt-metal#60850 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
backend::sglang bug language::python observability
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
OpenShot/openshot-qt#6202 ·
Maintainer thường phản hồi trong vòng 1 ngày