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

Java: CWE-347 Query for detecting Signature Exclusion Attack with SAML assertion #6935

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
@luchua-bc
Copy link
Contributor

@luchua-bc luchua-bc commented Oct 22, 2021

SAML (Security Assertion Markup Language) is an XML-based markup language for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. It is used for security assertions, which are statements that service providers use to make access-control decisions. SAML response messages consist of issuer, assertion (subject, conditions, and statements), signing key, and signature.

If SAML token does not contain any signature, no protection of integrity or authenticity is provided. Since no digital signature for the token is required, an attacker can generate tokens containing arbitrary identities of other users.

Java applications use the JAXB (Java Architecture for XML Binding) API for unmarshalling (reading) XML instance documents into Java content trees, and then marshalling (writing) Java content trees back into XML instance documents. The Java XML Digital Signature APIs are specified in JSR-105 and are implemented in the javax.xml.crypto package, which are used to verify signature of SAML XML documents.

The query detects missing signature check against SAML assertion XML documents. Please consider to merge the PR. Thanks.

Copy link
Contributor

@atorralba atorralba left a comment

Hey @luchua-bc, thanks for your contribution! I added some inline comments.

java/ql/src/experimental/Security/CWE/CWE-347/SAML.qll Outdated Show resolved Hide resolved
java/ql/src/experimental/Security/CWE/CWE-347/SAML.qll Outdated Show resolved Hide resolved
java/ql/src/experimental/Security/CWE/CWE-347/SAML.qll Outdated Show resolved Hide resolved
java/ql/src/experimental/Security/CWE/CWE-347/SAML.qll Outdated Show resolved Hide resolved
}

/** Configuration of validating signature in XML file. */
class SamlAssertionSignatureCheckConf extends TaintTracking::Configuration {
Copy link
Contributor

@atorralba atorralba Oct 28, 2021

I'm not convinced about this second taint tracking configuration. Mainly, because if there's a path that goes through validation, its source is completely discarded, even if there's another unsafe path (i.e. that doesn't validate the signature) starting from that same source.

I experimented a bit with the query and managed to transform this into a sanitizer for the first Configuration that effectively has the same logic, but only discards the flows that go through validation. It also prunes the flows earlier when the sanitizer is found (instead of calculating all flows and then discarding those with a source that gets validated somewhere), which results in less nodes being generated.

The diff is too big to comprehensively add it as a suggestion so, if you agree, I can commit it directly to your branch (and we can further discuss it if needed after that).

Copy link
Contributor Author

@luchua-bc luchua-bc Oct 29, 2021

Thanks @atorralba for your help with optimizing this part. Yes, please commit it directly to my branch.

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