BUG: HTTPTarget turns CRLF into LF in the request body
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
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'.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 4.7k
- Forks
- 980
- Ø Merge
- 2 T. 6 Std.
- Gemergte PRs (30 T.)
- 447
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/PyRIT
-
BUG: CredentialLeakScorer misses postgresql://, mongodb+srv://, rediss:// and amqps:// connection stringsEvtl. vergeben @ShivamSharma43 hat das vor 1 Tag übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Conversation drawer shows the previous attack's conversations after switching attacksEvtl. vergeben @ManoharPaturi hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
microsoft/PyRIT#3575 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Conversation draft turns permanently dirty when applied conversions match no pieceEvtl. vergeben @ManoharPaturi hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
microsoft/PyRIT#3573 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
New finding dialog loses a severity only edit without an unsaved changes warningEvtl. vergeben @ManoharPaturi hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
microsoft/PyRIT#3569 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
BUG: within word punctuation insertion can never land at the last two positions of the promptEvtl. vergeben @ManoharPaturi hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
microsoft/PyRIT#3565 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in microsoft/PyRIT
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagationEvtl. vergeben @muskan-creates352 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
mllam/neural-lam#848 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
infra
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
fab-geocommuns/RNB-coeur#1166 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
deepspeedai/DeepSpeed#8951 ·
Maintainer antworten meist innerhalb von 2 Tagen