fix: remediate 4 SAST findings in app.js (asset 73206) - #12
fix: remediate 4 SAST findings in app.js (asset 73206)#12eduardoconviso wants to merge 1 commit into
Conversation
Fix the four vulnerabilities reported by Conviso AST for asset 73206:
- OS Command Injection (/ping, issue 7823033): replace exec() with
execFile() so no shell is spawned, and validate host against a
hostname/IP allowlist that rejects flags and shell metacharacters.
- SQL Injection (/users, issue 7823032): bind id as a query parameter
('... WHERE id = ?', [id]) instead of string concatenation.
- Reflected XSS (/greet, issue 7823031): HTML-escape user input before
writing it to the response.
- DOM XSS (/search, issue 7823030): JSON-encode the value into a JS
string literal and assign via textContent instead of innerHTML.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LMYDs3LsR9Ck2VBqtntfrn
🛡️ Conviso Application Security Scan ResultsSummary: 0 Critical | 0 High | 3 Medium | 1 Low 🟠 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')Severity: Medium | File: User data flows into the host portion of this manually-constructed HTML. This can introduce a Cross-Site-Scripting (XSS) vulnerability if this comes from user-provided input. Consider using a sanitization library such as DOMPurify to sanitize the HTML within. 🟠 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')Severity: Medium | File: Detected directly writing to a Response object from user-defined input. This bypasses any HTML escaping and may expose your application to a Cross-Site-scripting (XSS) vulnerability. Instead, use 'resp.render()' to render safely escaped HTML. 🔵 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')Severity: Low | File: Cannot determine what 'encoded' is and it is used with a '<script>' tag. This could be susceptible to cross-site scripting (XSS). Ensure 'encoded' is not externally controlled, or sanitize this data. |
Summary
Remediates the 4 latest vulnerabilities reported by Conviso AST for asset 73206 (
teste2), all inapp.js./ping/users/greet/searchFixes
/ping) — replacedexec('ping -c 1 ' + host)withexecFile('ping', ['-c','1','--', host])so no shell is spawned;hostis validated against a hostname/IP allowlist (/^[a-zA-Z0-9.-]{1,253}$/, leading-rejected) before use./users) —idis now bound as a parameter (SELECT * FROM users WHERE id = ?,[id]) instead of string concatenation. Thedb.querystub was updated to a(sql, params, cb)signature mirroring real drivers./greet) — user input is HTML-escaped via a newescapeHtml()helper before being written to the response./search) — the value is JSON-encoded into a JS string literal (with<escaped to prevent early</script>) and assigned viatextContentinstead ofinnerHTML.Testing
node --check app.jspasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01LMYDs3LsR9Ck2VBqtntfrn