Validate namespace and local name in require#36915
Open
junhyeong9812 wants to merge 1 commit into
Open
Conversation
AbstractXMLStreamReader.require(int, String, String) only checked the event type and ignored the namespaceURI and localName arguments, so a mismatched name or namespace passed silently, contrary to the XMLStreamReader#require contract where a non-null namespaceURI or localName must match the current event. Validate the local name and namespace against the current event. This reader exposes a name only for START_ELEMENT and END_ELEMENT, so a non-null name or namespace on any other event is reported as a mismatch. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
AbstractXMLStreamReader(the base forXMLEventStreamReader, reachable via the publicStaxUtils.createEventStreamReader(XMLEventReader)) implementsrequire(int expectedType, String namespaceURI, String localName).Problem
requireonly compared the event type; thenamespaceURIandlocalNamearguments were ignoredentirely:
So a mismatched name or namespace passed silently, contrary to the
XMLStreamReader#require(int, String, String)contract: whennamespaceURI/localNamearenon-null they must match the current event, otherwise an
XMLStreamExceptionis thrown. The methodhas only ever validated the event type since the class was introduced, and there are no in-tree
callers, so it went unnoticed.
Fix
Validate
localNameandnamespaceURIagainst the current event. A test is added toXMLEventStreamReaderTests.Note on scope
This reader exposes a name and namespace only for
START_ELEMENTandEND_ELEMENT(
getName()is defined only for those states). Accordingly, a non-null name or namespace on anyother event type is treated as a mismatch and reported via
XMLStreamException.ENTITY_REFERENCElocal-name validation (permitted by the spec) is intentionally not attempted, because this reader
cannot expose entity names —
getName()throwsIllegalStateExceptionoutside of element events.This keeps
requirehonest (it never silently accepts a non-matching name) within what the readercan actually observe; happy to adjust the scope if maintainers prefer a different boundary.