bug: fix lodash prototype pollution in PUT /chat (CWE-1321) - #239
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
bug: fix lodash prototype pollution in PUT /chat (CWE-1321)#239devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Replace the _.merge of the client-supplied chat message with an allow-listed Object.assign copy, require canDelete to be an own property on the delete guard, and upgrade the vulnerable lodash 4.17.4 dependency to 4.17.21.
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.
Summary
Fixes the CWE-1321 prototype pollution reachable through
PUT /chat(Snyk inventoryvuln_id83, "Prototype pollution in lodash defaults").routes/index.jsmerged the raw request body into a new message object with lodash 4.17.4:lodash < 4.17.5 does not filter
__proto__, so{"message": {"__proto__": {"canDelete": true}}}setsObject.prototype.canDelete. The in-repo gadget ischat.delete, whose guard is!user.canDelete— after pollution every user (including the low-privileged demo account) inheritscanDeleteand can delete messages; any otherif (obj.someFlag)check in the process is equally affected.Changes:
chat.addno longer merges attacker-controlled objects: it copies only own, string-typedtext/iconviapickMessageFields, then assignsid/timestamp/userNameserver-side. Thelodashimport is dropped (it was the only usage).chat.deleterequirescanDeleteto be an own property strictly equal totrue, so inherited flags from any future pollution sink cannot grant deletion.findUserrejects non-string credentials (blocks operator-object auth payloads).lodashbumped4.17.4→4.17.21inpackage.jsonandpackage-lock.json, removing the vulnerable version itself.Testing
tests/chat.prototype-pollution.test.js(new):__proto__andconstructor.prototypepayloads leaveObject.prototypeclean, only allow-listed fields are copied, delete stays 403, non-string auth is rejected.Requested by the code-scan remediation automation. Devin session: https://app.devin.ai/sessions/916f278a627a4ec188495dd38af4b17a
Devin-Org: engineering