Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TraitErrors on BeanDefinitionMethodGeneratorTests with XML parser XXE vulnerability #125

Open
timtebeek opened this issue Feb 27, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@timtebeek
Copy link
Contributor

Problem

Describe the issue you are experiencing.

Expected behavior

Describe what you expected to see.

Example diff

From: spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java

  				Collections.emptyList());
MethodReference method = generator.generateBeanDefinitionMethod(
this.generationContext, this.beanRegistrationsCode);
-		compile(method, (actual, compiled) -> {
+		compile(method, (actual, {{80000000-0000-03c6-0000-000000000000}}compiled{{80000000-0000-03c6-0000-000000000000}}) -> {
SourceFile sourceFile = compiled.getSourceFile(".*BeanDefinitions");
assertThat(sourceFile).contains("Get the bean definition for 'testBean'");
assertThat(sourceFile).contains("new RootBeanDefinition(TestBean.class)");

Recipes in example diff:

  • org.openrewrite.java.security.XmlParserXXEVulnerability

Error messages:

org.openrewrite.analysis.trait.util.TraitErrorsException: TraitErrors: 
- Method must be created from class org.openrewrite.java.tree.J$MethodDeclaration but was class org.openrewrite.java.tree.J$Lambda
- No parent Method found
- Field must be declared in a class, interface, or anonymous class
org.openrewrite.analysis.trait.util.TraitErrors.doThrow(TraitErrors.java:43)
fj.data.Either$RightProjection.on(Either.java:531)
fj.data.Validation.on(Validation.java:146)
org.openrewrite.analysis.trait.expr.VarAccessBase$1.visitVariable(VarAccess.java:187)
org.openrewrite.analysis.trait.expr.VarAccessBase$1.visitVariable(VarAccess.java:175)
org.openrewrite.java.tree.J$VariableDeclarations$NamedVariable.acceptJava(J.java:5938)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1375)
org.openrewrite.java.JavaVisitor.lambda$visitVariableDeclarations$29(JavaVisitor.java:963)
org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
org.openrewrite.java.JavaVisitor.visitVariableDeclarations(JavaVisitor.java:963)
org.openrewrite.java.tree.J$VariableDeclarations.acceptJava(J.java:5824)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
...

References:

  • View original result
  • Recipe ID: org.openrewrite.java.security.XmlParserXXEVulnerability
  • Recipe Name: XML parser XXE vulnerability
  • Repository: spring-projects/spring-framework/main
  • Created at Tue Feb 27 2024 19:57:08 GMT+0100 (Central European Standard Time)
@timtebeek timtebeek added the bug Something isn't working label Feb 27, 2024
@timtebeek timtebeek transferred this issue from openrewrite/rewrite Feb 27, 2024
@timtebeek
Copy link
Contributor Author

@JLLeitschuh do you see any reason why we're seeing these issues over the past two days that weren't there before? This is from our daily flagship recipe runs.

@JLLeitschuh
Copy link
Collaborator

JLLeitschuh commented Mar 11, 2024

Likely caused by: openrewrite/rewrite-analysis#38

@JLLeitschuh
Copy link
Collaborator

do you see any reason why we're seeing these issues over the past two days that weren't there before?

Likely something about the underlying code changed, causing this to occur. This needs to be resolved in rewrite-analysis so we stop having these errors spuriously.

@timtebeek
Copy link
Contributor Author

Saw this again today on compiled on this particular line: https://github.com/spring-projects/spring-framework/blob/ae9153e644b0e4ccc414e1e4749ac082ca242739/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java#L111

TraitErrors: 
- Method must be created from class org.openrewrite.java.tree.J$MethodDeclaration but was class org.openrewrite.java.tree.J$Lambda
- No parent Method found
- Field must be declared in a class, interface, or anonymous class

Detail:

org.openrewrite.analysis.trait.util.TraitErrorsException: TraitErrors: 
- Method must be created from class org.openrewrite.java.tree.J$MethodDeclaration but was class org.openrewrite.java.tree.J$Lambda
- No parent Method found
- Field must be declared in a class, interface, or anonymous class
 org.openrewrite.analysis.trait.util.TraitErrors.doThrow(TraitErrors.java:43)
 fj.data.Either$RightProjection.on(Either.java:531)
 fj.data.Validation.on(Validation.java:146)
 org.openrewrite.analysis.trait.expr.VarAccessBase$1.visitVariable(VarAccess.java:188)
 org.openrewrite.analysis.trait.expr.VarAccessBase$1.visitVariable(VarAccess.java:176)
 org.openrewrite.java.tree.J$VariableDeclarations$NamedVariable.acceptJava(J.java:5955)
 org.openrewrite.java.tree.J.accept(J.java:59)
 org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
 org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:324)
 org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1369)
 org.openrewrite.java.JavaVisitor.lambda$visitVariableDeclarations$29(JavaVisitor.java:963)
 org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
 org.openrewrite.java.JavaVisitor.visitVariableDeclarations(JavaVisitor.java:963)
 org.openrewrite.java.tree.J$VariableDeclarations.acceptJava(J.java:5840)
 org.openrewrite.java.tree.J.accept(J.java:59)
 org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
 ...

@timtebeek
Copy link
Contributor Author

Also seen on FINOS: https://app.moderne.io/results/nhAg9TUiZ
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants