GHSA-595m-wc8g-6qgc WeKnora is Vulnerable to SSRF via Redirection
SummaryThe application's "Import document via URL" feature is vulnerable to Server-Side Request Forgery (SSRF) through HTTP redirects. While the backend implements comprehensive URL validation (blocking private IPs, loopback addresses, reserved hostnames, and cloud metadata endpoints), it **fails to validate redirect targets**. An attacker can bypass all protections by using a redirect chain, forcing the server to access internal services. Additionally, Docker-specific internal addresses like `host.docker.internal` are not blocked.DetailsThe `/api/v1/knowledge-bases/{id}/knowledge/url` endpoint validates the initial URL but follows HTTP redirects without re-validating the destination. This allows attackers to:Submit a URL to an attacker-controlled domain (passes validation)Have that domain respond with a 307 redirect to an internal serviceThe backend automatically follows the redirect without checking if the destination is restrictedThe internal service response is exposed to the attackerValidation GapsThe `IsSSRFSafeURL()` function (in `internal/utils/security.go`) validates the initial URL thoroughly, but there's no validation of HTTP redirect targets`host.docker.internal` is not in the `restrictedHostnames` listDocker-specific IP ranges (172.17.0.0/16 for bridge networks) are not explicitly blockedThe code validates `parsed.Hostname()` from the initial URL, but redirect Location headers bypass this checkRoot Cause AnalysisThe backend makes the security mistake of trusting the server's HTTP client library to be secure. In Go, when using http.Get() or similar functions, the standard library will automatically follow redirects up to 10 times by default. The SSRF validation only checks the URL passed to the endpoint, not intermediate redirects.PoC**Step 1**: Set up an attacker-controlled server that responds with a redirect:**Step 2**: Send the request with a clean URL:The URL `https://attacker-domain.com` passes all validation checks because:
✓ Valid `https://` scheme
✓ Not an IP address (it's a domain)
✓ Not in restricted hostnames
✓ Doesn't resolve to a private IP (assuming attacker controls a public domain)**Step 3**: The backend's HTTP client follows the redirect to `http://host.docker.internal:7777`, which:
✗ Is not validated
✗ `host.docker.internal` is not in the blocklist
✗ Successfully accesses the internal serviceImpactVulnerability Type: Server-Side Request Forgery (SSRF) via HTTP Redirect**Who is Impacted**:The organization running the applicationInternal services and databases accessible from the application containerServices in the Docker network (other containers, internal infrastructure)Sensitive data stored in internal services**Potential Consequences**:Access to internal databases (PostgreSQL, MongoDB, MySQL) running in DockerInformation disclosure from internal services (Redis cache, configuration servers)Access to Docker container metadata and environment variablesLateral movement to other containers in the same Docker networkExfiltration of sensitive configuration, API keys, or database credentialsPotential RCE if internal services have exploitable vulnerabilities
CVSS v3.1 score: 5.9