-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW: Added a unit test to validate that the XML parsing behavior used …
…is not vulnerable to a comment injection attack.
- Loading branch information
Torben Werner
committed
Mar 6, 2018
1 parent
319306b
commit a962dc7
Showing
3 changed files
with
82 additions
and
20 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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"compress/flate" | ||
|
||
"github.com/beevik/etree" | ||
"github.com/russellhaering/gosaml2/types" | ||
"github.com/russellhaering/goxmldsig" | ||
require "github.com/stretchr/testify/require" | ||
) | ||
|
@@ -253,3 +254,35 @@ func TestInvalidResponseNoElement(t *testing.T) { | |
require.EqualError(t, err, "unable to parse response") | ||
require.Nil(t, response) | ||
} | ||
func TestSAMLCommentInjection(t *testing.T) { | ||
/* | ||
Explanation: | ||
See: https://duo.com/blog/duo-finds-saml-vulnerabilities-affecting-multiple-implementations | ||
The TLDR is that XML canonicalization may result in a different value being signed from the one being retrieved. | ||
The target of this is the NameID in the Subject of the SAMLResponse Assertion | ||
Example: | ||
The following Subject | ||
```<Subject> | ||
<NameID>[email protected]<!---->.evil.com</NameID> | ||
</Subject>``` | ||
would get canonicalized to | ||
``` | ||
<Subject> | ||
<NameID>[email protected]</NameID> | ||
</Subject> | ||
``` | ||
Many XML parsers have a behavior where they pull the first text element, so in the example with the comment, a vulnerable XML parser would return `[email protected]`, ignoring the text after the comment. | ||
Knowing this, a user ([email protected]) can attack a vulnerable SP by manipulating their signed SAMLResponse with a comment that turns their username into another one. | ||
*/ | ||
|
||
// To show that we are not vulnerable, we want to prove that we get the canonicalized value using our parser | ||
_, el, err := parseResponse([]byte(commentInjectionAttackResponse)) | ||
require.NoError(t, err) | ||
decodedResponse := &types.Response{} | ||
err = xmlUnmarshalElement(el, decodedResponse) | ||
require.NoError(t, err) | ||
require.Equal(t, "[email protected]", decodedResponse.Assertions[0].Subject.NameID.Value, "The full, canonacalized NameID should be returned.") | ||
} |
Oops, something went wrong.