Contextual output encoding for Java 8+ to help prevent XSS. Version 1.6.0 provides a zero-dependency core, String and Writer APIs, and optional javax/Jakarta JSP adapters.
Untrusted numeric text must be parsed and validated before emitting a numeric literal. Use a known numeric type and enforce the application’s range and finiteness rules; do not emit an arbitrary object’s toString() result as JavaScript.
For complete JSON documents, use a serializer. JSON does not permit NaN or Infinity. If embedding JSON in an HTML script element, configure serialization for safe HTML embedding.
Parse numeric input on the server and handle invalid input explicitly. For example, Double.parseDouble(rawValue) can throw NumberFormatException; also reject non-finite values with Double.isFinite(value) when a finite number is required. Apply domain-specific bounds before emitting the validated number. Prefer a JSON serializer for structured data.
Alternatively, transfer the input as a quoted JavaScript string and convert it at runtime:
const raw = "<%= Encode.forJavaScriptBlock(rawValue) %>";
const value = Number(raw);
Validate the result and apply application-specific bounds before using it. String encoding does not make a value numeric or enforce business rules.
Project Leader
Jeremy Long co-leads OWASP Java Encoder and coordinates project maintenance, releases, and security response with Jim Manico.
Project Leader
Jim Manico is the founder of Manicode Security, where he trains developers and organizations in secure coding. He is an OWASP Distinguished Lifetime Member, a Java Champion, and the author of Iron-Clad Java. He leads the OWASP AISVS, Cheat Sheet Series, Java HTML Sanitizer, and Java Encoder projects.
Recognizing key contributors who have made significant impact on this project.
Original Author
Original author of OWASP Java Encoder.