Summary
fast-uri can serialize an untrusted URI port value without verifying that it contains only digits. A malformed port may inject authority delimiters, reinterpret the intended host as user information, and redirect the resulting URI to an attacker-controlled host when applications build URIs from separate components.
Affected context
The issue can occur in applications that use fast-uri object-form APIs to serialize, normalize, or compare URIs assembled from individual components. Risk increases when an untrusted value is assigned to the port field and the resulting URI is later used for routing, fetching resources, authentication decisions, or security validation. Re-parsing the generated URI may not reveal the problem because URI parsers can accept the recomposed authority and interpret the attacker-controlled host as valid.
Exploit preconditions
- Attack surface: Application code that constructs URIs from structured components through fast-uri.
- Required access: Ability to influence the port component supplied to the serialize, normalize, or equal object forms.
- Trigger point: Authority recomposition followed by use or interpretation of the generated URI.
- Why exploitation is possible: The port is concatenated without the encoding and syntax validation applied to other authority components, allowing delimiter characters to alter authority parsing.
Why this happens
The vulnerability is caused by inconsistent validation and escaping during URI authority serialization. Although the userinfo and host components are escaped, the port component is emitted verbatim rather than being restricted to the digit sequence permitted by RFC 3986. This is an instance of CWE-116: Improper Encoding or Escaping of Output, because attacker-controlled data is incorporated into a structured URI without preserving the intended component boundaries.
Potential impact
- The generated URI may resolve to an attacker-controlled host.
- Applications could send requests or credentials to an unintended destination.
- Host-based allowlists, routing logic, or security checks may be bypassed.
- Server-side request forgery-like behavior could occur where the URI is used for outbound requests.
- Authentication, logging, or audit decisions could be based on a misleading URI interpretation.
General mitigation guidance
Mitigation generally focuses on preserving URI component boundaries and reducing trust in externally supplied components.
Common defensive patterns include:
- Restricting port values to a validated sequence of decimal digits before serialization.
- Using a URI recomposition implementation that rejects invalid port syntax rather than emitting it.
- Treating host, userinfo, port, and other authority fields as separate typed values throughout application logic.
- Avoiding security decisions based solely on re-parsing a URI that was assembled from untrusted parts.
- Applying destination allowlists after canonicalization and validating the final authority against the intended destination.
- Running outbound URI consumers with least privilege and appropriate network egress controls.
- Using a maintained fast-uri release that includes strict port validation, without relying on downstream re-validation alone.
How teams detect issues like this
Detection approaches can include:
- Static analysis for object-form URI construction where user-controlled data reaches a port property.
- Code review checks for URI fields concatenated or serialized without component-specific validation.
- Tests covering non-numeric, delimiter-containing, empty, and boundary port values.
- Policy enforcement requiring structured URI builders to reject invalid authority components.
- Runtime monitoring for generated requests whose effective host differs from the application's intended host.
- Automated dependency and code review tools that flag vulnerable fast-uri usage patterns and outdated dependency ranges.

