Back to Blog
critical SEVERITY5 min read

How Server-Side Request Forgery (SSRF) happens in Node.js API proxies and how to fix it

A critical SSRF vulnerability was discovered in server.js where the API proxy endpoint constructed target URLs from user-controlled path parameters without validating the final origin. Attackers could use URL encoding tricks like `/api/%2F%2Fevil.com` to redirect proxy requests to arbitrary hosts, potentially accessing cloud metadata services or internal resources. The fix adds origin validation to ensure all proxied requests only reach the intended openrouter.ai upstream.

O
By Orbis AppSec
•Technically reviewed by Anupam Mediratta•Published August 28, 2026•Reviewed August 28, 2026

Answer Summary

This is a Server-Side Request Forgery (SSRF) vulnerability (CWE-918) in a Node.js/Bun.js API proxy that allowed attackers to manipulate URL paths to redirect requests to unintended hosts. The vulnerable code in server.js concatenated user-controlled path segments directly into target URLs without validating the final destination origin. The fix parses the constructed URL as a URL object and validates that `targetUrl.origin` equals `"https://openrouter.ai"` before forwarding the request.

Vulnerability at a Glance

cweCWE-918
fixParse URL and validate origin matches expected upstream before proxying
riskAttackers can redirect proxy requests to internal services or cloud metadata endpoints
languageJavaScript (Bun.js)
root causeURL constructed from user input without origin validation
vulnerabilityServer-Side Request Forgery (SSRF)

Introduction

The server.js file in this Node.js library implements an API proxy that forwards client requests to OpenRouter's API. However, a flaw in how the proxy constructed target URLs from the request pathname created a critical Server-Side Request Forgery vulnerability at line 92.

The vulnerable code extracted the path after /api and concatenated it directly into the target URL:

const targetPath = pathname.slice(4); // remove /api prefix
const targetUrl = `https://openrouter.ai/api${targetPath}${url.search}`;

This pattern seems safe at first glance—after all, the base URL is hardcoded to openrouter.ai. But URL parsing rules create an unexpected attack vector that could allow requests to any host on the internet, making this a serious concern for any downstream consumers of this package.

The Vulnerability Explained

How String Concatenation Betrays You

The vulnerability lies in how browsers and HTTP clients parse URLs. When you concatenate user input into a URL string, the resulting URL might resolve to a completely different host than you intended.

Consider what happens when an attacker sends a request to:

/api/%2F%2Fevil.com%2Fmalicious

The %2F is URL-encoded /. After the proxy processes this:

  1. pathname.slice(4) extracts %2F%2Fevil.com%2Fmalicious
  2. String concatenation produces: https://openrouter.ai/api%2F%2Fevil.com%2Fmalicious
  3. When this string is used to make an HTTP request, URL parsing may decode and interpret //evil.com as a protocol-relative URL or authority component

Even more concerning, attackers could target cloud metadata services:

/api/%2F%2F169.254.169.254%2Flatest%2Fmeta-data%2F

This could allow access to AWS/GCP/Azure instance metadata, potentially exposing IAM credentials, API keys, and other sensitive configuration.

Real-World Attack Scenario

Imagine this library is used in a production application running on AWS EC2:

  1. Attacker discovers the /api/* proxy endpoint
  2. Attacker crafts a request: GET /api/../../../latest/meta-data/iam/security-credentials/
  3. The proxy forwards this to what it thinks is OpenRouter, but URL parsing tricks redirect it to 169.254.169.254
  4. The response contains temporary AWS credentials
  5. Attacker now has access to AWS resources with the EC2 instance's IAM role permissions

This is not theoretical—SSRF attacks against cloud metadata services are one of the most common vectors for cloud account compromise.

The Fix

The fix adds explicit origin validation after URL construction. Here's the before and after:

Before (Vulnerable)

const targetPath = pathname.slice(4); // remove /api prefix
const targetUrl = `https://openrouter.ai/api${targetPath}${url.search}`;

After (Secure)

const targetPath = pathname.slice(4); // remove /api prefix
const targetUrl = new URL(`https://openrouter.ai/api${targetPath}${url.search}`);
// Ensure path manipulation (e.g. encoded "//host" tricks) can never
// redirect the proxy to a different origin than the intended upstream.
if (targetUrl.origin !== "https://openrouter.ai") {
  return new Response("Forbidden", { status: 403 });
}

Why This Works

The key insight is using the URL constructor to parse the concatenated string, then checking the origin property. The URL object applies standard URL parsing rules, resolving any encoding tricks or path traversal attempts. If the final parsed origin doesn't match https://openrouter.ai, the request is blocked with a 403 Forbidden response.

This approach is robust because:

  1. It validates after parsing: No matter what encoding tricks an attacker uses, the final resolved origin is checked
  2. It uses the URL API: The standard URL constructor handles all edge cases in URL parsing
  3. It fails closed: Any unexpected origin results in rejection, not a best-effort forward
  4. It preserves functionality: Legitimate requests to OpenRouter's API continue to work unchanged

Key Takeaways

  • URL string concatenation with user input is dangerous — even with a hardcoded base URL, encoding tricks can redirect to arbitrary hosts
  • The server.js proxy at line 92 was vulnerable because it concatenated targetPath without validating the final parsed origin
  • Always validate URL.origin after construction when building URLs from untrusted input
  • Cloud metadata endpoints (169.254.169.254) are prime SSRF targets that can expose IAM credentials
  • This fix preserves all legitimate functionality while blocking malicious path manipulation attempts

How Orbis AppSec Detected This

  • Source: HTTP request path parameter extracted via pathname.slice(4) in server.js
  • Sink: URL string concatenation used in HTTP proxy request at server.js:92
  • Missing control: No validation that the constructed URL's origin matched the intended upstream host
  • CWE: CWE-918 (Server-Side Request Forgery)
  • Fix: Added URL parsing and origin validation to ensure proxied requests only reach https://openrouter.ai

Orbis AppSec automatically detected this vulnerability and opened a pull request with the fix. Try Orbis AppSec on your repositories to find and fix issues like this automatically.

Conclusion

This SSRF vulnerability demonstrates why URL construction requires careful handling. What appeared to be a safely hardcoded proxy destination was actually exploitable through URL encoding tricks. The fix—parsing the URL and validating its origin—is simple, robust, and preserves all legitimate functionality.

For developers building API proxies or any code that constructs URLs from user input: always validate the final parsed URL, not just the input string. The URL API is your friend—use it to parse, then verify the result matches your expectations before making any requests.

Prevention and further reading

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #2

Related Articles

high

axios 1.18.1 CVE-2026-101898: HTTP/2 Ignores proxy and lookup

A dependency upgrade moved `axios` from 1.18.1 to 1.20.0 to pick up the fix for CVE-2026-101898, in which proxy and DNS resolution settings supplied through axios request configuration were not applied on the HTTP/2 request path. Applications that rely on `config.proxy`, `HTTP_PROXY`/`NO_PROXY` environment variables, or a custom `lookup` function as an SSRF or egress control could have those controls silently skipped for HTTP/2 requests.

critical

Cloudflare Worker Reverse Proxy SSRF via String Concatenation

A Cloudflare Worker reverse proxy built its upstream request URL by string-concatenating an environment variable with the incoming request's pathname and search string, letting a crafted path or query redirect requests to attacker-chosen hosts. The fix replaces concatenation with the `URL` object's `pathname` and `search` setters, which normalize input against the configured origin instead of blindly appending it.

high

fast-uri 3.1.2 IDN Host Bypass: CVE-2026-13676 Upgrade

A dependency tree in this repository resolved `fast-uri` 3.1.2, a version affected by CVE-2026-13676, in which improper Unicode hostname canonicalization lets a crafted URI parse to one host while the HTTP client connects to another. Because `fast-uri` is what `ajv` uses to parse and resolve URIs for `format: "uri"` validation and `$ref` resolution, any host allowlist built on its parsed output could be bypassed. The fix upgrades the resolved copy to `fast-uri` 4.1.4 and pins it with an npm `ove

high

boardcards.js parseArgs() SSRF: --board Flag Reaches Metadata IPs

The `parseArgs()` function in boardcards.js accepted a user-controlled `--board` command-line argument and passed it directly to fetch() calls without validating the URL scheme or hostname. An attacker could supply `http://169.254.169.254/latest/meta-data/` or other internal addresses to extract cloud credentials or scan internal networks.

high

fetch() with Automatic Redirects Leaks HTTPS Trust to api.tomys.top

The `withProxy()` fetch wrapper allowed automatic HTTP redirects from `api.tomys.top`, trusting the external API's domain integrity without validating final destinations. A compromised or malicious redirect response could send users to attacker-controlled phishing sites while maintaining HTTPS protocol and hostname checks that falsely appear secure.

high

Meta.get() Honored @uploadURL From Script Headers: SSRF Fix

A userscript manager's metadata parser accepted the `@uploadURL` directive from a script's own header block, so any installed or auto-updated script could silently redirect the options-page `uploadScript()` fetch to an attacker-chosen destination — including loopback, link-local metadata endpoints, and LAN addresses. The fix makes `Meta.get()` ignore `@uploadURL` when it appears in a script header, leaving the User Metadata field (validated in `Meta.getUserMeta()`) as the only way to set it, and