Skip to content

Commit

Permalink
Modify rule S6377: Change text to education framework format (APPSEC-…
Browse files Browse the repository at this point in the history
…1110) (#3164)

## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
  • Loading branch information
sebastien-andrivet-sonarsource authored Sep 29, 2023
1 parent 38c07d1 commit 6a11e47
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
16 changes: 0 additions & 16 deletions rules/S6377/description.adoc

This file was deleted.

2 changes: 1 addition & 1 deletion rules/S6377/java/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"tags": [
"symbolic-execution"
]
}
}
52 changes: 43 additions & 9 deletions rules/S6377/java/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
XML signatures are a method used to ensure the integrity and authenticity of XML documents. However, if XML signatures are not validated securely, it can lead to potential vulnerabilities.

== Why is this an issue?

include::../description.adoc[]
Before Java 17, XML Digital Signature API does not apply restrictions on XML signature validation unless the application runs with a security manager, which is rare.

== What is the potential impact

By not enforcing secure validation, the XML Digital Signature API is more susceptible to attacks such as signature spoofing and injections.

=== Increased Vulnerability to Signature Spoofing

By disabling secure validation, the Java application becomes more susceptible to signature spoofing attacks. Attackers can potentially manipulate the XML signature in a way that bypasses the validation process, allowing them to forge or tamper with the signature. This can lead to the acceptance of invalid or maliciously modified signatures, compromising the integrity and authenticity of the XML documents.

=== Risk of Injection Attacks

Disabling secure validation can expose the application to injection attacks. Attackers can inject malicious code or entities into the XML document, taking advantage of the weakened validation process. In some cases, it can also expose the application to denial-of-service attacks. Attackers can exploit vulnerabilities in the validation process to cause excessive resource consumption or system crashes, leading to service unavailability or disruption.


== How to fix it in Java SE

=== Noncompliant code example
=== Code examples

[source,java]
For versions of Java before 17, secure validation is disabled by default unless the application runs with a security manager, which is rare. It should be enabled explicitly by setting the ``org.jcp.xml.dsig.secureValidation`` attribute to true with the ``javax.xml.crypto.dsig.dom.DOMValidateContext.setProperty`` method.

For Java 17 and higher, secure validation is enabled by default.

==== Noncompliant code example

[source,java,diff-id=1,diff-type=noncompliant]
----
NodeList signatureElement = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
Expand All @@ -15,10 +38,9 @@ XMLSignature signature = fac.unmarshalXMLSignature(valContext);
boolean signatureValidity = signature.validate(valContext);
----

=== Compliant solution
In order to benefit from this secure validation mode, set the DOMValidateContext's ``org.jcp.xml.dsig.secureValidation`` property to ``TRUE``.
==== Compliant solution

[source,java]
[source,java,diff-id=1,diff-type=compliant]
----
NodeList signatureElement = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
Expand All @@ -30,12 +52,24 @@ XMLSignature signature = fac.unmarshalXMLSignature(valContext);
boolean signatureValidity = signature.validate(valContext);
----

=== How does this work?

When XML Signature secure validation mode is enabled, XML Signatures are processed more securely. It enforces a number of restrictionsto to protect from XML Documents that may contain hostile constructs that can cause denial-of-service or other types of security issues.

These restrictions can protect you from XML Signatures that may contain potentially hostile constructs that can cause denial-of-service or other types of security issues.

== Resources

* https://docs.oracle.com/en/java/javase/14/security/java-xml-digital-signature-api-overview-and-tutorial.html#GUID-DB46A001-6DBD-4571-BDBC-1BBC394BF61E[Oracle Java Documentation] - XML Digital Signature API Overview and Tutorial
* https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure[OWASP Top 10 2017 Category A3] - Sensitive Data Exposure
* https://cwe.mitre.org/data/definitions/347[MITRE, CWE-347] - Improper Verification of Cryptographic Signature
=== Documentation

* Oracle Java Documentation - https://docs.oracle.com/en/java/javase/21/security/java-xml-digital-signature-api-overview-and-tutorial.html[XML Digital Signature API Overview and Tutorial]

=== Standards

* OWASP - https://owasp.org/Top10/A02_2021-Cryptographic_Failures/[Top 10:2021 A02:2021 - Cryptographic Failures]
* OWASP - https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure[Top 10 2017 Category A3 -Sensitive Data Exposure]
* CWE - https://cwe.mitre.org/data/definitions/347[CWE-347 - Improper Verification of Cryptographic Signature]


ifdef::env-github,rspecator-view[]

Expand Down
10 changes: 0 additions & 10 deletions rules/S6377/rule.adoc

This file was deleted.

0 comments on commit 6a11e47

Please sign in to comment.