fix(): fix Critical command injection vulnerability + cross-platform breakage in CCTV image proxy - #244
Conversation
…breakage in CCTV image proxy
|
@simplifaisoul @sam1am @javierpr0 Can you please review this PR? |
|
Independently reached the same fix while hardening this file for a separate issue (#259), and can confirm the approach here is correct. A few notes that may help a reviewer merge with confidence: Root cause, not just symptom. Swapping the execSync(\curl.exe … "${url}" |
PR: Replace
execSync/curl.exewith Nativefetchin CCTV Image ProxyIssue
The CCTV image proxy (
src/app/api/cctv/proxy/route.ts:77) contained a critical command injection vulnerability and a cross-platform compatibility issue.The
curlFetchfunction executed a shell command usingexecSync:This introduced two separate problems:
curl.exeis the Windows binary name and does not exist on Linux, causing production deployments to fail.urlwas interpolated directly into a shell command, creating a command injection vulnerability.Fix
Replaced the
execSync/curl.exeimplementation with the native asynchronousfetchAPI.Changes include:
child_processimport.lenientFetch(url)helper built onfetch.AbortController.ALLOWED_HOSTSallowlist before issuing the request, preventing SSRF.Behavior
cdn.skylinewebcams.com)curl.exenot found)200)403 {"error":"Forbidden domain: ..."}urlparameter400 {"error":"Missing url parameter"}400 {"error":"Invalid URL"}AbortControllerFiles Changed
src/app/api/cctv/proxy/route.tsexecSync/child_processusage and replacedcurlFetch()with asynclenientFetch()using the nativefetchAPI.Verification
npm test— 9 passed, 1 skippednpm run build— Compiled successfullycurltesting — Success path and all error cases verified