fix(LicenseInfo): harden XML parsers against XXE in SPDXParser and AbstractCLIParser#3891
Open
saiteja-in wants to merge 1 commit intoeclipse-sw360:mainfrom
Open
fix(LicenseInfo): harden XML parsers against XXE in SPDXParser and AbstractCLIParser#3891saiteja-in wants to merge 1 commit intoeclipse-sw360:mainfrom
saiteja-in wants to merge 1 commit intoeclipse-sw360:mainfrom
Conversation
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.
Issue: #3890
Changes
1.
SPDXParser.openAsSpdx()—DocumentBuilderFactoryhardeningFile:
backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/SPDXParser.javaBefore (vulnerable):
After (hardened):
newInstance()tonewDefaultInstance()(matchesgetDocument()pattern)AbstractCLIParser.getDocument())setNamespaceAware(true)— required for SPDX RDF parsing (rdf:,spdx:namespace prefixes)disallow-doctype-declis the strongest defense: rejects all DOCTYPE declarations at parse time2.
AbstractCLIParser.hasThisXMLRootElement()—XMLInputFactoryhardeningFile:
backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/AbstractCLIParser.javaBefore (vulnerable):
After (hardened):
XMLInputFactory(StAX) uses a different API thanDocumentBuilderFactory(DOM)IS_SUPPORTING_EXTERNAL_ENTITIES = false— disables external entity resolutionSUPPORT_DTD = false— disables DTD processing entirely (strongest protection for StAX)XMLInputFactory3.
SPDXParserTest— test consistency + XXE regression testFile:
backend/licenseinfo/src/test/java/org/eclipse/sw360/licenseinfo/parsers/SPDXParserTest.javatestAddSPDXContentToCLIto use the same hardenedDocumentBuilderFactoryconfiguration as production code (ensures tests validate behavior with the secured parser, not a different config)testXXEAttackIsBlocked()— a regression test that:<!DOCTYPE>XXE entity pointing tofile:///etc/passwdSPDXParser.getLicenseInfos()public APISW360Exceptionor returns non-SUCCESS status)Suggest Reviewer