spring-boot: Loading application.yml fails with NoSuchMethodError when using SnakeYAML 2.0
When I upgrade snakeyaml from 1.33 to 2.0 version, Springboot Application run failed as below. I have tried springboot 2.7.4 and 3.0.0, neither works. Also I have tried JDK 8,11 and 17, none works.
- snakeyaml dependency
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
- Error log
11:28:31.187 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.yaml.snakeyaml.representer.Representer: method 'void <init>()' not found
at org.springframework.boot.env.OriginTrackedYamlLoader.createYaml(OriginTrackedYamlLoader.java:76)
at org.springframework.boot.env.OriginTrackedYamlLoader.createYaml(OriginTrackedYamlLoader.java:71)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:164)
at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:84)
at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50)
at org.springframework.boot.context.config.StandardConfigDataLoader.load(StandardConfigDataLoader.java:54)
at org.springframework.boot.context.config.StandardConfigDataLoader.load(StandardConfigDataLoader.java:36)
at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:107)
at org.springframework.boot.context.config.ConfigDataImporter.load(ConfigDataImporter.java:128)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:86)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:116)
at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:240)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:227)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at cc.vayne.Application.main(Application.java:10)
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 7
- Comments: 68 (31 by maintainers)
Links to this issue
Commits related to this issue
- FOLIO-3734: snakeyaml 2.0 Upgrade snakeyaml from 1.33 to 2.0 fixing Arbitrary Code Execution: https://nvd.nist.gov/vuln/detail/CVE-2022-1471 Spring Boot >= 3.0.3 is compatible with snakeyaml 2.x: ht... — committed to folio-org/mod-consortia by julianladisch a year ago
- Improve compatibility with SnakeYAML 2.0 Closes gh-34405 — committed to spring-projects/spring-boot by wilkinsona a year ago
- Resolve CVE-2022-1471: Bump Jackson and Spring Boot in pom.xml Ref: - https://github.com/spring-projects/spring-boot/issues/34405#issuecomment-1546430146 - https://access.redhat.com/documentation/... — committed to darkmastermindz/zipkin by darkmastermindz a year ago
- Resolve CVE-2022-1471: Securing the Vulnerability with SnakeYAML 2.0 and Spring Boot 2.7.10 (#3538) * Update pom.xml Bump snakeyml to 2.0 to resolve CVE-2022-1471 * Resolve CVE-2022-1471: Bump... — committed to openzipkin/zipkin by darkmastermindz a year ago
- chore: Upgraded Snake YAML version to 2.0 (#23572) ## Description Upgrades SnakeYaml dependency version forcefully to 2.0 to overcome [this issue](https://github.com/spring-projects/spring-boot/is... — committed to appsmithorg/appsmith by nidhi-nair a year ago
@DRoppelt Yes, that’s a change that we’re considering: https://github.com/wilkinsona/spring-boot/commit/6aa1ce75b0bade8e21b818d402b6abd9bfc8f57c. It will require further testing and we’ll also have to decide how much support we want to add for SnakeYAML 2.0 in maintenance releases.
@sandipbhttachrya We won’t be upgrading Spring Boot 2.7.x to use SnakeYAML 2.0 by default, however, Spring Boot 2.7.10 will allow you to upgrade the dependency yourself and not suffer the
NoSuchMethodError
. We plan to release 2.7.10 tomorrow. For future reference, the milestones page has target release dates.@Nicoagarciac Spring Boot 2.5.x is no longer supported. If you are using
application.yaml
files, SnakeYAML 2.0 will not work with it. To use Spring Boot 2.x with SnakeYAML 2.0 you will have to upgrade to Spring Boot 2.7.10 when it is released later this week.I assume it’s CVE-2022-1471 that’s triggering the alert. It’s very likely to be a false positive as Spring Boot itself is not vulnerable due to the way it uses SnakeYAML. Unless you’re using SnakeYAML in an unsafe manner and passing untrusted input into it, your application is not vulnerable. There’s some more background in https://github.com/spring-projects/spring-boot/issues/33457.
You have a few options right now:
application.properties
filesThe situation with 2 may improve in time, depending on the outcome of the further testing that we want to do as well as possible changes in Spring Framework being tracked by https://github.com/spring-projects/spring-framework/pull/30048.
@wilkinsona feel free to ping me if you need any help with SnakeYAML for Spring Boot 3 By the way, I fully support your proposals here. (this false positive CVE-2022-1471 drives me crazy - we have lost so much time for nothing)
@wilkinsona would you consider supporting a backport of this change to the 2.7.X line? https://github.com/spring-projects/spring-boot/commit/bf5bd4f91c8b5617b589795b4db6a2371b26d5f5#diff-07741e308f54bc7fc66aabb0a1594c1ff8a9785103fb8cdf4c930ad3b44ed2c6
I would submit a PR?
It appears to be both compatible with snakeyaml 1.30 and 2.0
I cannot chime in for reproducing this with spring boot 3.0, we also have this issue with some services that are stuck on 2.7.X (tested with 2.7.9), but would like to upgrade to snakeyaml 2.0 due to the safe defaults it is bringing (not related to spring, but just usage within the app).
@sportymsk, Spring Boot doesn’t require Snake YAML. It’s only used if you choose to configure your application using YAML files rather than properties files. It’s a dependency of
spring-boot-starter
purely for convenience and it you don’t use YAML configuration files it can be excluded using the appropriate configuration in yourbuild.gradle
orpom.xml
file.Hello All,
From the above discussion, it is still unclear if SnakeYaml
2.0
is compatible with Spring Boot3.0.x
or not. Could someone clarify?Thanks Sourabh
@zhudaxi We won’t be upgrading to SnakeYAML 2.0 in Spring Boot 2.7.x (which is the last planned 2.x release) since it’s a major version bump. We will try to make it possible to users to upgrade themselves, but we don’t have an estimate for when that will happen.
Upgrading Jackson to v 2.15.0 seems to fix this error when using SB 2.7.11 and snakeYAML 2.0.
We recently also ran into Springboot 2.7.7 and 2.7.8 issue with snakeyaml 1.33:
It looks like
io.kubernetes.client.openapi.ApiClient
or something that it references isn’t compatible with SnakeYAML 2.0. The complete stack trace will show you exactly where the incompatibility lies.If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Yes, I think so. Your Liquibase change logs are trusted input so you are not at risk. You also have the option of upgrading both SnakeYAML and Liquibase using the
snakeyaml.version
andliquidate.version
properties.The amount of work because of this false positive is enormous. Why not to keep using SnakeYAML 1.* ?
We have already upgraded to Jackson 2.14 in Boot 3.0. Boot 2.7.x will not upgrade to 2.14 as we generally do not upgrade to new minor versions of dependencies in maintenance releases of Spring Boot. If you are using Jackson’s YAML support and manually upgrading SnakeYAML to 2.0, you should also upgrade Jackson as needed.
Thanks, @asomov. @Abahafart, https://github.com/liquibase/liquibase/pull/3893 is the change in Liquibase. If you have any further questions about Liquibase’s compatibility please follow up with the Liquibase community as it is out of Spring Boot’s control.
downgrade your jackson implementation for parsing YAML and this should solve this issue. I had the same one.
there you go,
jackson-dataformat-yaml
, which you could try to change to a more recent version viajackson-bom.version
property. 3.0.6 is on2.14.2
as a reference.From what it looks like, their repo is here https://github.com/FasterXML/jackson-dataformats-text I dug into the history and it appears that they have fixed it with 2.14 https://github.com/FasterXML/jackson-dataformats-text/pull/371/files
Maybe they would accept a backport to 2.13, from my understanding that should be compatible in their 2.13 line
e: judging by the context within the PR, if you can adjust the caller to inject a non-null
loaderOptions
, the deprecated method should also not be called, therefore preventingNoSuchMethodError
SB 2.7.11 and SnakeYAML 2.0 dont work together. Gives the same error.
@DManstrator We have no plans to back port the changes. Firstly, Spring Boot 2.6.x is no longer supported. Secondly, unless you are passing untrusted input to SnakeYAML for processing, the CVE is a false positive. You can safely use
application.yaml
without being vulnerable as it is trusted input. If, out of an abundance of caution, you want to eliminate the dependency anyway, you can configure your application using application.properties and exclude the SnakeYAML dependency.@rowi1de that’s an incompatibility between Jackson and SnakeYAML which is out of Spring Boot’s control. Please see https://github.com/spring-projects/spring-boot/issues/34527 for some further details.
We are on spring boot version 2.7.6 and snakeyaml 1.33. For us, changing the application.yml to application.properties and excluding the snakeyaml from dependency fixed the issue. Thanks @wilkinsona
Hello, could you help me? I have the same issue and I’m working with spring 3.0.0, here the details
@jliu1970 I would not expect that error with SnakeYAML 1.33 as
org.yaml.snakeyaml.representer.Representer
has a default constructor in that version. If you can reproduce the problem, please open a new issue with a minimal sample that does so.As far as we know, the problem above should only occur with Spring Boot 2.7. While not officially supported, the failure above should not occur with SnakeYAML 2.0 and Spring Boot 3.0. Can you please provide a minimal sample that shows a failure with Spring Boot 3.0.3 and SnakeYAML 2.0?