CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-3419
5.3

CVE-2026-3419: Content-Type Validation Bypass in Fastify via Regex Anchor Missing

Alon Barad
Alon Barad
Software Engineer

Mar 6, 2026·4 min read·3 visits

PoC Available

Executive Summary (TL;DR)

Fastify versions prior to 5.8.1 incorrectly validate `Content-Type` headers due to a missing regex anchor. Attackers can append arbitrary garbage to media types (e.g., `application/json<script>`) to bypass validation logic while still triggering JSON parsing.

Fastify, a high-performance web framework for Node.js, contains a validation bypass vulnerability in its `Content-Type` header parsing logic. Due to an incomplete regular expression in `lib/content-type.js`, the framework fails to enforce the end-of-string anchor (`$`) when validating media subtypes. This omission allows attackers to supply malformed `Content-Type` headers containing illegal trailing characters (e.g., `application/json garbage`), which Fastify incorrectly accepts as valid. This behavior violates RFC 9110 §8.3.1 and can lead to parser confusion where malicious payloads are routed to incorrect content parsers, potentially bypassing security controls or triggering unexpected application behavior.

Vulnerability Overview

CVE-2026-3419 identifies a medium-severity validation flaw in the Fastify web framework's handling of HTTP Content-Type headers. The vulnerability resides in the core library's MIME type parsing mechanism, specifically where it validates the subtype portion of a media type (the json in application/json).

Under RFC 9110, a media type must conform to strict syntax rules, essentially type/subtype. Fastify attempts to validate this structure using regular expressions. However, the regex used for the subtype validation failed to assert the end of the input string. Consequently, the parser performs a prefix match rather than an exact match.

This flaw allows a client to send a header like Content-Type: application/json unknown-suffix. While a strictly compliant server would reject this as an invalid media type (returning HTTP 415), vulnerable versions of Fastify validate the json prefix and accept the header. This discrepancy permits malformed requests to proceed to the body parsing stage, potentially confusing downstream logic or logging systems that expect RFC-compliant headers.

Root Cause Analysis

The root cause is a classic Regular Expression Anchoring error (CWE-185) located in lib/content-type.js. The regular expression subtypeNameReg was designed to validate that the subtype consists only of allowed characters (alphanumerics and specific symbols like !#$%&'*+.^|~-`).

The vulnerable definition was:

const subtypeNameReg = /^[\w!#$%&'*+.^`|~-]+\s*/

This regex uses the start-of-string anchor (^) but omits the end-of-string anchor ($). In JavaScript's RegExp engine, this instructs the matcher to verify that the string starts with valid characters, but it does not constrain what follows those characters. If the input is json garbage, the engine matches json against the allowed character class and considers the pattern satisfied, ignoring the trailing garbage.

Correct validation requires ensuring the entire string matches the allowed pattern. By missing the $, Fastify effectively downgraded its validation from "is exactly this format" to "starts with this format," opening the door for arbitrary suffix injection.

Code Analysis

The remediation involves a single-character change to the regular expression in lib/content-type.js. The patch enforces strict equality by appending the $ anchor, ensuring the regex matches the full string length.

Below is the comparison of the vulnerable and patched code:

// Vulnerable Code (lib/content-type.js)
// The regex matches any string starting with valid subtype characters.
// Input "json malicious" -> MATCH (Vulnerable)
const subtypeNameReg = /^[\w!#$%&'*+.^`|~-]+\s*/
 
// Patched Code (Fixed in v5.8.1)
// The '$' anchor ensures the string ends immediately after the valid characters.
// Input "json malicious" -> NO MATCH (Secure)
const subtypeNameReg = /^[\w!#$%&'*+.^`|~-]+\s*$/

When subtypeNameReg.test(subtype) is called in the fixed version, the engine consumes the valid characters and then checks for the end of the string. If unauthorized characters (like spaces followed by text, or control characters) are present, the match fails, and Fastify correctly identifies the media type as invalid.

Exploitation Scenarios

Exploitation of this vulnerability requires an attacker to send HTTP requests with crafted Content-Type headers. The primary goal is to bypass strict validation checks while still triggering a specific content parser (usually the JSON parser).

Attack Scenario: Parser Confusion

  1. Setup: A Fastify server is configured to parse application/json. It may have security middleware that blocks requests with unknown content types but uses the same loose validation logic.
  2. Execution: The attacker sends a request with Content-Type: application/json; boundary=exploit (syntactically incorrect for JSON) or Content-Type: application/json<script>.
  3. Result: Fastify validates the header as application/json because of the prefix match. The request is routed to the JSON parser.

This behavior is particularly risky if the application relies on the Content-Type header for security decisions (e.g., "only allow strictly application/json") or if the malformed header bypasses a WAF rule that expects strict RFC compliance but the application accepts it, creating a differential allowing the payload through.

Impact Assessment

The impact of CVE-2026-3419 is classified as Medium (CVSS 5.3). While it does not directly allow Remote Code Execution (RCE) or SQL Injection, it compromises the integrity of the input validation layer.

Technical Impact Breakdown:

  • RFC Violation: The server accepts traffic that violates HTTP standards (RFC 9110), making it non-compliant.
  • Security Bypass: Security controls relying on strict content-type definition can be circumvented. For example, a WAF might block application/x-www-form-urlencoded to prevent parameter pollution, but if an attacker sends application/json payload, and the server parses it as form data due to a misconfiguration or fallback, the protection is bypassed.
  • Log Injection / Obfuscation: Malformed headers (e.g., application/json\x00garbage) may corrupt logs or mislead analysts reviewing traffic logs.

CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N

  • Confidentiality: None.
  • Integrity: Low (Modification of interpreted request metadata).
  • Availability: None.

Official Patches

FastifyCommit 67f6c9b3 fixing the regex validation
FastifyOfficial GitHub Security Advisory

Fix Analysis (1)

Technical Appendix

CVSS Score
5.3/ 10
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N

Affected Systems

Fastify Framework (Node.js)

Affected Versions Detail

Product
Affected Versions
Fixed Version
Fastify
OpenJS Foundation
< 5.8.15.8.1
AttributeDetail
CWE IDCWE-185
CWE NameIncorrect Regular Expression
CVSS v3.15.3 (Medium)
Attack VectorNetwork
ImpactValidation Bypass
StatusPatched

MITRE ATT&CK Mapping

T1190Exploit Public-Facing Application
Initial Access
CWE-185
Incorrect Regular Expression

The software uses a regular expression that contains an error, or the regex does not correctly adhere to the intended logic, leading to inaccurate matches.

Known Exploits & Detection

GitHubThe fix commit includes test cases acting as PoC, such as 'application/json<script>alert(1)</script>'

Vulnerability Timeline

Fix commit merged into Fastify main
2026-03-05
Fastify v5.8.1 released
2026-03-05
CVE-2026-3419 and GHSA published
2026-03-06

References & Sources

  • [1]GHSA-573f-x89g-hqp9
  • [2]NVD - CVE-2026-3419
  • [3]RFC 9110 §8.3.1

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.