BUG: HTTPTarget turns CRLF into LF in the request body
维护者通常 2 天内回复
评估
调研方向
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
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/PyRIT 的其他 Issue
-
BUG: Overlapping scorer-evaluation globs duplicate CSVs and change accuracy可能已有人在做 @its-amann 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/PyRIT#3430 · 1 条评论 ·
维护者通常 2 天内回复
-
BUG: MarkdownInjectionScorer misses shortcut-reference images with path-based exfiltration, and raw HTML <img>可能已有人在做 @aatif101 于 1 天前认领。 未关闭Bug: triage
难度 2/5 1-3 小时 新手友好度 72/100
microsoft/PyRIT#3343 · 2 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
BUG: OpenAITTSTarget accepts any speed, so an out-of-range value is only sent to the API on every request可能已有人在做 @ShivamSharma43 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 2 天内回复
-
BUG: KeywordSelectionStrategy accepts a negative context, so SelectiveTextConverter duplicates or truncates the prompt可能已有人在做 @ShivamSharma43 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
维护者通常 2 天内回复
-
BUG: PackageHallucinationScorer flags Rust std paths, type names and hyphenated crates as hallucinated可能已有人在做 @nniiovoo 今天认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 2 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
-
[Bug]: Queen's own Ollama model loses num_ctx when a running session switches to it可能已有人在做 @anasamin26 今天认领。 未关闭bug enhancement
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
llm translation
难度 2/5 1-3 小时 新手友好度 78/100
BerriAI/litellm#47884 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug 🐛
难度 2/5 1-3 小时 新手友好度 72/100
netalertx/NetAlertX#1856 · 1 个 reaction ·
维护者通常 1 天内回复