Cache Key Injection Flaw in Nginx Configurations Allows Access Bypass, Data Disclosure and Cached Denial of Service

Security researcher Alex Brumen from YesWeHack has detailed a Cache Key Injection attack vector that exploits poorly constructed cache keys in Nginx. The issue arises when administrators concatenate variable-length values without delimiters, such as $scheme$host$request_uri$http_accept, allowing different requests to produce identical cache keys. Attackers can poison the cache with 404 responses to deliver CPDoS, expose restricted pages like /admin by manipulating path components, or even achieve stored XSS by colliding HTTP and HTTPS responses. The technique can also bypass Cloudflare protection when the Authorization header routes requests directly to the vulnerable Nginx cache. Mitigation requires using explicit delimiters or structured encoding in cache keys, validating the Host header, enforcing HTTPS redirects, and avoiding caching of authenticated requests.

AntiMalwareTranslated from Russian

Read at source

Security researcher Alex Brumen from YesWeHack has described a new attack vector called Cache Key Injection that targets custom Nginx cache configurations. The vulnerability does not affect default Nginx setups but emerges when administrators concatenate multiple variable-length values without separators, for example $scheme$host$request_uri$http_accept.

Because two different requests can generate the same cache key string, an attacker who submits a request to /h with the header Accept: ome*/* can create an identical key to a legitimate request for /home with Accept: */*. If the attacker first stores a 404 response in the cache, subsequent users receive the error page instead of the homepage until the entry expires, resulting in CPDoS — cache-poisoned denial of service.

The same technique can expose restricted areas. In a lab example, the page /admin was accessible only from localhost, yet an attacker could request /ad and shift the remaining characters into an adjacent key component. Nginx would treat the path as authorized while serving the cached admin-panel content.

Under certain conditions the attack can also merge HTTP and HTTPS requests, allowing an attacker to store a page containing a malicious JavaScript reference and thereby turn the misconfiguration into stored XSS. Even Cloudflare does not always protect against the issue, because an Authorization header can route a request past Cloudflare’s cache directly to the vulnerable Nginx instance.

Protection is straightforward: cache keys must incorporate delimiters or structured encoding, for instance $scheme|$host|$request_uri|$http_accept. Administrators should also validate the Host header, enforce HTTPS redirects, and refrain from caching authenticated requests.

Meridian digestThe week's most consequential security stories, distilled into one briefing.See the digest

More in Vulnerabilities & Exploits

Telegram for Android Patches Voice Call Vulnerability Enabling Code Execution
Yandex Patches Millions of Stations After eMudhra Certificate Keys Compromised
Cisco ASA and FTD Face DoS Vulnerability in SSL VPN Already Exploited in the Wild