Fix: Path Traversal vulnerability (SonarQube S2083)#38
Fix: Path Traversal vulnerability (SonarQube S2083)#38devin-ai-integration[bot] wants to merge 1 commit into
Conversation
🤖 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 summary — SonarQube
|
- Import path module for path resolution validation - Validate resolved template path stays within views directory - Pass only whitelisted profile fields to res.render() instead of raw req.body to prevent user-controlled properties from influencing template file resolution Co-Authored-By: Joao Esteves <joao.esteves@cognition.ai>
e298fe2 to
7508b2c
Compare
| return res.render('account.hbs', profile) | ||
| // render the view with only the expected, validated fields | ||
| // to prevent path traversal via user-controlled template properties (S2083) | ||
| var viewPath = 'account.hbs'; |
SonarQube Remediation Documentation
What was changed
Why
|
Summary
Fixes a path traversal vulnerability flagged by SonarQube (rule
jssecurity:S2083, issue keyAZoM-zIBs8nSf3VywcRW, BLOCKER) atroutes/index.js:107.Vulnerability: In
save_account_details, the entire user-controlledreq.bodywas passed directly tores.render(). Express/Handlebars treats the second argument as render options as well as template data — user-controlled keys likelayoutcould influence filesystem path resolution, enabling path traversal.Fix:
pathmodule and validate the resolved template path stays within the configured views directory usingpath.resolve()+startsWith()checkres.render()instead of the rawreq.bodyUser-controlled keys can no longer reach the renderer's option/path resolution.
Link to Devin session: https://app.devin.ai/sessions/d4144ad73bdf49a1954c358860323103
Requested by: @joao-cognition
Devin Review