Skip to content

bug: return 404 instead of crashing on POST /update for a missing todo - #1108

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/sfind-036662fe-update-missing-todo-404
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/sfind-036662fe-update-missing-todo-404

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Contexto

Corrige o finding de code scan sfind-036662fe9eae4ebbb6c944fc5bf559eb (Updating a missing todo crashes the server, routes/index.js:218-221).

exports.update usava todo.content sem verificar err nem se todo era null. Um POST /update/000000000000000000000000 anônimo lançava TypeError: Cannot set properties of null (setting 'content') dentro do callback do Mongo, fora do tratamento de erros do Express, e o processo caía.

Mudança

  • routes/index.js (exports.update): if (err) return next(err); e if (!todo) return res.status(404).send('Todo not found'); antes de alterar o todo.
  • sarif.json: âncoras de routes/index.js após a linha 219 deslocadas +2 (o check SnykCode usa esse SARIF estático; sem isso as linhas mudariam e apareceriam como "novos alertas").

Mudança de contrato de API: POST /update/:id com id inexistente agora responde 404 Todo not found (antes: sem resposta + crash do processo). Erro de banco agora vai para next(err) (500 via errorhandler). O caminho de sucesso (302 para /) não mudou.

Escopo: só o handler do finding. exports.destroy tem um padrão parecido (o try/catch vazio deixa a requisição pendurada para id inexistente), mas não derruba o processo e ficou de fora.

Como testar

Harness (app real app.js com stand-in de Mongo em memória, porque o mongod 7 local é incompatível com o mongoose 4.2.4):

Cenário main (e2ed058) este PR
POST /update/000000000000000000000000 sem resposta, processo morre (TypeError ... setting 'content') 404 Todo not found
GET / depois disso connection refused 200
POST /update/<id> com erro de DB injetado — 500 (next(err))
POST /update/<id existente> — 302 → /, conteúdo atualizado aparece em /

Manual: npm start, depois curl -i -X POST -d content=x localhost:3001/update/000000000000000000000000 → deve retornar 404 e o servidor continua respondendo.

Não há suíte de testes automatizada (npm test = snyk test, precisa de auth).

Devin-Org: engineering

Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/d9d84b7ab4b142f39ea12bd6f9869d9d
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/d9d84b7ab4b142f39ea12bd6f9869d9d?variant=devin


Devin Review

Status Commit
⚪ Not started —

Run Devin Review

Enable auto-review to review your pull requests automatically.

Devin Review (Staging)


Devin Review

exports.update dereferenced todo without checking err or null, so
POST /update/<unknown id> threw inside the Mongo callback and killed the
process. Return next(err) on DB error and 404 when the todo is missing.
sarif.json routes/index.js anchors after line 219 shifted by 2.

Refs: sfind-036662fe9eae4ebbb6c944fc5bf559eb
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

Saída do harness (notes/goof-0366-harness/run.sh, app real + Mongo em memória):

== before (e2ed058)
GET /                                        -> 200
POST /update/000000000000000000000000 (missing) -> [000]
   body: 
server process: DEAD (exit after crash)
GET / after missing-id update                -> connection refused
uncaught errors in log: 1
TypeError: Cannot set properties of null (setting 'content')

== after (e2ed058)
GET /                                        -> 200
POST /update/000000000000000000000000 (missing) -> [404]
   body: Todo not found
server process: ALIVE
GET / after missing-id update                -> 200
POST /update/eeee... (injected DB error)     -> 500
POST /create (content=hello)                 -> 302
POST /update/6aecf5fcc82e9e4b2e1a9577 (existing) -> 302 Location=http://localhost:3612/
GET / shows edited0366: 2
uncaught errors in log: 0

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants