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

オープン 初心者向け
#18,138 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
express, javascript, nodejs
領域
backend

調査の方向性

server/routes/platformAccounts.js の52〜74行目付近から始めてください。ここでは validateRequest が実行される前に req.body.credentials を読み取っており、body がない場合はこの読み取りでエラーが発生します。次に server/routes/platformAccounts.test.js を開き、body がなく JSON の Content-Type もない状態で /api/agents/accounts に POST するケースを追加してください。そのリクエストが 400 VALIDATION_ERROR を返し、テストが合格すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
JavaScript
スター
38
フォーク
32
平均マージ
20分
マージ済み PR(30日)
996

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

atomantic/PortOS のほかの issue

atomantic/PortOS の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。