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

[Bug] MSAL.Net incorrectly detects SAML1.1 token leading to error "AADSTS7500514: A supported type of SAML response was not found" (Ping Federation) #1871

Closed
6 tasks
bachoang opened this issue Jun 8, 2020 · 10 comments
Assignees
Labels
Milestone

Comments

@bachoang
Copy link

bachoang commented Jun 8, 2020

Which Version of MSAL are you using ?
Note that to get help, you need to run the latest version. Preview version are also ok.
For ADAL, please log issues to https://github.com/AzureAD/azure-activedirectory-library-for-dotnet

This problem exists in all version of MSAL including the latest version v4.14.0
Platform

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Auth
    • [ x] Username Password
    • Device code flow (browserless)
  • Web App
    • Authorization code
    • OBO
  • Web API
    • OBO

Other? - please describe;

Is this a new or existing app?

Repro
This is the same problem that ADAL.Net has for Federated scenario, see the following github issues for background info:

AzureAD/azure-activedirectory-library-for-dotnet#893
AzureAD/azure-activedirectory-library-for-dotnet#420

Environment:
Azure AD is federated with another IDP like ADFS, PingFederate, etc...

When authenticating with a UserName and Password, MSAL (and ADAL) uses SAML Assertion Grant flow (https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-saml-bearer-assertion) to request a SAML token from the IDP and then exchange that SAML token for an JWT OAuth2 token. The problem is typically seen with PingFederate since Ping issues a SAML v1.1 token. MSAL incorrectly detects the SAML token version as V2.0 token and hence sends the v2 token bearer with a v1.1 token payload to Azure AD, which causes the above AADSTS error.

Below is the code snippet that causes the problem:

            var pcaOptions = new PublicClientApplicationOptions
            {
                ClientId = "app id",
                TenantId = "Directory ID"
            };

            var pca = PublicClientApplicationBuilder
                .CreateWithApplicationOptions(pcaOptions).Build();

            var ewsScope = new string[] { "https://graph.microsoft.com/.default };

            var s = new System.Security.SecureString();
             s.AppendChar('p');
             s.AppendChar('a');
             s.AppendChar('a');
             s.AppendChar('s');
             s.AppendChar('s');
             s.AppendChar('w');
             s.AppendChar('o');
             s.AppendChar('r');
             s.AppendChar('d');

             var authResult = await pca.AcquireTokenByUsernamePassword(ewsScope, "user@contoso.com", s).ExecuteAsync();  // contoso.com is a federated domain

Expected behavior
AAD returns a successful JWT access token

Actual behavior
AAD returns error : AADSTS7500514: A supported type of SAML response was not found. The supported response types are 'Response' (in XML namespace 'urn:oasis:names:tc:SAML:2.0:protocol') or 'Assertion' (in XML namespace 'urn:oasis:names:tc:SAML:2.0:assertion').

Possible Solution

Additional context/ Logs / Screenshots
Fiddler trace analysis:

  1. MSAL (after performing a home realm discovery) sends a POST request to the IDP (PingFederate in this case) to get a SAML token using WS-Trust protocol:

POST https://pingfedactive..com/idp/sts.wst?TokenProcessorId=O365Token

Body:
WS Trust XML Payload containing username and password

response:
HTTP/1.1 200 OK
...
Content-Type: application/soap+xml; charset=utf-8

payload:
<s:Body>
<wst13:RequestSecurityTokenResponseCollection xmlns:wst13="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
....
wst13:RequestSecurityTokenResponse
wst13:TokenTypehttp://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1</wst13:TokenType>
wst13:RequestedSecurityToken
<s:Body>
<wst13:RequestSecurityTokenResponseCollection xmlns:wst13="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
wst13:RequestSecurityTokenResponse
wst13:TokenTypehttp://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1</wst13:TokenType>
wst13:RequestedSecurityToken

*** Note in the above response, the IDP returns the following TokenType (Token version) and that's what leads to the problem.
wst13:TokenTypehttp://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1</wst13:TokenType>
wst13:RequestedSecurityToken

MSAL's detection logic parses the token type above and thinks this is a SAML V2 token so it sends the following POST request to AAD to exchange for the JWT token:

POST https://login.microsoftonline.com/Directory ID/oauth2/v2.0/token
body:
client_id=xxx
&client_info=1
&scope=openid offline_access profile https://graph.microsoft.com/.default
&grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer
&assertion=SAML1.1 Assertion

response:
400 Bad Request
error_description":"AADSTS7500514: A supported type of SAML response was not found. The supported response types are 'Response' (in XML namespace 'urn:oasis:names:tc:SAML:2.0:protocol') or 'Assertion' (in XML namespace 'urn:oasis:names:tc:SAML

**** MSAL should send the following grant_type for a V1.1 token:
urn:ietf:params:oauth:grant-type:saml1_1-bearer

The bug is in the following file detecting the SAML Token version:
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/1cef43d185bb0a1dcc013d2ec232ae9d4c6c053a/src/client/Microsoft.Identity.Client/WsTrust/WsTrustResponse.cs
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/20f633ac1ceea4cbb9dd3f1fa7ea9236be4322ac/src/client/Microsoft.Identity.Client/Internal/Requests/UsernamePasswordRequest.cs

Basically MSAL just looks at the WS Trust response to look for the following TokenType node:
"urn:oasis:names:tc:SAML:1.0:assertion"
If the above TokenType value exists then it's a SAML 1.1 token, everything else must be SAML 2.0 token. This is the wrong logic. The above tokentype is what ADFS uses but that may not be the correct version based on the Token Version specification.

Based on the following specification, the SAML token version value should be the following:

http://docs.oasis-open.org/wss-m/wss/v1.1.1/os/wss-SAMLTokenProfile-v1.1.1-os.html

Section 3.4:

Assertion Version
Value

V1.1 <================
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1

V2.0
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0

This bug has been around long enough and we need to fix this so MSAL can support other federated IDPs, and not just ADFS.

Summary:
MSAL should correctly detect the SAML1.1 token if the TokenType is one of the following:
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1 or
urn:oasis:names:tc:SAML:1.0:assertion

grant_type=urn:ietf:params:oauth:grant-type:saml1_1-bearer

and use the following grant_type for SAML2.0 TokenType:
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0

grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer

@jmprieur jmprieur added the bug label Jun 9, 2020
@jmprieur
Copy link
Contributor

jmprieur commented Jun 9, 2020

@bachoang could it be a configuration issue with the federation server? or are you sure this is a bug in MSAL.NET (and ADAL.NET)?

@bachoang
Copy link
Author

bachoang commented Jun 9, 2020

@jmprieur based on everything I am seeing and comparing it to the specification. I don't see anything the IDP is doing incorrectly. The IDP is sending back a SAML 1.1 token in their Assertion element below:

saml:Assertion [ AssertionID=NX1Mbx7WnPnhbLgAf8t2JQS1c7W IssueInstant=2020-05-11T15:53:24.967Z Issuer=MerckPingIDPWSFedPROD MajorVersion=1 MinorVersion=1 xmlns:saml=urn:oasis:names:tc:SAML:1.0:assertion ]

Based on the token profile specification (section 3.4 Table 3) at https://www.oasis-open.org/committees/download.php/16768/wss-v1.1-spec-os-SAMLTokenProfile.pdf

specifying the TokenType element to be "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" is the correct value for a SAML 1.1 token.

Unfortunately ADFS does not adhere to the standards. I have asked this question on the ADFS engineering team but no one can give me a straight answer. ADFS has been around for 15 years so it might have carried a lot of legacy behavior forward (perhaps even before the standards was defined).

MSAL should be able to detect the correct SAML token version for any IDP (and not just geared for ADFS).

@bgavrilMS bgavrilMS added this to Todo/Committed in MSAL.NET (legacy) via automation Jun 11, 2020
@bgavrilMS bgavrilMS moved this from Todo/Committed to vNext in MSAL.NET (legacy) Jun 11, 2020
@bgavrilMS bgavrilMS added the P1 label Jun 11, 2020
@bgavrilMS
Copy link
Member

P1 because it is a blocker for migration of v1 to v2

@bgavrilMS bgavrilMS moved this from vNext to Todo/Committed in MSAL.NET (legacy) Jun 22, 2020
@bgavrilMS bgavrilMS added this to the 4.16.0 milestone Jun 22, 2020
@bgavrilMS bgavrilMS moved this from Todo/Committed to vNext in MSAL.NET (legacy) Jun 25, 2020
@bgavrilMS bgavrilMS moved this from vNext to Todo/Committed in MSAL.NET (legacy) Jun 25, 2020
@bgavrilMS bgavrilMS changed the title [Bug] MSAL.Net incorrectly detects SAML1.1 token leading to error "AADSTS7500514: A supported type of SAML response was not found" [Bug] MSAL.Net incorrectly detects SAML1.1 token leading to error "AADSTS7500514: A supported type of SAML response was not found" (Ping Federation) Jul 7, 2020
@bgavrilMS bgavrilMS added P2 and removed P1 labels Jul 7, 2020
@bgavrilMS bgavrilMS modified the milestones: 4.16.0, 4.17.0 Jul 8, 2020
@neha-bhargava
Copy link
Contributor

Fixed in MSAL 4.17.0 release

@bgavrilMS
Copy link
Member

Not fixed.

@bgavrilMS bgavrilMS modified the milestones: 4.17.0, 4.18.0 Jul 28, 2020
@jennyf19
Copy link
Collaborator

@bgavrilMS @neha-bhargava What's the status on this?

@bgavrilMS
Copy link
Member

Parsing the MEX document and understanding SAML is very difficult and I do not have enough expertise or test resources to make meaningful progress. I am marking this item as blocked until we can find better guidance (C++ or WAM?)

@jmprieur @henrik-me

@bgavrilMS bgavrilMS removed this from the 4.18.0 milestone Aug 18, 2020
@bgavrilMS bgavrilMS moved this from Todo/Committed to Blocked in MSAL.NET (legacy) Aug 18, 2020
@bgavrilMS
Copy link
Member

For an example SAML response that can be used for Integrated Windows Auth, please see

https://sts.usystech.net/adfs/services/trust/2005/issuedtokenmixedsymmetricbasic256

@henrik-me
Copy link
Contributor

@jmprieur for evaluating priority

@jmprieur
Copy link
Contributor

jmprieur commented Nov 5, 2020

Closing a duplicate of #2152 which is better explained.
and moving to 4.24.0

@jmprieur jmprieur closed this as completed Nov 5, 2020
@jmprieur jmprieur added this to the 4.24.0 milestone Nov 5, 2020
@bgavrilMS bgavrilMS removed this from Blocked/Waiting for reply in MSAL.NET (legacy) Nov 5, 2020
@jmprieur jmprieur added duplicate and removed blocked labels Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants