← Back to archive

/ 9 min read / apache struts · java · denial of service · cve

Ten bytes to OutOfMemoryError: CVE-2026-133641 in Apache Struts

A request-derived BigDecimal is expanded in full by Struts code that applies no digit bound, while the bound it needs sits private in a neighbouring class.

Summary

Apache Struts published S2-085 today with CVE-2026-133641. I reported it privately on 1 November, the PMC confirmed it as a vulnerability two days later, and the fix shipped in 7.5.0 and 6.13.0.

The bug is easy to state. A request parameter of ten bytes becomes a BigDecimal with a very large negative scale at no cost at all. The object itself stays tiny. Framework code then formats it in full, and the ten bytes become twenty-six million characters. Add one byte to the parameter and the JVM runs out of heap inside the framework's own text provider.

What made this worth reporting was not the amplification on its own. It was where the bound was. Struts already had the exact check this needs, written a few days earlier for a different path, sitting private in a class that nothing else can reach.

How the number gets large

NumberConverter parses incoming parameters with DecimalFormat and setParseBigDecimal(true), which requires the whole string to be consumed:

java
protected Object convertToBigDecimal(Map<String, Object> context, String stringValue) {
    Locale locale = getLocale(context);

    NumberFormat format = getNumberFormat(locale);
    if (format instanceof DecimalFormat) {
        ((DecimalFormat) format).setParseBigDecimal(true);
        ...
    }
    ParsePosition parsePosition = new ParsePosition(0);
    Number number = format.parse(stringValue, parsePosition);

1E20000000 is consumed in full and gives precision=1, scale=-20000000. Ten bytes, one significant digit, and an exponent that costs nothing to carry. Nothing has been allocated yet. The expansion only happens when something asks for the decimal expansion in text.

The bound that already existed

On 31 October, WW-5828 added a digit limit to StringConverter for exactly this shape of value:

java
private static final int MAX_INTEGER_DIGITS = 340;

protected String convertToString(Locale locale, Object value) {
    if (value instanceof BigDecimal decimal && integerDigits(decimal) > MAX_INTEGER_DIGITS) {
        return decimal.toString();
    }
    if (value instanceof Number) {
        NumberFormat format = NumberFormat.getNumberInstance(locale);

Both the constant and the integerDigits() helper are private to that class. Every other place in the framework that formats a request-derived number has no way to honour them, and two of those places do the same work without any bound at all.

Sink one: the number tag

java
public boolean end(Writer writer, String body) {
    java.lang.Number number = findNumberName();

    if (number != null) {
        NumberFormat format = getNumberFormat();
        findCurrency(format);
        setNumberFormatParameters(format);
        setRoundingMode(format);

        String msg = format.format(number);

findNumberName() pulls the value straight off the value stack with no conversion, so the BigDecimal arrives exactly as parsed. The only thing that could bound the output here is an integer-digit limit, and that is applied only when the JSP author set the attribute:

java
private void setNumberFormatParameters(NumberFormat format) {
    ...
    if (maximumIntegerDigits != null) {
        format.setMaximumIntegerDigits(maximumIntegerDigits);
    }

Unset, DecimalFormat keeps its default maximumIntegerDigits of Integer.MAX_VALUE. Grouping is left on too unless the tag turns it off, so the rendered string is about a third larger again than the digit count. A tag with nothing but a name attribute, which is how the tag is documented and how it is normally written, is the unbounded case.

Sink two: localized messages

java
protected String formatWithNullDetection(MessageFormat mf, Object[] args) {
    String message = mf.format(args);

MessageFormat hands a numeric argument to NumberFormat.getInstance(locale), with the same unbounded default. That is reached by getText(key, args), by the text tag with a param, and by the validation framework, which resolves message parameters off the stack and passes the raw object through:

java
Object val = stack.findValue(messageParameter);
parsedMessageParameters.add(val);

The validation path is the one I would use. The application never renders the attacker's value anywhere. It rejects it, and the rejection message interpolates the field that was rejected. Any range or expression validator will refuse 1E20000000 happily, and build a twenty-six million character error string while refusing it.

The JSON plugin reaches the same state

A JSON request body never passes through NumberConverter. JSONPopulator constructs the BigDecimal itself:

java
} else if (BigDecimal.class.equals(clazz)) {
    return new BigDecimal(value.toString());

Same value, same scale, same sinks. The reproduction asserts that both entry points produce an identical object, which is why the test lives in the JSON plugin module: it is the one place that sees both struts2-core and the plugin.

Measurements

One self-contained JUnit test, no servlet container and no network. Default heap for the project's own test run is 1536 MB.

text
payload: "1E20000000"  (10 bytes, no URL-encoding required)
  ENTRY 1 form parameter  -> NumberConverter  : precision=1 scale=-20000000
  ENTRY 2 JSON body       -> JSONPopulator    : precision=1 scale=-20000000
  StringConverter (bounded by WW-5828)                        11 chars      0 ms  BOUNDED
  <s:number name="amount"/>                           26,666,667 chars    823 ms  UNBOUNDED
  getText(key, {amount})  /  <s:text><s:param/>       26,666,674 chars    809 ms  UNBOUNDED
  validation error message (value only REJECTED)      26,666,704 chars    854 ms  UNBOUNDED
  5 numeric fields in ONE request                    133,333,520 chars   3935 ms  UNBOUNDED

Same file, one more byte in the parameter:

text
payload: "1E200000000"  (11 bytes)
  StringConverter (bounded by WW-5828)                        12 chars      0 ms  BOUNDED
  <s:number name="amount"/>                          266,666,667 chars   7218 ms  UNBOUNDED

java.lang.OutOfMemoryError: Java heap space
    at org.apache.struts2.text.TextProviderSupport.getText(TextProviderSupport.java:219)
    at org.apache.struts2.ActionSupport.getText(ActionSupport.java:138)
    at org.apache.struts2.validator.DelegatingValidatorContext.getText(DelegatingValidatorContext.java:164)

Two details that matter more than the ratio. The attacker never receives any of this: the string is assembled inside format.format() before a byte is written out, so the connection can be dropped the moment the request is sent and the server still pays in full. And the request is ten bytes in an entirely ordinary shape, so request-size limits, proxy body limits and rate limiting are all sized against something this does not use.

The message can be made to persist

The amplified string does not have to be transient. With the store interceptor in the stack, a normal thing to have in a redirect-after-post flow, field errors are written into the HTTP session. The storage mode is read from a request parameter, and the switch is on by default:

java
private boolean allowRequestParameterSwitch = true;
private String requestParameterSwitch = "operationMode";
private String operationMode = NONE;

So the attacker chooses retention. In the test the mode is set only through the request parameter, never through configuration, and the field errors appear in the session map at around 50 MB resident. That entry serializes to 26,667,151 bytes, which is what a persistent session manager writes to disk and what a replicated cluster pushes to every node.

What I ruled out

Listed so nobody repeats the walk:

  • Locale control. request_locale is attacker-settable through I18nInterceptor and only validated against available locales, so the choice is free. Ten locales including en-IN, hi-IN and bn-IN all produce 1.333x the digit count. No advantage.
  • TextParseUtil.translateVariables over the amplified message. OgnlTextParser does two linear indexOf scans; the quadratic substring-and-concatenate path only runs on a match, and the content is digits and separators.
  • JSON and XSLT output. StrutsJSONWriter.add() is buf.append(obj) and StringAdapter.getStringValue() is toString(), both compact for this value.
  • The template layer. UIBean.getValueClassType() returns String.class and the property tag resolves with String.class, so form fields and ordinary property rendering go through the bounded StringConverter.
  • A trust-boundary crossing. The output is digits and grouping separators, the expression-length cap is 256, and nothing I traced interprets it. I did not find a path past resource consumption.

What shipped

The fix is WW-5836, landed on 7 November by Lukasz Lenart: one commit on main for 7.5.0, a second on the 6.x support branch for 6.13.0. I sent an approach rather than a patch, since Struts treats a fix as a disclosure. The shape of what shipped matches it, and in one place it goes further than I had worked out.

The bound leaves StringConverter and becomes shared. The constant and the integer-digit arithmetic move into a new BigDecimalBounds that the converter, the number tag and message formatting all call:

java
public static boolean exceedsMaxIntegerDigits(Object value) {
    // long: precision - scale overflows int at the edge of the scale range
    return value instanceof BigDecimal decimal && (long) decimal.precision() - decimal.scale() > MAX_INTEGER_DIGITS;
}

That cast is the detail worth stopping on. precision() and scale() are both int, and scale reaches Integer.MIN_VALUE, so computing the integer-digit count in int overflows at exactly the range the attacker is steering into. A guard written the obvious way fails open on the values it exists to catch. It has to widen before it subtracts.

The number tag becomes a one-line fallback:

java
String msg = BigDecimalBounds.exceedsMaxIntegerDigits(number) ? number.toString() : format.format(number);

The commit message records why maximumIntegerDigits was not used instead: DecimalFormat applies it by dropping leading digits, so the tag would render a numerically wrong amount.

The case I did not account for

Message arguments were the harder half, for the reason I had flagged: the argument cannot be swapped for a compact String, because a typed element like {0,number} rejects one. What landed is BoundedMessageFormat. Ordinary calls go to MessageFormat untouched, and only a call actually carrying an over-bound argument takes the slow path:

java
static String format(MessageFormat messageFormat, Object[] args) {
    if (args != null && Arrays.stream(args).anyMatch(BigDecimalBounds::exceedsMaxIntegerDigits)) {
        return bound(messageFormat, args).format(args);
    }
    return messageFormat.format(args);
}

The slow path clones the MessageFormat and wraps each format element in a delegating format that passes values through unchanged below the bound and emits toString() above it. So far that is the design I proposed. Then there is ChoiceFormat.

MessageFormat re-parses the result of a ChoiceFormat element when that result contains a brace, and it decides whether to do so by checking the concrete type of the element's format. Wrap that element in anything else and the re-parse silently stops happening, so a nested pattern is no longer expanded. BoundedMessageFormat repeats the step by hand, re-entering itself with the bound applied to the nested pattern:

java
if (original instanceof ChoiceFormat choice) {
    String selected = choice.format(obj);
    if (selected.indexOf('{') >= 0) {
        return toAppendTo.append(BoundedMessageFormat.format(new MessageFormat(selected, locale), args));
    }
    return toAppendTo.append(selected);
}

My own suggestion, installing a delegating format through setFormatByArgumentIndex, would have walked straight into that and quietly broken nested choice patterns. The lesson generalises past this bug: a wrapper around a java.text.Format is not transparent, because MessageFormat branches on what its elements are, not only on what they do. The same commit also has to re-implement MessageFormat's own defaults for an untyped element, for the same reason.

Both questions I left open in the report are answered by what shipped. The bound stayed a constant rather than becoming configurable, and the StringConverter unification happened in the same change rather than a follow-up ticket.

Timeline

  • 1 November 2026: reported to security@struts.apache.org with a self-contained reproduction.
  • 3 November 2026: confirmed as a vulnerability under the Struts security process.
  • 7 November 2026: fixed as WW-5836 on main and on the 6.x support branch.
  • 30 November 2026: S2-085 and CVE-2026-133641 published. Fixed in 7.5.0 and 6.13.0.

Struts handles security fixes privately from start to finish, so there is no public pull request to point at for this one. Lukasz Lenart handled the report, and the turnaround on it was quick.

References

Apache Struts security bulletin S2-085

WW-5836 on main, for 7.5.0

WW-5836 on the 6.x support branch, for 6.13.0