Fix jssecurity:S2083: path traversal in routes/index.js - #241
Fix jssecurity:S2083: path traversal in routes/index.js#241devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…e AZoM-zIBs8nSf3VywcRW) Co-Authored-By: Joao Esteves <joao.esteves@cognition.ai>
| // render the view, passing only the known profile fields so that | ||
| // request data cannot override view/template resolution options | ||
| return res.render('account.hbs', { | ||
| firstname: profile.firstname, |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Remediation of SonarQube issue What changed: In Why: Express merges the locals object into the options passed to the view engine, so any extra attacker-supplied key in Scope: Minimal and behavior-preserving — |
Summary
Fixes SonarQube issue
AZoM-zIBs8nSf3VywcRW(rulejssecurity:S2083, BLOCKER, path traversal) atroutes/index.js:107insave_account_details.The handler took the whole request body (
const profile = req.body) and passed that object straight to the template renderer:Express merges the locals object into the render options it hands to the view engine, so attacker-controlled keys in
req.body(e.g.layout,partials,settings, or other engine path options accepted by hbs/consolidate) flow into template path resolution. Exploit scenario:POST /account_detailswith validfirstname/lastname/country/phone/emailplus an extra field such aslayout=../../../../etc/passwd, making the render step resolve and read a file outside theviews/directory — file disclosure via path traversal. Only the five fields the form/validation actually covers are now forwarded, so no request-controlled key can reach path resolution.Behavior is otherwise unchanged:
views/account.hbsonly reads those five fields, and the validation/rtrimlogic is untouched. No other vulnerability in the file was modified.Verification:
node --check routes/index.jspasses.npm testin this repo runs a Snyk vulnerability scan (requires Snyk auth) rather than a unit suite, so it was not run.Devin-Org: engineering
Link to Devin session: https://app.devin.ai/sessions/42c2452f929b472a87fd4c36d64f0b7d
Open in Devin Desktop: https://app.devin.ai/desktop/session/42c2452f929b472a87fd4c36d64f0b7d?variant=devin
Requested by: @joao-cognition
Note
Devin errored when opening this Pull Request as joao-cognition.
As a fallback, Devin opened this PR as itself.
Devin Review