Protection

8 min readUpdated

What is virtual patching? How a WAF rule buys time before the real fix

Quick answer

Virtual patching is a security rule, usually in a web application firewall or reverse proxy, that blocks requests exploiting a known vulnerability without changing the vulnerable code. OWASP describes it as a policy enforcement layer that buys time while the real fix is built, tested and deployed. It works best when an exploit needs a distinctive request feature, and poorly when the trigger can be rephrased endlessly or lives in business logic.

01What is virtual patching?

OWASP defines virtual patching as a security policy enforcement layer that detects and blocks exploitation attempts against a known vulnerability without changing the vulnerable code. The code stays exactly as it is; the patch is a rule in front of it that refuses the requests an attacker needs.

The rule can live in an intermediary such as a web application firewall or an intrusion prevention system, in a web server module, or in a filter inside the application. Whatever the location, a virtual patch is not a fix. OWASP is explicit that code fixes and virtual patching are not mutually exclusive, and that a virtual patch covers only the traffic that passes through the layer enforcing it.

02Why do teams use virtual patching?

To close the gap between disclosure and a deployed fix. Attackers move fast: Cloudflare saw a Log4Shell exploitation attempt nine minutes after public disclosure, and earlier attempts eight days before it. A fix that waits for next week's change window leaves days of exposure. A second use is noise reduction: after a large disclosure, scanning for the flaw starts quickly, and a narrow rule turns away the opportunistic probes while the team works through the real patch.

OWASP lists the usual reasons a code fix cannot happen at once, and operations adds a few more:

  • The vendor has not shipped a fix yet, or the first fix is incomplete and follow-up releases are coming.
  • A fix exists but needs testing, a change window or a dependency upgrade that cannot happen today.
  • The software belongs to a third party, so the team cannot change its code.
  • The application is legacy or out of support, and nobody will patch it.
  • Development is outsourced, and any change means a new project cycle.

03How long is the gap? Real CVE timelines

The dates below come from the vendors' advisories, NVD and CISA's Known Exploited Vulnerabilities (KEV) catalogue, checked against the catalogue version of 23 October 2026. They show how different the gap can be, and how differently each flaw responds to a rule at the edge.

Two lessons stand out. Log4Shell was exploited before anyone outside the vendor knew to write a rule, so virtual patching starts at disclosure, never before it. And the quality of the rule depends on the bug, not on the tool: one internal header in Next.js was easy to filter, while a rich expression language in Log4j was not.

VulnerabilityKey datesDid a virtual patch help?
Log4Shell, CVE-2021-44228Disclosed 9 Dec 2021; attempts seen from 1 Dec; added to KEV 10 Dec; the first fix, 2.15.0, was followed by three more CVEsPartly: early rules blocked the plain string, then attackers rebuilt it with Log4j's own lookup syntax within days
Next.js middleware bypass, CVE-2025-29927Reported 27 Feb 2025; first fixes 17 to 18 Mar; made public 21 Mar; not in KEVYes: removing one internal header at the edge closes the bypass, as the vendor advised for anyone who could not upgrade
React2Shell, CVE-2025-55182Disclosed with fixes 3 Dec 2025; added to KEV 5 DecOnly as a stopgap: React's advisory said not to depend on hosting providers' temporary mitigations and to update immediately
PHP2Shell, CVE-2026-109618Published by NVD 21 Oct 2026, the day PHP released 8.2.35, 8.3.36, 8.4.27 and 8.5.12; not in KEVPartly: edge limits on multipart bodies narrow the demonstrated trigger, but NVD describes request memory left uninitialised by a condition that multiple out-of-memory strategies can reach, so no single request feature covers them all

04When does a virtual patch work well?

When the exploit needs something legitimate traffic never contains. The cleanest virtual patches match a fixed, low-variance feature, or allow only what the application expects; OWASP recommends that positive security model over a block list of known attack strings, which is faster to write but easier to evade.

In the test, the rule below returned 403 for the header in any letter case, and the stand-in upstream never received a client-supplied value. Test before blocking all the same: Cloudflare made its managed rule for this CVE opt-in because sites whose middleware used third-party authentication vendors saw failing requests. Run the rule in log-only mode first and check whether any middleware calls back through the same proxy.

  • A header, method or parameter that real clients never send, such as the internal header behind CVE-2025-29927.
  • A path that can simply be closed, such as an unused admin endpoint or a vulnerable plugin file.
  • A parameter with a strict format that can be allow-listed, such as an ID that must be digits.
  • A size or count limit that the exploit has to exceed.
A virtual patch for CVE-2025-29927 in nginx (passes nginx -t, nginx 1.22.1)
# Virtual patch: CVE-2025-29927 (Next.js middleware bypass).
# Remove once every instance runs 12.3.5, 13.5.9, 14.2.25, 15.2.3 or later.
location / {
    if ($http_x_middleware_subrequest) {
        return 403;
    }
    proxy_set_header Host $host;
    proxy_set_header X-Middleware-Subrequest "";   # never forward a client value
    proxy_pass http://nextjs_upstream;
}

05What can't virtual patching do?

A virtual patch has to recognise the attack in the request. OWASP calls injection-type flaws the best fit, provided a rule can pin down what a parameter may contain; the trouble starts when the dangerous syntax can be rebuilt after the filter, and some classes of bugs give a rule nothing reliable to recognise at all.

Every rule is also a trade between false positives and false negatives. OWASP asks for neither and accepts that the result is risk reduction, not elimination: a rule broad enough to catch every variant tends to block legitimate traffic, and one narrow enough to be safe can be sidestepped. That is why logic-heavy categories in the OWASP Top 10, such as broken access control, are poor candidates.

Bug classWhy an edge rule strugglesExample
Memory corruption in a runtime or libraryMany different inputs reach the same broken state; the trigger is a condition, not a stringPHP2Shell
Injection through a syntax the application expands laterThe payload can be rewritten, nested or encoded until it no longer matches, then expanded by the applicationLog4Shell lookups
Business logic and authorisationThe malicious request is well formed; only the application knows this user may not see that recordChanging an order ID in a URL
Flaws reached without crossing the filterInternal calls, other protocols or a directly reachable origin never meet the ruleLogged values that arrive from other systems
Payloads the filter cannot readEncodings, compression or body formats the enforcing layer does not decodeA body format the WAF does not parse

06How to deploy a virtual patch safely

OWASP's virtual patching cheat sheet splits the work into six phases: preparation, identification, analysis, virtual patch creation, implementation and testing, and recovery and follow-up. In day-to-day operations that comes down to a short checklist.

  • Confirm the application is affected: the version, the configuration and whether the vulnerable feature is reachable at all.
  • Write the narrowest rule that stops the exploit path, scoped to the affected host and route.
  • Run it in log-only mode first, as OWASP recommends, and compare its hits with known-good traffic.
  • Switch to blocking, and label the rule with the CVE ID, an owner and a removal date.
  • Watch for follow-up advisories; an incomplete first fix, as with Log4j 2.15.0, often means the rule must change too.
  • Remove the rule once the code fix is deployed and verified everywhere, so stale rules do not pile up.

07Virtual patching or patching: what comes first?

Both, in the order the situation allows. The table is a starting point for that decision; a WAF in front of the origin is what makes the middle column possible quickly, and it does not change the last one.

SituationDo nowThen
Fix available and deployable todayPatchAn optional rule to absorb scanning
Fix available, but testing or a change window is neededVirtual patchPatch in the window, then remove the rule
No vendor fix yet (zero-day)Virtual patch, and disable the vulnerable feature if possiblePatch when the fix is released
Unsupported or third-party applicationVirtual patch as a long-term compensating controlPlan a replacement
Logic or authorisation bugCode fixA rule only if the abusive request is unmistakable

Questions

Frequently asked questions

01Is virtual patching the same as a WAF?
No. A WAF is a tool, and virtual patching is one way of using it. A WAF also applies general rules against common attack classes, while a virtual patch is a specific rule written for one known vulnerability, usually for a limited time. Virtual patches can also live elsewhere: in an intrusion prevention system, a web server module or a filter inside the application.
02Does virtual patching stop zero-day exploits?
Only once the zero-day is known. A zero-day is a flaw attackers exploit before a fix exists, and a virtual patch needs a description of the attack to match. After disclosure, even without a vendor fix, a rule can block the published exploit path. Before disclosure, only general rules and anomaly controls have any chance of catching it.
03How long should a virtual patch stay in place?
Until the real fix is deployed on every affected system and verified, and then it should go. OWASP recommends periodic re-assessment to decide when earlier virtual patches can be removed. Stale rules cost performance, cause false positives as the application changes and hide which systems were actually patched. A removal date written on the rule keeps that honest.
04Can attackers get around a virtual patch?
Often, if the rule matches a string rather than the condition the exploit needs. After the first Log4Shell rules appeared, attackers rewrote their payloads with Log4j's own syntax so filters no longer recognised them. Rules that allow only the expected format, or remove the single feature an exploit depends on, are much harder to sidestep than block lists of known payloads.
05Who should write a virtual patch?
Someone who understands both the vulnerability and the application. The rule has to stop the exploit path without blocking legitimate requests, which takes the advisory, the list of affected routes and real traffic to test against. Managed WAF services publish rules for widely known CVEs, but custom applications usually need a rule written and tested by their own team.

Sources

Sources and verification

Checked on 13 November 2026 on Debian 12: the nginx configuration in “When does a virtual patch work well?” passes nginx -t (nginx 1.22.1). Other configuration, commands, log lines and output on this page are examples: adapt them to your system and check them before use.

  1. 01Virtual Patching Cheat Sheet · OWASP
  2. 02CVE-2021-44228 · NVD
  3. 03Exploitation of Log4j CVE-2021-44228 before public disclosure and evolution of evasion and exfiltration · Cloudflare
  4. 04Known Exploited Vulnerabilities catalogue (JSON feed) · CISA
  5. 05Postmortem on Next.js middleware bypass · Vercel
  6. 06GHSA-f82v-jwr5-mffw: Authorization bypass in Next.js middleware · GitHub Security Advisories
  7. 07New managed WAF rule for Next.js CVE-2025-29927 · Cloudflare docs
  8. 08Critical security vulnerability in React Server Components · React
  9. 09CVE-2026-109618 · NVD
  10. 10GHSA-w8hw-w9fx-j79w: RCE via OOM corruption (CVE-2026-109618) · PHP security team (GitHub Security Advisories)
  11. 11PHP news archive 2026 (security advisory and releases of 21 October 2026) · php.net

Last updated