Java: which APIs and framework defaults turn into vulnerabilities?

Before your next release, move to JDK 25 or 21 and Spring Boot 4.15, stop deserializing outside data into classes it names, and require Find Security Bugs or CodeQL in CI. Judge everything else by whether outside data can pick a class, become SQL, an expression or a command, reach an XML parser, a path or a URL, or slip past an authorization rule.

Reviewed
Next review
Version
1.1
Written for
Developers and tech leads writing production Java, including Spring Boot services, and the security people who review it

If you only do five things

  1. Stay on supported lines and take every update.

    OpenJDK ships fixes each January, April, July and October, plus three extra releases in 20263. Spring Boot 3.5 lost free fixes in June 2026, 4.0 loses them in December and 4.1 in July 20275. Patch within the patching sheet's deadlines.

  2. Never let outside data name the class.

    Java deserialization creates the classes the stream names, and no filter runs unless you set one12; Jackson's default typing lets JSON do the same21. Read outside data as JSON into records.

  3. Keep input out of queries, expressions and commands.

    Use parameters for SQL and JPQL, never parse SpEL or OGNL from input, and give ProcessBuilder an argument list. SQL, OS command and code injection rank 2nd, 9th and 10th in the CWE Top 2525.

  4. Deny by default and keep actuator private.

    End your rules with .anyRequest().denyAll()8 and expose only health, Boot's default9. ActiveMQ's Jolokia endpoint let logged-in users run code (CVE-2026-34197, exploited)2324.

  5. Make the analyzers a required check.

    Run Find Security Bugs or CodeQL on every pull request2830; CodeQL on private code needs paid Code Security32. Set Dependency-Check's failBuildOnCVSS: by default it never fails31.

Review a Java pull request

  1. Where does outside data enter?

    Find the controllers, listeners, uploads and batch jobs it touches. Each should bind a record made for that request, as Spring advises11, not an entity: Spring4Shell was code execution through data binding24.

  2. Who may call it, on which record?

    Ask why for each new permitAll(), each matcher placed after a broader one8 and each csrf change. Missing authorization ranks 4th in the CWE Top 2525: check who owns the record.

  3. Can data choose a class or code?

    Search for ObjectInputStream, XMLDecoder, enableDefaultTyping, activateDefaultTyping, Id.CLASS, Class.forName, parseExpression and lookup(.

  4. Does it reach SQL, a process, XML, a path or a URL?

    Check createQuery and @Query strings built with +, ProcessBuilder, XML parser factories, resolve( and HTTP clients given URLs from input.

  5. What does it expose?

    Check exposure.include, new SecurityFilterChain beans, which replace Boot's actuator rules9, error details and logged secrets.

Java traps and what to use instead

  • ObjectInputStream.readObject() and XMLDecoder. The stream picks the classes, and gadgets on the classpath turn that into code execution12; OWASP lists XMLDecoder as unsafe for untrusted input26. If you must read Java serialization, set jdk.serialFilter to an allowlist ending in !*, with maxbytes and maxdepth limits13.
  • activateDefaultTyping() and @JsonTypeInfo(use = Id.CLASS). The JSON then names the class, and Jackson calls the validator you pass critical for security21. Use Id.NAME with listed subtypes28. XStream with a relaxed allowlist, SnakeYAML before 2.0 without SafeConstructor and fastjson without safe mode share the problem26.
  • DocumentBuilderFactory.newInstance() defaults. JDK parsers fetch external DTDs and entities unless you set secure processing explicitly14, and GeoServer's XXE (CVE-2025-58360) is exploited24. Set jdk.xml.dtd.support=deny on JDK 22 and later, or disallow-doctype-decl for DOM and SAX and SUPPORT_DTD false for StAX14.
  • "WHERE id = " + id in JDBC, JPQL or a native @Query. Hibernate queries are injectable when you concatenate27. Bind ? or :name parameters, and map sort columns and directions from a fixed list: parameters can't stand for column names27.
  • SpEL, OGNL, Class.forName() or JNDI lookup() fed from input. Spring says StandardEvaluationContext must never evaluate untrusted SpEL and SimpleEvaluationContext is only best-effort10. Spring Cloud Function (SpEL), Confluence (OGNL) and PaperCut (reflection) flaws are exploited24; Log4Shell ran LDAP code named in a log message22. Keep input in variables; map names from a fixed list.
  • Runtime.exec(String) and sh -c. exec(String) splits on whitespace and is deprecated since JDK 1816. Give ProcessBuilder a fixed program and one element per argument, put -- before input that may start with a dash, and never hand input to sh -c or cmd /c.
  • base.resolve(name). An absolute name replaces base, and normalize() ignores symlinks15. Require startsWith(base) on the normalized path, which compares whole name elements, and on toRealPath() where links matter15. Check ZipEntry names too.
  • URL.openStream() and HTTP clients given URLs from input. URL connections also open file: URLs28; server-side request forgery ranks 22nd in the CWE Top 2525. Allowlist hosts, check resolved addresses and refuse redirects, the JDK HttpClient default17. Boot's clients follow them unless spring.http.clients.redirects is dont-follow1918.

Tools that catch it

  • Find Security Bugs. Add findsecbugs-plugin to SpotBugs and fix OBJECT_DESERIALIZATION, XXE_DOCUMENT, SQL_INJECTION_JPA and SPEL_INJECTION first28.
  • Error Prone flags BanJNDI as an error by default; turn on the experimental BanSerializableRead and BanClassLoader checks29.
  • CodeQL's java/unsafe-deserialization, java/xxe and java/jndi-injection queries cover these traps30.
  • Dependency-Check fails builds only once you set failBuildOnCVSS31. The supply-chain sheet covers the rest.

What you can skip

  • The Security Manager. JDK 24 disabled it for good, and servers rarely used it20. Isolate untrusted code in a process or container.
  • Hunting gadget classes. OWASP expects more to be found26. Stop deserializing outside data instead.
  • Find Security Bugs' inventory patterns. SPRING_ENDPOINT and SERVLET_PARAMETER flag every controller and parameter read28. Exclude them.
  • Escaping input for SQL, shells or SpEL yourself. Bind parameters, drop the shell and stop evaluating input instead.

What changed in 2026

  • Oracle JDK 21 updates are no longer no-fee. Releases since 20 October use the OTN license; Oracle JDK 25 updates stay no-fee through September 20281. Temurin supports 21 until at least December 20292.
  • Compromised eMudhra CA keys need another JDK update. Install a runtime that fixes JDK-8395690 (CVE-2026-114820) in every image, even if you updated in October; on Debian and Ubuntu, also rebuild the Java keystore4.
  • Spring Boot 4.0.0 to 4.0.5 could open every endpoint in some apps on Boot's default web security (CVE-2026-40976, critical). 4.0.6 fixes it6.
  • Free Spring fixes now skip Spring Security 6.5. August's critical fix for its embedded LDAP server (CVE-2026-59270) shipped free only for 7.0 and 7.17.
  • Spring Boot 4.1 added SSRF protection. An InetAddressFilter bean limits the addresses its HTTP clients may call, except through a proxy18.

What this looks like for your code

New project

  • Start on JDK 25 and Spring Boot 4.1, with .anyRequest().denyAll() as the last rule.
  • Set jdk.serialFilter=!* and jdk.xml.dtd.support=deny if nothing needs serialization or DTDs.
  • Bind every request to a record and keep entities out of controllers.

Existing codebase

  • Move Oracle JDK 21 to JDK 25 or an OpenJDK build, and leave JDK 11 and 17 before October 20272.
  • Search for ObjectInputStream, activateDefaultTyping, parseExpression and exposure.include.
  • Remove Log4j 1, at end of life since 201522.

High-assurance or regulated

  • Make CodeQL's security-extended suite and Find Security Bugs required checks.
  • Run with an allowlist jdk.serialFilter and the strict JAXP template as the JAXP configuration file14.
  • Stay on Spring and JDK lines with free fixes, or pay for support on the ones you keep.