Skip to content

Commit c7f6554

Browse files
authored
fix: allow multipart/form-data boundary to end with a newline (#5660)
The RFC 7578 spec for multipart/form-data requests does not require the body of a request to end with a CRLF, only that each section begins with a CRLF. While many clients implement multipart requests with the trailing CRLF, the implementation for fetch in Node.js version 22 and below does not. This caused my a good number of hours debugging! It does turn out that in September 2024 the Node.js fetch implementation added the CRLF (nodejs/undici#3625), though this hasn't made it to a Node.js release yet. This change allows the boundary to end with a newline or not, as long as the boundary is followed by the end of the request body.
1 parent 349f344 commit c7f6554

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backend/base/langflow/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@ async def check_boundary(request: Request, call_next):
193193
body = await request.body()
194194

195195
boundary_start = f"--{boundary}".encode()
196+
# The multipart/form-data spec doesn't require a newline after the boundary, however many clients do
197+
# implement it that way
196198
boundary_end = f"--{boundary}--\r\n".encode()
199+
boundary_end_no_newline = f"--{boundary}--".encode()
197200

198-
if not body.startswith(boundary_start) or not body.endswith(boundary_end):
201+
if not body.startswith(boundary_start) or not body.endswith((boundary_end, boundary_end_no_newline)):
199202
return JSONResponse(
200203
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
201204
content={"detail": "Invalid multipart formatting"},

0 commit comments

Comments
 (0)