The vulnerability lies in the SpecificCompiler class of the Apache Avro Java SDK, which is responsible for generating Java code from Avro schemas. The analysis of the patch 84bc7322ca1c04ab4a8e4e708acf1e271541aac4 reveals two main issues that were fixed:
-
Code Injection via javaAnnotation Property: The javaAnnotations method in SpecificCompiler.java was modified to validate the contents of the javaAnnotation schema property. Previously, this property was treated as a raw string and injected directly into the generated Java file as an annotation. A malicious user could craft a schema with a javaAnnotation value like ... */ static { System.exit(0); } // to break out of the annotation context and inject arbitrary code. The patch introduces the isValidAsAnnotation method to strictly validate the annotation syntax, preventing this injection vector.
-
Javadoc Injection via doc Fields: The Velocity templates used for code generation (e.g., record.vm, enum.vm, protocol.vm) were updated to escape documentation fields (e.g., $schema.getDoc(), $field.doc()) using a new escapeForJavadoc method. Previously, the raw doc string was inserted directly into Javadoc comments. A malicious doc string like */ arbitrary code /* could be used to terminate the Javadoc comment and inject code or manipulate the generated documentation. The compile() method is the entry point that drives this template processing.
The primary vulnerable function is org.apache.avro.compiler.specific.SpecificCompiler.javaAnnotations as it directly handles the injectable javaAnnotation property. The overall compile() method of the SpecificCompiler is the entry point that orchestrates the entire vulnerable code generation process, including the processing of unescaped doc comments. During exploitation, a runtime profiler would likely show org.apache.avro.compiler.specific.SpecificCompiler.compile() as the top-level function call leading to the vulnerable code generation steps.