Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

BUG: HTTPTarget turns CRLF into LF in the request body

已关闭
#3,353 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@nniiovoo 已经在做这个了。

开始于 2026年10月19日。

  • #3354 来自 @nniiovoo —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
api, backend

调研方向

The issue identifies HTTPTarget.parse_raw_http_request and describes a reproducible multipart request that fails in Starlette. Read that method and reproduce the example to confirm the body loses its CRLF line endings. Done means the request preserves the multipart separators and the example returns server got prompt='hello'.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

HTTPTarget.parse_raw_http_request replaces every \r\n in the raw request with \n before it splits the headers from the body, so the body loses its CRLFs too. This changes multipart boundary separators. The local example below fails with Starlette's multipart parser, which returns Invalid multipart data. A prompt that contains \r\n is changed the same way.

The comment just above that line says body whitespace should be kept exactly as given.

Steps/Code to Reproduce
import asyncio

import httpx
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.routing import Route

from pyrit.models import Message
from pyrit.prompt_target import HTTPTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit_async


async def upload(request):
    form = await request.form()
    return PlainTextResponse(f"server got prompt={form['prompt']!r}")


app = Starlette(routes=[Route("/upload", upload, methods=["POST"])])

# multipart request as copied from Burp (CRLF line endings)
raw_request = (
    "POST /upload HTTP/1.1\r\n"
    "Host: example.com\r\n"
    "Content-Type: multipart/form-data; boundary=XyZ\r\n"
    "\r\n"
    "--XyZ\r\n"
    'Content-Disposition: form-data; name="prompt"\r\n'
    "\r\n"
    "{PROMPT}\r\n"
    "--XyZ--\r\n"
)


async def main():
    await initialize_pyrit_async(memory_db_type=IN_MEMORY)
    client = httpx.AsyncClient(transport=httpx.ASGITransport(app=app))
    target = HTTPTarget(http_request=raw_request, prompt_regex_string="{PROMPT}", client=client)
    response = await target.send_prompt_async(message=Message.from_prompt(prompt="hello", role="user"))
    print(response[0].get_value())


asyncio.run(main())
Expected Results
server got prompt='hello'
Actual Results
Invalid multipart data.

The body that gets sent is --XyZ\nContent-Disposition: form-data; name="prompt"\n\nhello\n--XyZ--\n, with no CR left.

Versions
  • OS: macOS 26.4.1 (arm64)
  • Python 3.13.16
  • PyRIT 1.2.0.dev0, main (672a8fc5), editable install

I have a fix that splits off the body before normalizing the header line endings. Happy to open a PR if that sounds right.

主要语言
Python
星标
4.6k
派生
962
平均合并
2 天 15 小时
30 天内合并 PR
398

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/PyRIT 的其他 Issue

查看 microsoft/PyRIT 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。