-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(xml): ship an XSD for testng.xml alongside the DTD #3325
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
Open
juherr
wants to merge
7
commits into
testng-team:master
Choose a base branch
from
juherr:juherr/xml-xsd-alongside-dtd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0af93d8
fix(xml): re-enable DTD validation and stop losing data in toXml()
juherr e83e6a0
fix(xml): make validation self-consistent and stop it depending on JV…
juherr dd4dd49
fix(xml): let the validation mode take effect after start-up
juherr 9b4e342
test(xml): clean up the temporary DTD fixture
juherr b8b3b7c
test(xml): keep fixture cleanup from masking a test failure
juherr 93b504b
refactor(test): extract the suite corpus helpers out of XmlRoundTripTest
juherr 9b6382f
feat(xml): ship testng-1.1.xsd alongside the DTD
juherr 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
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
69 changes: 69 additions & 0 deletions
69
testng-core/src/main/java/org/testng/xml/XmlValidationMode.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,69 @@ | ||
| package org.testng.xml; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Locale; | ||
| import org.testng.internal.RuntimeBehavior; | ||
| import org.testng.log4testng.Logger; | ||
|
|
||
| /** | ||
| * How strictly a suite file is checked against the TestNG DTD, selected with the {@code | ||
| * testng.xml.validation} system property. | ||
| * | ||
| * <p>Validation used to be silently disabled: {@code XMLParser} probed the SAX validation feature | ||
| * under an {@code https} identifier, which no parser recognizes, so {@code setValidating(true)} was | ||
| * never reached and DTD violations went unreported. Turning it back on means suite files that have | ||
| * been accepted for years can suddenly be rejected -- the DTD constrains the order of the children | ||
| * of {@code <suite>}, for instance -- so {@link #WARN} is the default for now and reports | ||
| * violations without failing the run. | ||
| * | ||
| * <p>The property is read once per parse, never in the middle of one. {@code XMLParser} rebuilds | ||
| * its shared parser when the mode has changed since the last parse, which decides <em>whether</em> | ||
| * violations are raised at all, and {@code TestNGContentHandler} captures the mode when it is | ||
| * constructed, which decides <em>how</em> they are reported. Changing the property therefore takes | ||
| * effect from the next parse onwards, including when moving away from {@link #OFF}; changing it | ||
| * while a parse is in flight has no effect on that parse. | ||
| */ | ||
| public enum XmlValidationMode { | ||
|
|
||
| /** Do not validate at all. */ | ||
| OFF, | ||
|
|
||
| /** Validate and report violations as warnings. The default. */ | ||
| WARN, | ||
|
|
||
| /** Validate and fail on the first violation. */ | ||
| STRICT; | ||
|
|
||
| private static final XmlValidationMode DEFAULT = WARN; | ||
|
|
||
| public boolean isValidating() { | ||
| return this != OFF; | ||
| } | ||
|
|
||
| /** | ||
| * The mode requested by the {@code testng.xml.validation} system property, falling back to {@link | ||
| * #WARN} when the property is absent or holds an unknown value. | ||
| */ | ||
| public static XmlValidationMode current() { | ||
| String requested = RuntimeBehavior.getXmlValidationMode(); | ||
| if (requested == null || requested.trim().isEmpty()) { | ||
| return DEFAULT; | ||
| } | ||
| try { | ||
| return valueOf(requested.trim().toUpperCase(Locale.ROOT)); | ||
| } catch (IllegalArgumentException e) { | ||
| Logger.getLogger(XmlValidationMode.class) | ||
| .warn( | ||
| "Unknown value [" | ||
| + requested | ||
| + "] for the system property [" | ||
| + RuntimeBehavior.XML_VALIDATION_MODE | ||
| + "]. Expected one of " | ||
| + Arrays.toString(values()) | ||
| + ". Falling back to [" | ||
| + DEFAULT | ||
| + "]."); | ||
| return DEFAULT; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
JAXP SAXParserFactory FEATURE_SECURE_PROCESSING billion laughs protection default💡 Result:
In the Java Development Kit (JDK), the SAXParserFactory has the FEATURE_SECURE_PROCESSING (FSP) feature enabled by default [1][2][3]. When FSP is enabled—either by default or through explicit configuration—the JDK enforces various security limits to protect against common XML-based attacks, including the "billion laughs" (exponential entity expansion) attack [1][3][4]. Key aspects of this default behavior include: 1. Processing Limits: With FSP enabled, the XML parser adheres to specific security properties that limit resource consumption, such as entity expansion limits and maximum occurrences of elements [1][2][5]. These limits directly mitigate the risk of denial-of-service attacks like the billion laughs attack [3][4]. 2. Default Status: While FSP is true by default for SAX, DOM, and validation factories, the JDK differentiates between this "default enabled" state and "explicitly set" state in older versions [6]. However, modern JDK security guidelines emphasize that these parsers observe secure processing limits by default [3][4]. 3. External Connections: Enabling FSP by default provides a baseline of protection; however, it does not automatically disable external connections (such as external entity resolution) [1][2][5]. To fully restrict external access, you must explicitly configure properties such as accessExternalDTD and accessExternalSchema [1][2][4]. 4. Explicit Configuration: To ensure a consistent security posture, it is a recommended practice to explicitly set the feature in your application code [3]: SAXParserFactory spf = SAXParserFactory.newInstance; spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Citations:
🏁 Script executed:
Repository: testng-team/testng
Length of output: 12957
🏁 Script executed:
Repository: testng-team/testng
Length of output: 28819
Secure the SAX factory before enabling DTD validation.
spf.newSAXParser()is created withoutXMLConstants.FEATURE_SECURE_PROCESSING; theEntityResolveronly controls external DTD/entity fetching and does not protect against internal-entity-exansion attacks such as “billion laughs”. With DTD validation re-enabled, configure the SAX parser with secure processing, and disable external DTD access unless it is intentionally required.🧰 Tools
🪛 ast-grep (0.45.0)
[warning] 69-69: SAXParser created without secure processing is vulnerable to XXE
Context: spf.newSAXParser()
Note: [CWE-611] Improper Restriction of XML External Entity Reference.
(xml-parsing-xxe-saxparser)
🤖 Prompt for AI Agents
Source: Linters/SAST tools