This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
commit 713989aa74ab97e3b82901e5b9e333d20c9da4f3 Author: Gary Gregory <[email protected]> AuthorDate: Thu Nov 19 11:26:44 2026 -0500 Escape unknown method attribute names in Class2HTML code reports CodeHTML.writeMethod() concatenated the Unknown attribute object into the <LI> element without escaping, so an attacker-controlled CONSTANT_Utf8 attribute name was emitted as active HTML in <ClassName>_code.html. Escape it with the shared Class2HTML.toHTML() helper. Adds a regression test (Class2HTMLXSSTest) with a method-level unknown attribute whose name contains <, >, &, ', and ". --- src/changes/changes.xml | 1 + src/main/java/org/apache/bcel/util/CodeHTML.java | 2 +- .../org/apache/bcel/util/Class2HTMLXSSTest.java | 35 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 90b6f440..f06b99e0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -62,6 +62,7 @@ The <action> type attribute can be add,update,fix,remove. <release version="6.14.1" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required."> <!-- FIX --> <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary Gregory">InstConstraintVisitor check objectref class in getfield and putfield verification (#547).</action> + <action type="fix" dev="ggregory" due-to="hataehoon, Gary Gregory">Escape unknown method attribute names in Class2HTML code reports (incomplete fix for CVE-2026-105111).</action> <!-- ADD --> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-lang3 from 3.21.0 to 3.22.0.</action> diff --git a/src/main/java/org/apache/bcel/util/CodeHTML.java b/src/main/java/org/apache/bcel/util/CodeHTML.java index 097592ed..47f2502a 100644 --- a/src/main/java/org/apache/bcel/util/CodeHTML.java +++ b/src/main/java/org/apache/bcel/util/CodeHTML.java @@ -521,7 +521,7 @@ final class CodeHTML { printWriter.print("<LI><A HREF=\"" + className + "_attributes.html#method" + methodNumber + "@" + i + "\" TARGET=Attributes>" + Const.getAttributeName(tag) + "</A></LI>\n"); } else { - printWriter.print("<LI>" + attributes[i] + "</LI>"); + printWriter.print("<LI>" + Class2HTML.toHTML(String.valueOf(attributes[i])) + "</LI>"); } if (tag == Const.ATTR_CODE) { c = (Code) attributes[i]; diff --git a/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java b/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java index 2e91f15d..fcfe102b 100644 --- a/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java +++ b/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java @@ -27,9 +27,15 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import org.apache.bcel.Const; +import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; +import org.apache.bcel.classfile.Unknown; import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.ConstantPoolGen; import org.apache.bcel.generic.FieldGen; +import org.apache.bcel.generic.InstructionList; +import org.apache.bcel.generic.MethodGen; import org.apache.bcel.generic.Type; import org.junit.jupiter.api.Test; @@ -77,4 +83,33 @@ class Class2HTMLXSSTest { assertFalse(methods.contains("x\" onmouseover"), "field name broke out of the attribute context"); assertTrue(methods.contains("x" onmouseover"), "expected quotes in the field name to be escaped"); } + + /** + * An unknown method attribute's name is any CONSTANT_Utf8 value, hence attacker controlled and may contain HTML + * metacharacters; the code report must escape it in text context rather than emit a live element (incomplete fix + * for CVE-2026-105111). + */ + @Test + void testUnknownMethodAttributeNameIsEscaped() throws Exception { + final ClassGen cg = new ClassGen("EvilUnknownAttr", "java.lang.Object", "EvilUnknownAttr.java", Const.ACC_PUBLIC, null); + final ConstantPoolGen cpg = cg.getConstantPool(); + final String marker = "x<svg onload=\"alert(1)\">&'\"y"; + final int nameIndex = cpg.addUtf8(marker); + final MethodGen mg = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] {}, new String[] {}, "value", "EvilUnknownAttr", new InstructionList(), cpg); + final Method method = mg.getMethod(); + method.setAttributes(new Attribute[] { new Unknown(nameIndex, 0, new byte[0], cpg.getFinalConstantPool()) }); + cg.addMethod(method); + final JavaClass jc = cg.getJavaClass(); + + final File outputDir = new File("target/test-output/html-xss"); + if (!outputDir.mkdirs()) { + assertTrue(outputDir.isDirectory()); + } + new Class2HTML(jc, outputDir.getAbsolutePath() + File.separator); + + final String code = new String(Files.readAllBytes(new File(outputDir, "EvilUnknownAttr_code.html").toPath()), StandardCharsets.UTF_8); + assertFalse(code.contains(marker), "unknown attribute name was emitted unescaped in text context"); + assertTrue(code.contains("(Unknown attribute x<svg onload="alert(1)">&'"y)"), + "expected the unknown attribute name to be HTML-escaped"); + } }
