← back

Java4Shell: A Bug AI Found Twice, Five Years Apart

11 min read#security #cve #ai #java #jvm

On November 17, 2026, a security firm called Calif disclosed Java4Shell (CVE-2026-114938): a memory-corruption bug in OpenJDK's Base64 decoder that chains into pre-auth remote code execution on Keycloak, Jira, Confluence, Artifactory, Jenkins, and PingFederate in their default configs (Calif). Java is famous for being memory-safe. This bug lives in the 64 bytes of hand-written x86-64 assembly where that promise quietly stops applying.

Two things about it are worth more than the CVE number. First, the vulnerable code was merged into OpenJDK in June 2021 (OpenJDK PR #4368, per Aikido) and shipped quietly for five years before anyone noticed. Second, a fix for it sat open and unmerged on GitHub for two months before disclosure, and in that window the same bug was found independently at least three times, once by a human reviewer, once by Calif's AI agent, once by Chainguard's (Chainguard).

This post is a technical walkthrough of the bug, and a look at what it says about where AI actually sits in the vulnerability pipeline right now: it found the exploit, and - in a separate experiment a security vendor ran after the fact - it would also have found the bug in code review, five years earlier, for about the cost of a coffee.

The bug, in one picture

OpenJDK's java.util.Base64.Decoder has a slow, safe, pure-Java path and a fast path. Once the JIT compiler (C2) notices you're decoding Base64 a lot, it swaps in intrinsics: hand-written machine code using AVX-512 VBMI instructions, which decode up to 64 bytes per CPU cycle instead of looping byte by byte. This only exists on x86-64 chips with AVX-512 VBMI - Intel Ice Lake and newer Xeons, AMD Zen 4 and newer. ARM64 never runs this code at all.

The decoder processes input 64 bytes at a time. For the last, short chunk, it has to compute a mask telling the CPU's masked-store instruction (evmovdqub - vectorized move of doubleword-bytes, unaligned) which of the 64 lanes to actually write. Get the mask right and it writes only the valid output bytes. Get it wrong, and evmovdqub is happy to write all 64 lanes into memory that was never allocated for them.

Here's the mask logic, lightly adapted from Calif's write-up:

// Zero High Bits starting with Specified bit position
input_mask  = bzhiq(-1, input_length);
output_len  = (input_length / 4) * 3;

// strip trailing '=' padding
if (input[input_length - 1] == '=') {
    output_len  -= 1;
    input_mask >>= 1;
    if (input[input_length - 2] == '=') {
        output_len  -= 1;
        input_mask >>= 1;
    }
}
output_mask = bzhiq(-1, output_len);

bzhiq(-1, n) means "set the low n bits of all-ones, zero the rest" - that's how the mask is built. Feed it a padded tail shorter than one full 4-character block - say, 64 valid characters followed by a lone = - and output_len computes to 0, then gets decremented for the padding to -1. bzhiq treats any n >= 64 as "don't touch any bits," so bzhiq(-1, -1) comes back as 0xFFFFFFFFFFFFFFFF. Every one of those 64 lanes is now marked "write me."

For a 65-byte input ("A" * 64 + "="), the runtime had already allocated a precise 50-byte output buffer. The intrinsic writes a full 64-byte block starting at offset 48. That's 62 bytes written past the end of the array - bytes the application never asked for, in memory it doesn't own.

On OpenJDK 17, the JIT's threshold for switching to the vector path is higher, so the trigger needs 128 As instead of 64. Everywhere else - 21, 25, 27 - one block plus a short tail does it.

From "wrote some bytes" to "pre-auth RCE"

The overflow writes a fixed, attacker-uncontrolled pattern - you don't get to choose the bytes, only where the write lands relative to your input. Calif's writeup describes this as looking "borderline unexploitable" at first: a write primitive with zero control over its contents is usually a crash, not a shell.

The escalation path they used is a straight port of a technique from browser-engine exploitation (a parallel Calif itself draws), applied to the JVM heap instead of a JS heap:

Corrupt one array's length field and the array keeps its original backing memory but now thinks it's bigger - every read or write through it reaches past its real bounds. Point that at a neighboring object whose contents get echoed back to the client, and you have a heap-memory leak before you've executed a single instruction - Calif calls this primitive JavaBleed, after Heartbleed. Point it at the JVM's Code Cache, where compiled native methods live, and a bounded-but-chosen-value write becomes RCE.

None of this is a generic payload. Calif is explicit that there's no universal exploit - every target needs its own reachable decoder call, a writable buffer in a useful position, some channel that leaks data back, and a specific heap layout. That's also, not coincidentally, why they published the mechanism but withheld the per-product weaponized chains.

A $200, one-hour bug hunt

Here's the part that's actually new. Calif's Quang Luong didn't find this by reading Base64 code looking for Base64 bugs. He pointed Codex at broad, hard-to-audit surface area - the JIT compiler, intrinsics, widely used APIs, cryptography - the way, in his words, "any serious security researcher in 2026" would, and let the agent report back:

Most early results Codex brought me were slops, either unreachable or the requirement of exploitation is not realistic at all. [...] So I just prompted harder.

Twenty minutes of prompting-and-discarding later, Codex surfaced the Base64 memory corruption. Discovery took about an hour. A working exploit took two more. Total token spend: under $200.

This is also, to be fair, not a story where the human did nothing. Calif frames it as "the centaur hacker" - the AI supplies raw horsepower and breadth, the human supplies judgment about what's worth chasing and how to turn a crash into a chain. The heap-grooming, the JavaBleed trick, the Code Cache targeting - that part reads like a specialist's expertise, assisted rather than replaced.

Meanwhile, five years earlier

Here's where it gets uncomfortable. A week after Calif's disclosure, the application-security vendor Aikido published a different experiment with the same bug (Aikido):

They traced the vulnerable code to the exact PR that introduced it - openjdk/jdk#4368, merged June 25, 2021 - forked OpenJDK at that commit, and reconstructed that same pull request with the original diff and description, author and reviewer names swapped for placeholders. Then they pointed their automated code-review tool, Deep Review, at it. Isolated from the internet - no searching for "Java4Shell," no cheating off the November disclosure.

Deep Review left three comments. One of them was this bug, described correctly: a non-MIME input ending in invalid padding causing an integer underflow in the AVX-512 decoding path, producing a bad output mask, writing past the destination buffer. Its suggested fix - check whether the remaining input is under 4 bytes and fall back to the scalar path - is, character for character except for one equivalent comparison operator, the same patch OpenJDK shipped on November 17 (JDK-8393212).

The other two comments flagged separate, real defects in the same PR: an oversized vectorized write that could exceed its destination region, and an input-validation gap where one of four AVX-512 lanes skipped the invalid-character check. Both have since been independently fixed upstream too.

One AI agent, aimed at production, found a critical bug and helped weaponize it into working RCE chains across half a dozen household-name products. A different AI tool, aimed backward at a five-year-old pull request, found the same bug with the same suggested fix - and would have, in principle, caught it before a single line shipped.

This wasn't even found once

The timeline above has a detail that matters more than either AI result: a fix for this exact bug sat unmerged on GitHub for two months before anyone disclosed anything. Someone opened openjdk/jdk#32781 on September 9, proposing essentially the same guard that eventually shipped. It was auto-closed without being merged - the kind of thing that happens to contributions that don't get picked up by a committer in time. The bug stayed live in every shipped build for another two months while that PR sat there.

Then Calif's agent found it on October 30. Chainguard's independent research found it on November 13, with no knowledge of Calif's work. Chainguard's own framing: "This bug was found three different times in the last few weeks. [...] Simultaneous discovery is becoming the new norm."

That's the real shift, and it's bigger than any one tool. The cost of finding a critical memory-safety bug in one of the most heavily audited runtimes on Earth has dropped to roughly the price of lunch. Which means the question "did anyone already find this bug?" used to have a reassuringly small answer space - now the honest answer is "assume yes, assume more than one party, assume you don't know who."

Am I affected?

Java4Shell needs both a vulnerable JDK and a CPU that runs the AVX-512 VBMI path at all. If either side is missing, the bug is unreachable.

CPU check (Linux):

grep -m1 '^flags' /proc/cpuinfo | tr ' ' '\n' \
  | grep -E '^(avx512f|avx512bw|avx512vbmi|bmi2)$'

All four flags present means Intel Ice Lake/Sapphire Rapids/Emerald Rapids/Granite Rapids-class, or AMD Zen 4+. Nothing printed means you're not exposed to this one, full stop - ARM64 included.

JDK check - affected if you're on OpenJDK 17.0.6 or newer (the AVX-512 decoder was backported there in January 2023), including every build derived from it: Amazon Corretto, Eclipse Temurin, Microsoft Build of OpenJDK, Azul Zulu, BellSoft Liberica, SAP SapMachine, Red Hat OpenJDK, Oracle OpenJDK, Oracle Java SE, Oracle GraalVM for JDK.

LineStatus as of Nov 17-18
Oracle Java SE / GraalVMFixed: 8u511.33-perf, 17.0.21.1, 21.0.13.1, 25.0.5.1, 27.0.1.1
OpenJDK mainlineFixed, jdk-27.0.1.1-ga carries JDK-8393212
jdk17u / jdk21u / jdk25uFix not yet backported as of disclosure day - check before assuming you're clear
Eclipse TemurinCheck vendor advisory directly; status varied by line at disclosure

Immediate mitigations if you can't patch yet:

  • -XX:-UseBASE64Intrinsics - disables the accelerated path entirely, falls back to safe Java. Costs some Base64 throughput, costs nothing in correctness.
  • -XX:UseAVX=2 - steps down from AVX-512 to AVX2, sidestepping only the vulnerable path. x86-64 only - OpenJDK on ARM doesn't recognize the flag and refuses to start.

Request buffering at your reverse proxy is not a general mitigation here - Calif notes some targets (Elasticsearch, for one) process a complete request body in one shot regardless, and WebSocket upgrades bypass body buffering entirely once the tunnel is open.

As of the write-ups above, NVD had the record at CVSS 3.1 8.1 and it was not yet in CISA's KEV catalog - Calif's own CVSS 4.0 self-score is 9.2, and multiple writeups note the two scores describe somewhat different things. No confirmed in-the-wild exploitation had been reported at disclosure, for whatever a number of days' head start is worth against a now-public technique.

What this changes

I wrote a previous post about CVE volume trending up with no end in sight. Java4Shell is a single, concrete data point for the mechanism behind that trend, from both directions at once:

Attack got cheaper. A critical, chainable RCE in a runtime used by most of the Fortune 500, for under $200 in model tokens and about three hours of a skilled human's time directing an agent. That ratio - human judgment plus cheap, tireless exploration - is not going back up.

Defense got cheaper too, if you aim it backward. The same category of tool, pointed at your own git history instead of someone's production endpoint, can re-review a five-year-old merged PR in isolation and land on the actual bug with the actual fix. The gap isn't model capability. It's that almost nobody runs this kind of review against code that already shipped - only against new pull requests, if that.

Neither side of this needed a frontier breakthrough. Both runs used off-the-shelf coding agents against code that was always sitting there, in public, for anyone to read. The asymmetry that mattered wasn't AI capability - it was who pointed it where, and when.

Sources

press s to toggle scanlines

this site also runs in your shell: $ curl zvdy.vercel.app