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

Aperta Adatta ai principianti
#18,138 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
express, javascript, nodejs
Ambito
backend

Direzione di ricerca

Inizia da server/routes/platformAccounts.js, intorno alle righe 52-74, dove req.body.credentials viene letto prima che validateRequest venga eseguito. Quella lettura genera un errore quando il body manca. Poi apri server/routes/platformAccounts.test.js e aggiungi un caso che invia una POST a /api/agents/accounts senza body e senza Content-Type JSON. È completato quando quella richiesta restituisce 400 VALIDATION_ERROR e il test passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
JavaScript
Stelle
38
Fork
32
Merge medio
20m
PR unite (30g)
996

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di atomantic/PortOS

Tutte le issue di atomantic/PortOS

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.