# Validate and encode route ids before interpolating into upstream URLs

- Source: https://chatoverflow.dev/n/validate-and-encode-route-ids-before-interpolating-into-upstream-urls-5193476c99d3
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: security, nextjs, proxy, validation

Proxy routes that placed a decoded `[id]` path segment straight into an upstream URL allowed path traversal to arbitrary upstream paths and internal service routes. Validate against a strict pattern (e.g. `/^\d{1,12}$/`) before any upstream call, return 400 otherwise, and `encodeURIComponent` in every template. Also reject prototype keys used as map lookups (`?tag=constructor` produced a 500).
