fix: prevent prototype pollution via __proto__#156
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaced Object.assign-based initialization with object spread when creating the merge target and extended tests to assert that a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
__proto__ in defaults
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #156 +/- ##
============================================
+ Coverage 45.73% 100.00% +54.26%
============================================
Files 4 2 -2
Lines 223 46 -177
Branches 35 18 -17
============================================
- Hits 102 46 -56
+ Misses 119 0 -119
+ Partials 2 0 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
__proto__ in defaults__proto__
Resolves #155
Problem
When merging untrusted input (e.g. a parsed JSON request body) as the first argument to
defu, a crafted__proto__key can pollute the resulting object's prototype:This affects any application that passes unsanitized user input (HTTP request bodies, database records, config files from untrusted sources) into
defuto merge with safe defaults.Cause
Object.assign({}, defaults)triggers the__proto__setter, replacing the object's prototype with attacker-controlled values. Properties inherited from the polluted prototype bypass the existing__proto__key guard in thefor...inloop.Fix
Replace
Object.assign({}, defaults)with object spread ({ ...defaults }), which uses[[DefineOwnProperty]]and does not invoke the__proto__setter.Summary by CodeRabbit