Skip to content
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

update for missing a couple possibly unsafe xml parser #902

Merged
merged 6 commits into from
Feb 2, 2024
Merged

update for missing a couple possibly unsafe xml parser #902

merged 6 commits into from
Feb 2, 2024

Conversation

Crispy-fried-chicken
Copy link
Contributor

@Crispy-fried-chicken Crispy-fried-chicken commented Jan 31, 2024

Fixes #901

@CLAassistant
Copy link

CLAassistant commented Jan 31, 2024

CLA assistant check
All committers have signed the CLA.

Comment on lines 101 to 103
} catch (ParserConfigurationException e) {
log.warn(e);
}
Copy link

Choose a reason for hiding this comment

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

Note that catching and swallowing the exception makes it possible to return a document builder factory which is still vulnerable!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've already delete this block, please check it again, thank you!

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution! I have a couple of comments that should be easy to address. Also you will need to agree to the CLA before we can merge this contribution (see the comment on the PR by the bot).

@@ -94,14 +94,25 @@ public static <T> DefaultXMLValueProvider<T> getValueFromTag(
return new DefaultXMLValueProvider<>(null, klass);
}

public DocumentBuilderFactory safeDocumentBuilderFactory() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method should be static. Also can we add a bit of Javadoc as to its purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course! Thanks for your comment.

Comment on lines 92 to 102
public DocumentBuilderFactory safeDocumentBuilderFactory() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://apache.org/xml/features/dom/create-entity-ref-nodes", false);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
return dbf;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once we make the XMLUtil#safeDocumentBuilderFactory method static, we can get rid of this method, and just call XMLUtil.safeDocumentBuilderFactory() below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I've already make the XMLUtil#safeDocumentBuilderFactory method static. please check it again, Thank you!

@@ -16,7 +16,7 @@
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* OUT OF OR IN CONNECTION WITH com.uber.nullaway.fixserializationTHE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we revert this change? we shouldn't modify license headers unless there's a reason

Comment on lines 92 to 93


Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you run our configured formatter (./gradlew spotlessApply) on this PR?

We try to be consistent in formatting and these two blank lines don't seem right.

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

In addition to the comment, based on the CI run looks like there are compile errors. You can run ./gradlew compileJava to ensure that all the code compiles

@@ -94,14 +94,25 @@ public static <T> DefaultXMLValueProvider<T> getValueFromTag(
return new DefaultXMLValueProvider<>(null, klass);
}

public static DocumentBuilderFactory safeDocumentBuilderFactory() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add Javadoc describing what this method does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what your project use is jdk 21?

Copy link
Collaborator

Choose a reason for hiding this comment

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

JDK 21 is required in order to run certain tests. Sorry for the hassle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I‘ve already pushed and the ./gradlew spotlessApply is run successfully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the cli ./gradlew compileJava is failed cause it need to use jdk8? I don't know why, but I think it's not caused by the code I've added. Please check it again, and I will try to fix it if you find any error again. Feel sorry to trouble you again.

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@msridhar msridhar enabled auto-merge (squash) February 2, 2024 15:46
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (00a317a) 86.99% compared to head (dcafa95) 86.98%.

Files Patch % Lines
...va/com/uber/nullaway/fixserialization/XMLUtil.java 83.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #902      +/-   ##
============================================
- Coverage     86.99%   86.98%   -0.01%     
- Complexity     1958     1959       +1     
============================================
  Files            77       77              
  Lines          6319     6330      +11     
  Branches       1223     1223              
============================================
+ Hits           5497     5506       +9     
- Misses          418      420       +2     
  Partials        404      404              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@msridhar msridhar merged commit 848b0b1 into uber:master Feb 2, 2024
10 of 12 checks passed
@Crispy-fried-chicken
Copy link
Contributor Author

Thanks for the contribution!

Thank you for your merge! Considering the possible information leakage consequences of this vulnerability, maybe we can request for a CVE-ID?

@msridhar
Copy link
Collaborator

msridhar commented Feb 2, 2024

Sorry no, I do not believe this deserves a CVE. See my previous comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Security Vulnerability - Action Required: XXE vulnerability in the newest version of the NullAway
5 participants