Security: Fix SSRF vulnerability in media conversion endpoints#2104
Open
Yunkaiwjs wants to merge 1 commit into
Open
Security: Fix SSRF vulnerability in media conversion endpoints#2104Yunkaiwjs wants to merge 1 commit into
Yunkaiwjs wants to merge 1 commit into
Conversation
This commit addresses a Server-Side Request Forgery (SSRF) vulnerability in the media conversion endpoints that allowed authenticated users to make arbitrary HTTP requests to internal services. Changes: - Add URL validation in fetchBuffer() to block private IP ranges - Block access to localhost, 127.0.0.1, and cloud metadata endpoints - Enable certificate validation (rejectUnauthorized: true) - Disable automatic redirects (maxRedirects: 0) - Add scheme whitelist (http/https only) - Add 30-second timeout to prevent hanging requests Security Impact: - Prevents access to internal services (10.x, 192.168.x, 172.16-31.x) - Blocks cloud metadata endpoint access (169.254.169.254) - Prevents SSRF via redirect chains - Enables proper certificate validation for HTTPS requests Affected endpoints: - POST /api/:session/media/convert/voice - POST /api/:session/media/convert/video CVSS: 7.7 (High) - CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N CWE: CWE-918 (Server-Side Request Forgery) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a Server-Side Request Forgery (SSRF) vulnerability in the media conversion endpoints (
/api/:session/media/convert/voiceand/api/:session/media/convert/video) that allowed authenticated users to make arbitrary HTTP requests to internal services.Vulnerability Details
CVSS: 7.7 (High) -
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:NCWE: CWE-918 (Server-Side Request Forgery)
The
fetchBuffer()function insrc/utils/fetch.tsperformed no validation on user-provided URLs, allowing authenticated attackers to:Changes
Security Improvements
URL Validation - Added
validateUrl()function to check:Certificate Validation - Changed from
InsecureHttpsAgent(rejectUnauthorized: false) toSecureHttpsAgent(rejectUnauthorized: true)Redirect Protection - Set
maxRedirects: 0to prevent SSRF via redirect chainsTimeout - Added 30-second timeout to prevent hanging requests
Code Changes
src/utils/fetch.ts:validateUrl()function with comprehensive checksisPrivateIP()helper functionInsecureHttpsAgentwithSecureHttpsAgentmaxRedirects: 0andtimeout: 30000Testing
Tested with the following scenarios:
Impact
This fix prevents authenticated users from:
Backward Compatibility
Warning - Breaking Change: This fix will reject URLs pointing to private IP ranges and localhost. If your application legitimately needs to fetch from internal services, you may need to:
References