Repository navigation
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
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
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
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Author
|
Saída do harness ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto
Corrige o finding de code scan
sfind-036662fe9eae4ebbb6c944fc5bf559eb(Updating a missing todo crashes the server,routes/index.js:218-221).exports.updateusavatodo.contentsem verificarerrnem setodoeranull. UmPOST /update/000000000000000000000000anônimo lançavaTypeError: 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);eif (!todo) return res.status(404).send('Todo not found');antes de alterar o todo.sarif.json: âncoras deroutes/index.jsapós a linha 219 deslocadas +2 (o checkSnykCodeusa esse SARIF estático; sem isso as linhas mudariam e apareceriam como "novos alertas").Mudança de contrato de API:
POST /update/:idcom id inexistente agora responde 404Todo not found(antes: sem resposta + crash do processo). Erro de banco agora vai paranext(err)(500 via errorhandler). O caminho de sucesso (302 para/) não mudou.Escopo: só o handler do finding.
exports.destroytem um padrão parecido (otry/catchvazio deixa a requisição pendurada para id inexistente), mas não derruba o processo e ficou de fora.Como testar
Harness (app real
app.jscom stand-in de Mongo em memória, porque o mongod 7 local é incompatível com o mongoose 4.2.4):main(e2ed058)POST /update/000000000000000000000000TypeError ... setting 'content')Todo not foundGET /depois dissoPOST /update/<id>com erro de DB injetadonext(err))POST /update/<id existente>/, conteúdo atualizado aparece em/Manual:
npm start, depoiscurl -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