`text/plain` request bodies are parsed instead of streamed: non-UTF-8 bytes corrupted, bodies over 1 MiB rejected with 413
Chưa có ai nhận issue nà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
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
- Lĩnh vực
- backend, networking
Hướng nghiên cứu
Bắt đầu tại index.js, khoảng dòng 718–719, nơi proxy đăng ký các bộ phân tích cú pháp nội dung, rồi đọc các bài kiểm thử parser gần đó. Bổ sung kiểm thử cho các lượt tải lên text/plain có byte không phải UTF-8 và phần nội dung vượt quá giới hạn mặc định. Sau đó, đăng ký parser cần thiết và xác nhận các bài kiểm thử cho thấy dữ liệu được chuyển tiếp nguyên vẹn từng byte mà không có phản hồi 413.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
5.12.8
Plugin version
@fastify/http-proxy 11.6.6 (also main at ce4d419), @fastify/reply-from 12.8.1
Node.js version
26.13.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Debian 12
Description
The README says non-JSON payloads are streamed directly to the destination. That holds for text/csv or application/octet-stream, but not for text/plain: Fastify's built-in text/plain parser still runs, because the plugin only overrides application/json and * (index.js lines 718-719). The body is decoded as UTF-8 and re-sent as a string, so a text/plain upload in any other charset is corrupted, and a text/plain upload larger than bodyLimit gets a 413 instead of being streamed.
// repro.mjs
import http from 'node:http';
import Fastify from 'fastify';
import proxy from '@fastify/http-proxy';
// upstream: report how many bytes arrived and the first bytes
http.createServer((req, res) => {
const chunks = [];
req.on('data', (c) => chunks.push(c));
req.on('end', () => {
const b = Buffer.concat(chunks);
res.end(`got ${b.length} bytes: ${b.subarray(0, 6).toString('hex')}`);
});
}).listen(3001);
const app = Fastify();
app.register(proxy, { upstream: 'http://127.0.0.1:3001' });
await app.listen({ port: 3000 });
const send = async (type, body) => {
const r = await fetch('http://127.0.0.1:3000/upload', { method: 'POST', headers: { 'content-type': type }, body });
console.log(type.padEnd(30), `sent ${body.length} bytes: ${body.subarray(0, 6).toString('hex')} ->`, r.status, await r.text());
};
const latin1 = Buffer.from('café crème', 'latin1');
await send('text/plain; charset=iso-8859-1', latin1);
await send('text/csv; charset=iso-8859-1', latin1);
await send('text/plain', Buffer.alloc(2 * 1024 * 1024, 'a'));
await send('application/octet-stream', Buffer.alloc(2 * 1024 * 1024, 'a'));
process.exit(0);
node repro.mjs prints:
text/plain; charset=iso-8859-1 sent 10 bytes: 636166e92063 -> 200 got 14 bytes: 636166efbfbd
text/csv; charset=iso-8859-1 sent 10 bytes: 636166e92063 -> 200 got 10 bytes: 636166e92063
text/plain sent 2097152 bytes: 616161616161 -> 413 {"statusCode":413,"code":"FST_ERR_CTP_BODY_TOO_LARGE","error":"Payload Too Large","message":"Request body is too large"}
application/octet-stream sent 2097152 bytes: 616161616161 -> 200 got 2097152 bytes: 616161616161
Link to code that reproduces the bug
https://gist.github.com/trackoor/a9dc305ecd07ded3018ca5fea688a582
Expected Behavior
text/plain bodies reach the upstream byte for byte, like every other non-JSON type: 10 bytes 636166e92063 in the first line and 200 got 2097152 bytes in the third. Registering bodyParser for text/plain next to application/json should be enough.
Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.
Credit: https://ucsbplse.github.io/
- Ngôn ngữ chính
- JavaScript
- Star
- 394
- Fork
- 105
- Merge trung bình
- 9 giờ 34 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọ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 fastify/fastify-http-proxy
-
reply.fromParameters() drops query params after a second "?"Có thể đã có người làm @RaphaelFakhri đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fastify/fastify-http-proxy#491 ·
Tất cả issue của fastify/fastify-http-proxy
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
arfct/timezone.fyi#19 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tensorflow/tfjs#8754 ·
-
Marketplace time-zone issueĐang mởbug main ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openhab/openhab-webui#4671 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
scratch-paint's npm test does not run lint, so CI never lints paint; one lint error is currently in developCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
scratchfoundation/scratch-editor#754 ·
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 96/100
google/site-kit-wp#14102 ·
Maintainer thường phản hồi trong vòng 2 ngày