Guard req.body before branching on credentials in POST /api/agents/accounts

Đang mở Phù hợp với người mới
#18,138 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại server/routes/platformAccounts.js, khoảng dòng 52-74, nơi req.body.credentials được đọc trước khi validateRequest chạy. Thao tác đọc này sẽ ném lỗi khi thiếu body. Sau đó mở server/routes/platformAccounts.test.js và thêm một trường hợp gửi POST tới /api/agents/accounts không có body và không có Content-Type JSON. Công việc hoàn tất khi yêu cầu đó trả về 400 VALIDATION_ERROR và test vượt qua.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

api-contract area:cos-agents effort:low in-progress model:light plan planner:gemini-4-neon-high

Problem

POST /api/agents/accounts (server/routes/platformAccounts.js:52-74) dereferences req.body.credentials unconditionally at line 55 before calling validateRequest. In Express 5 ([email protected]), req.body is undefined when a POST arrives without a body or without Content-Type: application/json, causing line 55 to throw TypeError: Cannot read properties of undefined (reading 'credentials'), which asyncHandler normalizes into a 500 INTERNAL_ERROR rather than a 400 VALIDATION_ERROR.

Impact

External/agent callers or malformed clients sending POST /api/agents/accounts without a JSON body or Content-Type: application/json trigger an unhandled TypeError (HTTP 500 INTERNAL_ERROR) and error-telemetry/stderr alerts instead of a clean 400 VALIDATION_ERROR.

Decided Fix

Change server/routes/platformAccounts.js:55-74 to normalize const body = req.body && typeof req.body === 'object' ? req.body : {}; (or if (req.body?.credentials) and pass req.body ?? {} to validateRequest) before branching between platformAccountSchema and accountRegistrationSchema. Add a regression test in server/routes/platformAccounts.test.js sending a bodyless POST without Content-Type: application/json.

Affected Files

  • server/routes/platformAccounts.js
  • server/routes/platformAccounts.test.js

Acceptance Criteria

  • POST /api/agents/accounts handles an undefined, null, or non-object req.body by passing req.body ?? {} into validation and returning HTTP 400 VALIDATION_ERROR instead of throwing HTTP 500 INTERNAL_ERROR.
  • server/routes/platformAccounts.test.js covers POST /api/agents/accounts with an omitted/empty body (no JSON Content-Type) and asserts a 400 VALIDATION_ERROR response.

Origin: PortOS api-contract baseline audit (2026-11-24) · Severity: 4/10

Ngôn ngữ chính
JavaScript
Star
38
Fork
32
Merge trung bình
20 phút
Pull request đã merge (30 ngày)
996

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của atomantic/PortOS

Tất cả issue của atomantic/PortOS

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.