Skip to content

Conversation

@nscuro
Copy link
Member

@nscuro nscuro commented Nov 2, 2025

@nscuro nscuro added the bug Something isn't working label Nov 2, 2025
@nscuro nscuro requested a review from a team as a code owner November 2, 2025 19:52
@nscuro nscuro force-pushed the fix-schemafactory-config branch from 66161f8 to 658183c Compare November 2, 2025 19:54
@codacy-production
Copy link

codacy-production bot commented Nov 2, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.08% 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (1d9ecdb) 6456 4844 75.03%
Head commit (af0ec75) 6460 (+4) 4852 (+8) 75.11% (+0.08%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#737) 4 4 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@jkowalleck jkowalleck requested a review from Copilot November 3, 2025 09:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds XXE (XML External Entity) protection to prevent security vulnerabilities when parsing XML BOMs.

  • Added security properties to SchemaFactory to disable external DTD and schema access
  • Implemented a comprehensive test that validates XXE protection by attempting an actual network connection
  • Updated version from 11.1.0-SNAPSHOT to 11.0.1-SNAPSHOT (patch release)

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/org/cyclonedx/CycloneDxSchema.java Added XXE protection by restricting external DTD and schema access
src/test/java/org/cyclonedx/parsers/XmlParserTest.java Added test with server socket to verify XXE protection works correctly
src/test/resources/security/xxe-protection.xml Updated port number to 6666 to match the test implementation
pom.xml Changed version from 11.1.0-SNAPSHOT to 11.0.1-SNAPSHOT
README.md Updated version reference to 11.0.1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

final AtomicBoolean receivedConnection = new AtomicBoolean(false);

final ExecutorService executor = Executors.newSingleThreadExecutor();
try (final ServerSocket serverSocket = new ServerSocket(6666)) {
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded port 6666 may conflict with existing services or fail in restricted environments. Consider using port 0 to let the OS assign an available ephemeral port, then retrieve it with serverSocket.getLocalPort() and update the test XML dynamically.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified the fixture to reference a file path instead. The tests now assert on specific failure messages indicating that external resolution was blocked. Whether or not the file actually exists in then no longer relevant.

@nscuro nscuro force-pushed the fix-schemafactory-config branch from 658183c to 4a0121c Compare November 3, 2025 09:27

public Schema getXmlSchema(InputStream... inputStreams) throws SAXException {
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this actually prevent XEE? or does it only prevent unintended network access?

what about XMLConstants.FEATURE_SECURE_PROCESSING ?
what about schemaFactory.setExpandEntityReferences(false);?
or similar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schemaFactory.setExpandEntityReferences doesn't exist.

The ACCESS_EXTERNAL_* values are a list of protocols which are allowed, setting it to empty makes it disallow all:

I verified that this also prevents file:// access.

I will add FEATURE_SECURE_PROCESSING though, thanks for the tip.

@nscuro nscuro force-pushed the fix-schemafactory-config branch from 4a0121c to af0ec75 Compare November 3, 2025 10:13
@nscuro nscuro requested review from Copilot and jkowalleck November 3, 2025 10:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nscuro
Copy link
Member Author

nscuro commented Nov 6, 2025

@jkowalleck May I ask for a final look please?

@jkowalleck
Copy link
Member

LGTM, but I am no actual Java user.
Will formally approve to prevent any blockers.

If further review is needed, let me ping some potential reviewers: @DarthHater, @stevespringett, @mr-zepol, @mtsfoni, @hboutemy, @skhokhlov, @glefloch,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants