-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow DOCTYPE element in SAML responses to prevent XXE vulnerabili…
…ties (#38)
- Loading branch information
Showing
3 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: java | ||
|
||
jdk: | ||
- oraclejdk8 | ||
- openjdk8 | ||
|
||
cache: | ||
directories: | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -217,4 +217,22 @@ public void decodeAndValidateSamlResponseRejectsNowBeforeNotBefore() throws Thro | |
SamlResponse response = client.decodeAndValidateSamlResponse(AN_ENCODED_RESPONSE); | ||
assertEquals("[email protected]", response.getNameID()); | ||
} | ||
|
||
// Test for https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html | ||
@Test | ||
public void itIsNotVulnerableToXXEAttacks() throws Throwable { | ||
String decoded = new String(Base64.decodeBase64(AN_ENCODED_RESPONSE), StandardCharsets.UTF_8); | ||
String withDtd = "<!DOCTYPE note SYSTEM \"Note.dtd\">" + decoded; | ||
SamlClient client = | ||
SamlClient.fromMetadata( | ||
"myidentifier", "http://some/url", getXml("adfs.xml"), SamlClient.SamlIdpBinding.POST); | ||
client.setDateTimeNow(ASSERTION_DATE); | ||
try { | ||
client.decodeAndValidateSamlResponse( | ||
Base64.encodeBase64String(withDtd.getBytes(StandardCharsets.UTF_8))); | ||
assertTrue(false); | ||
} catch (SamlException ex) { | ||
assertTrue(ex.getCause().toString().contains("DOCTYPE is disallowed")); | ||
} | ||
} | ||
} |