-
-
Notifications
You must be signed in to change notification settings - Fork 244
Re-apply entity/DTD hardening after JDK deserialization of XmlFactory
#878
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
Merged
cowtowncoder
merged 7 commits into
FasterXML:3.x
from
Sahana2524:readresolve-secure-xmlinputfactory
Jul 23, 2026
+69
−2
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0b023df
re-apply entity/DTD hardening after JDK deserialization of XmlFactory
Sahana2524 81e5ab7
Merge branch '3.x' into readresolve-secure-xmlinputfactory
cowtowncoder 1ad6e02
add @since 3.3 to secureXmlInputFactory javadoc
Sahana2524 928bdbd
Merge branch '3.x' into readresolve-secure-xmlinputfactory
cowtowncoder a96d242
Merge branch '3.x' into readresolve-secure-xmlinputfactory
cowtowncoder b8cf75b
Add release notes
cowtowncoder 883a015
Minor test tweak
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/tools/jackson/dataformat/xml/misc/DTDAfterSerializationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package tools.jackson.dataformat.xml.misc; | ||
|
|
||
| import java.io.*; | ||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import tools.jackson.core.exc.StreamReadException; | ||
| import tools.jackson.dataformat.xml.XmlMapper; | ||
| import tools.jackson.dataformat.xml.XmlTestUtil; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| // [dataformat-xml]: entity/DTD hardening must survive JDK serialization of the mapper | ||
| public class DTDAfterSerializationTest extends XmlTestUtil | ||
| { | ||
| // Internal entity that only expands when DTD processing is enabled | ||
| private static final String ENTITY_XML = | ||
| "<?xml version='1.0'?><!DOCTYPE foo [ <!ENTITY x \"HELLO\"> ]>\n" | ||
| + "<foo>&x;</foo>"; | ||
|
|
||
| private XmlMapper jdkRoundtrip(XmlMapper mapper) throws Exception { | ||
| ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
| try (ObjectOutputStream os = new ObjectOutputStream(bytes)) { | ||
| os.writeObject(mapper); | ||
| } | ||
| try (ObjectInputStream is = new ObjectInputStream( | ||
| new ByteArrayInputStream(bytes.toByteArray()))) { | ||
| return (XmlMapper) is.readObject(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDTDStaysDisabledAfterRoundtrip() throws Exception | ||
| { | ||
| XmlMapper mapper = jdkRoundtrip(new XmlMapper()); | ||
| // Must fail specifically because the parser refuses the DTD-declared | ||
| // entity (DTD support off), leaving `&x;` unexpanded -- not for some | ||
| // unrelated binding reason. Before the fix this expanded to "HELLO". | ||
| StreamReadException e = assertThrows(StreamReadException.class, | ||
| () -> mapper.readValue(ENTITY_XML, Map.class)); | ||
| verifyException(e, "Undeclared general entity", "entity"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.