SnakeYaml Constructor Deserialization Remote Code Execution
Published 12 Dec 2022 · Updated 10 Sept 2026
Is your project on an affected org.yaml:snakeyaml?
Look after several Java apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- <2.0
- Fixed in
- 2.0
mvn versions:use-dep-version -Dincludes=org.yaml:snakeyaml -DdepVersion=2.0 -DforceVersion=trueDetails
Summary
SnakeYaml's Constructor class, which inherits from SafeConstructor, allows
any type be deserialized given the following line:
new Yaml(new Constructor(TestDataClass.class)).load(yamlContent);
Types do not have to match the types of properties in the
target class. A ConstructorException is thrown, but only after a malicious
payload is deserialized.
Severity
High, lack of type checks during deserialization allows remote code execution.
Proof of Concept
Execute bash run.sh. The PoC uses Constructor to deserialize a payload
for RCE. RCE is demonstrated by using a payload which performs a http request to
http://127.0.0.1:8000.
Example output of successful run of proof of concept:
$ bash run.sh
[+] Downloading snakeyaml if needed
[+] Starting mock HTTP server on 127.0.0.1:8000 to demonstrate RCE
nc: no process found
[+] Compiling and running Proof of Concept, which a payload that sends a HTTP request to mock web server.
[+] An exception is expected.
Exception:
Cannot create property=payload for JavaBean=Main$TestDataClass@3cbbc1e0
in 'string', line 1, column 1:
payload: !!javax.script.ScriptEn ...
^
Can not set java.lang.String field Main$TestDataClass.payload to javax.script.ScriptEngineManager
in 'string', line 1, column 10:
payload: !!javax.script.ScriptEngineManag ...
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:291)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:172)
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:332)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:220)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:174)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:158)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:491)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:416)
at Main.main(Main.java:37)
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field Main$TestDataClass.payload to javax.script.ScriptEngineManager
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.base/java.lang.reflect.Field.set(Field.java:780)
at org.yaml.snakeyaml.introspector.FieldProperty.set(FieldProperty.java:44)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:286)
... 9 more
[+] Dumping Received HTTP Request. Will not be empty if PoC worked
GET /proof-of-concept HTTP/1.1
User-Agent: Java/11.0.14
Host: localhost:8000
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-aliveFurther Analysis
Potential mitigations include, leveraging SnakeYaml's SafeConstructor while parsing untrusted content.
See https://bitbucket.org/snakeyaml/snakeyaml/issues/561/cve-2022-1471-vulnerability-in#comment-64581479 for discussion on the subject.
Timeline
Date reported: 4/11/2022 Date fixed: 30/12/2022 Date disclosed: 10/13/2022
Is GHSA-mjmj-j48q-9wg2 in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected org.yaml:snakeyaml, and gives you the command that fixes it.
More advisories for org.yaml:snakeyaml
- MediumCVE-2022-41854Snakeyaml vulnerable to Stack overflow leading to denial of service · 11 Nov 2022
- MediumCVE-2022-38751snakeYAML before 1.31 vulnerable to Denial of Service due to Out-of-bounds Write · 6 Sept 2022
- MediumCVE-2022-38752snakeYAML before 1.32 vulnerable to Denial of Service due to Out-of-bounds Write · 6 Sept 2022
- MediumCVE-2022-38749snakeYAML before 1.31 vulnerable to Denial of Service due to Out-of-bounds Write · 6 Sept 2022
- MediumCVE-2022-38750snakeYAML before 1.31 vulnerable to Denial of Service due to Out-of-bounds Write · 6 Sept 2022
- HighCVE-2022-25857Uncontrolled Resource Consumption in snakeyaml · 31 Aug 2022
References
- Linkgithub.com/google/security-research/security/advisories/GHSA-mjmj-j48q-9wg2
- Advisorynvd.nist.gov/vuln/detail/CVE-2022-1471
- Linkwww.github.com/mbechler/marshalsec/blob/master/marshalsec.pdf?raw=true
- Linksnyk.io/blog/unsafe-deserialization-snakeyaml-java-cve-2022-1471
- Linksecurity.netapp.com/advisory/ntap-20240621-0006
- Linksecurity.netapp.com/advisory/ntap-20230818-0015
- Linkinfosecwriteups.com/%EF%B8%8F-inside-the-160-comment-fight-to-fix-snakeyamls-rce-default-1a20c5ca4d4c
- Linkgroups.google.com/g/kubernetes-security-announce/c/mwrakFaEdnc
- Linkgithub.com/mbechler/marshalsec
- Linkconfluence.atlassian.com/security/cve-2022-1471-snakeyaml-library-rce-vulnerability-in-multiple-products-1296171009.html
- Linkbitbucket.org/snakeyaml/snakeyaml/wiki/CVE-2022-1471
- Linkbitbucket.org/snakeyaml/snakeyaml/issues/561/cve-2022-1471-vulnerability-in#comment-64876314
- Linkbitbucket.org/snakeyaml/snakeyaml/issues/561/cve-2022-1471-vulnerability-in#comment-64634374
- Linkbitbucket.org/snakeyaml/snakeyaml/issues/561/cve-2022-1471-vulnerability-in#comment-64581479
- Linkbitbucket.org/snakeyaml/snakeyaml/commits/acc44099f5f4af26ff86b4e4e4cc1c874e2dc5c4
- Linkbitbucket.org/snakeyaml/snakeyaml/commits/5014df1a36f50aca54405bb8433bc99a8847f758
- Packagebitbucket.org/snakeyaml/snakeyaml
- Linkpacketstormsecurity.com/files/175095/PyTorch-Model-Server-Registration-Deserialization-Remote-Code-Execution.html
- Linkwww.openwall.com/lists/oss-security/2023/11/19/1
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.