Skip to content
Access control Write-up Advanced

Azure Active Directory Flaw Allowed SAML Persistence

Secureworks Follow

Published on secureworks.com

In August 2022, Secureworks® Counter Threat Unit™ (CTU) researchers discovered a vulnerability in Azure Active Directory (Azure AD) that allowed a user to retain access to a targeted Security Assertion Markup Language (SAML) application after the user assignment was removed. Using a backdoor application that was given…

Secureworks Counter Threat Unit (@Secureworks), on secureworks.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Azure Active Directory (Azure AD) lets administrators configure SAML-based single sign-on (SSO) for pre-integrated and customer-developed services, referred to here as applications. When user assignment is required, users and groups must first be assigned to the application before they can access it. That assignment is the control an administrator relies on to revoke access: remove the user, and the application should no longer issue them anything.

Secureworks Counter Threat Unit (CTU) researchers found that this control could be bypassed. A user who had once been assigned to a SAML application could keep receiving valid SAML tokens for it after the assignment was removed, by chaining a backdoor application they controlled into the token request. The most lucrative target is a SAML application that relies solely on Azure AD's user assignment setting: if the application itself does not enforce assignment, the attacker can use the token to provision a new user for themselves in the target service.

The researchers reported the findings to Microsoft on 4 August 2022. Microsoft addressed the issue with mitigations initially deployed on 25 October.

Setup

The attack needs a tenant in which the attacker can register applications, and an existing SAML application to which the attacker currently has a valid user assignment. The attacker creates a new Azure AD application to act as a backdoor and consents it to the target SAML application while their assignment is still valid. No special tooling is described beyond a CLI application retrofitted with malicious code, discussed below.

The researchers note that although the vulnerability was trivially exploitable, it required a deep understanding of Azure AD applications and their configurations. Specifically:

  • Understanding on-behalf-of flows in Azure AD.
  • Understanding the use of non-standard flows to request a SAML token with a JWT.
  • Understanding Azure AD application consents and application permissions.
  • Understanding the use of SAML tokens outside the normal use pattern. The PoC abuses a CLI application with device code flow to gain a JWT, then exchanges it for a SAML token using the on-behalf-of pattern. This differs from the typical case where a web browser receives the SAML token by interfacing directly with the browser application.

Finding it

The flaw is triggered when chaining sign-in with an additional application and certain parameters in the token request. That use case was originally intended so that backend SAML APIs could be called from an OAuth 2.0 application. In other words, a legitimate middle-tier pattern was being reused to obtain a SAML token for an application the requesting user was no longer assigned to.

The attack process is summarised in Figure 1.

From the original on secureworks.com
  1. The malicious user requests an Azure AD access token for the additional application.

  2. The additional application requests a token for the SAML application using the on-behalf-of flow. The request payload includes the parameters listed in Figure 2.

    From the original on secureworks.com

    Chaining steps 1 and 2 bypasses the user assignment setting. The token generated in step 1 is used in the assertion parameter.

  3. The request response emits the SAML token.

Exploitation

In the proof-of-concept scenario, the attacker uses a backdoor application to reach any existing SAML applications they were assigned to when the backdoor application was configured. They retain access through the backdoor to those SAML applications after their access is removed.

Step 1: Create and consent the backdoor application

The malicious user creates a new Azure AD application to use as the backdoor, then consents it to any existing SAML application for which they want to receive tokens after the user assignment is removed. In the example shown in Figure 3, the backdoor application is named UnPrivilegedUserSAMLattack2 and it is used to access a generic application called SAML app, for which the malicious user had an existing user assignment.

From the original on secureworks.com

Step 2: The administrator removes the assignment

The application administrator removes the malicious user from the user assignment in the existing SAML application, as shown in Figure 4.

From the original on secureworks.com

Step 3: Request tokens through the backdoor

The malicious user requests tokens for the SAML application using the application configured in step 1. The backdoor application used in the PoC requests tokens by leveraging an unrelated app retrofitted with malicious code added to its getCode.js file. The lines referencing the requested token contain the following vulnerable parameter combination that bypasses the user assignment verification:

JavaScript
"requested_token_type":"urn:ietf:params:oauth:token-type:saml2",
JavaScript
"requested_token_use":"on_behalf_of"

The first parameter asks for a token of SAML 2.0 type rather than the usual access token, and the second selects the on-behalf-of flow. Together with the access token from the first leg, supplied as the assertion, they produce a SAML token for the target application even though the user assignment has been removed.

Evaluating the SAML token

The objective is to acquire a SAML token with a valid signature, issuer, audience and claims, as shown in Figure 5. The malicious user receives a SAML token comparable to one emitted using a legitimate access pattern, despite the lack of user assignment for the application. Testing concluded that additional claims configured for the SAML application, such as groups, were included in the maliciously obtained SAML token.

From the original on secureworks.com

Root cause

Chaining an additional application with certain parameters in the token request bypassed the user assignment setting. The on-behalf-of flow exists so a middle-tier application can exchange a token for a downstream API; here the same exchange, with requested_token_type set to urn:ietf:params:oauth:token-type:saml2 and requested_token_use set to on_behalf_of, emitted a SAML token for an application the user was no longer assigned to. The token was comparable to one emitted using a legitimate access pattern, and configured claims such as groups were included.

Two factors limited the exposure. Applications that support IdP-initiated SSO were affected; applications that only support SP-initiated SSO were not, because SP-initiated SSO requires the inResponseTo attribute in the SAML response. And applications that perform additional checks for user permissions or roles when receiving the token could prevent access even if the malicious user bypassed the user assignment on Azure AD.

Impact

A previously assigned user within the tenant boundary could retain access to an application via a backdoor application after the user assignment was removed, establishing persistence and potentially elevating privileges on targeted SAML applications. This was only possible if the user had valid access when the backdoor application was configured. The most lucrative target is a SAML application that relies solely on Azure AD's user assignment setting, where the absence of enforcement in the application could be exploited to provision a new user for the attacker in the target service.

Microsoft confirmed the attack pattern on 10 October and categorised it as an "important" elevation of privilege issue. Microsoft's response stated that it had fixed an issue in the Azure AD OAuth 2.0 protocol access token request when those requests are made by middle-tier applications that in turn use SAML-based authorisation to access back-end APIs, and that under certain circumstances the issue would allow users within a tenant inappropriate access to back-end application functionality.

Fix

Microsoft addressed the issue in mitigations initially deployed on 25 October, and stated that only correctly configured users will have access to the functionality of the back-end application. To reduce risk from similar threats, the researchers recommend that organisations prevent users from registering their own applications in the Azure AD tenant.

Variants to test

  • A positive result is a signed SAML assertion with the expected issuer, audience and claims for a user who should no longer have access.
  • A positive result is a token containing claims such as group membership that the application trusts for authorisation.
  • A positive result is continued token issuance after the user assignment is removed.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

Imagine a large office building where every door is opened with a badge. The building manager keeps a list of who is allowed through which door. When someone leaves a team, the manager crosses their name off the list, and the door should stop opening for them. That is the whole idea behind access control: remove the person from the list, and the door stays shut.

In August 2022, researchers at Secureworks Counter Threat Unit found that one particular door in Microsoft's cloud identity service, Azure Active Directory, kept opening for people whose names had been crossed off the list. The trick was to leave a second, hidden door propped open before the name was removed. Once that hidden door existed, the person could keep getting through the main door even after the manager had removed them.

In technical terms: Azure Active Directory (Azure AD) is Microsoft's cloud service that handles sign-in for organisations. It can be configured so that a user must be assigned to an application before they can use it. The researchers found that a user who had once been assigned could keep receiving valid sign-in tokens for that application after the assignment was removed, by chaining a second application they controlled into the token request. The researchers reported the issue to Microsoft on 4 August 2022, and Microsoft deployed mitigations on 25 October 2022.

This article walks through what the researchers found, step by step, explaining every concept from scratch. No prior security knowledge is assumed.

The pieces you need to know

Before the attack makes sense, a few everyday ideas need to be on the table.

What an application is here

In this context, an application is not something you install on your phone. It is a service that people sign in to, such as an internal HR portal, a project tracker, or a third-party tool the company pays for. Azure AD sits in front of these services and decides who gets in. The researchers call these services "applications" throughout.

What single sign-on (SSO) is

Single sign-on means you sign in once, and that one sign-in is accepted by many services. Think of a hotel key card: you check in once at reception, and the same card opens your room, the gym, and the pool. Without SSO you would have a separate key for every door.

Azure AD offers SSO using a standard called SAML, which is short for Security Assertion Markup Language. SAML is a way for one system (the identity provider, here Azure AD) to tell another system (the application) "this person is who they say they are, and here are some facts about them". Those facts travel in a small signed document called a SAML token or SAML assertion.

What a token is

A token is a small piece of data that proves something. A cinema ticket is a token: it proves you paid, and the usher trusts it because it looks genuine. A SAML token proves to an application that Azure AD has authenticated the user and that the user is allowed in. The application checks the token's signature (to make sure it really came from Azure AD), its issuer (who created it), its audience (which application it is meant for), and its claims (the facts inside, such as the user's name or group memberships).

What user assignment is

Azure AD lets an administrator require that users be assigned to an application before they can use it. The administrator maintains a list. If your name is on the list, you get in. If your name is removed, you should not. This is the control the whole story is about: it is the badge list from the opening comparison.

What an API is

An API (Application Programming Interface) is a way for one piece of software to talk to another. Think of a restaurant: the menu is the API, the kitchen is the service, and the waiter carries your order back and forth. You do not walk into the kitchen yourself; you ask through the waiter. In the same way, one application can ask another application for data or actions through its API.

What OAuth 2.0 is

OAuth 2.0 is a standard for granting one application limited access to something on your behalf, without handing over your password. When a website offers "Sign in with Google", that is OAuth at work. Azure AD uses OAuth 2.0 to issue access tokens, which are short-lived credentials an application can present to an API to prove it is allowed to call it.

What the on-behalf-of flow is

The on-behalf-of flow is a specific OAuth 2.0 pattern. It exists for a middle-tier application: a service that sits between the user and a back-end API. The middle tier receives a token from the user, and then exchanges that token for a new token that lets it call the back-end API on the user's behalf. The waiter takes your order (your token) to the kitchen and comes back with a dish (a new token for the kitchen). The kitchen never deals with you directly.

This flow was designed so that backend SAML APIs could be called from an OAuth 2.0 application. That legitimate purpose is exactly what the researchers abused.

What the vulnerability class means

The flaw is an access control bypass: a rule existed (only assigned users get tokens), but it could be bypassed by chaining an additional application into the token request. The rule was written down; it just was not applied on that path. This is a common category of bug: the check exists in the normal route but is missing in a side route.

The attack, step by step

The researchers summarise the attack in three steps. The diagram below shows the overall flow.

From the original on secureworks.com
  1. The malicious user requests an Azure AD access token for the additional application.

  2. The additional application requests a token for the SAML application using the on-behalf-of flow. The request payload includes the parameters listed in the next figure.

    From the original on secureworks.com

    Chaining steps 1 and 2 bypasses the user assignment setting. The token generated in step 1 is used in the assertion parameter.

  3. The request response emits the SAML token.

Why each step is taken:

  1. The attacker first needs a token for their own backdoor application. This is the ordinary, legitimate first leg of the on-behalf-of flow: prove who you are to the middle tier.
  2. The backdoor application then presents that token as the assertion in a second request, asking Azure AD to exchange it for a token for the target SAML application. This is the step that bypasses the user assignment setting.
  3. Azure AD returns a SAML token for the target application. The attacker now holds a valid ticket to a door they were supposed to be locked out of.

The proof of concept

A proof of concept (PoC) is a small demonstration that shows a vulnerability is real, without causing harm. The researchers built one to show the attack end to end.

In the PoC, the attacker uses a backdoor application to reach any existing SAML applications they were assigned to when the backdoor application was configured. They keep access through the backdoor to those SAML applications after their access is removed.

Step 1: Create and consent the backdoor application

The attacker creates a new Azure AD application to use as the backdoor, then consents it to any existing SAML application for which they want to receive tokens after the user assignment is removed. Consenting means granting the backdoor application permission to act toward the target application. Think of it as adding a trusted assistant to your account: the assistant can now do things on your behalf, and the assistant's permission does not automatically disappear when your own permission does.

In the example shown below, the backdoor application is named UnPrivilegedUserSAMLattack2 and it is used to access a generic application called SAML app, for which the malicious user had an existing user assignment.

From the original on secureworks.com

Why this step matters: the consent has to happen while the attacker still has a valid assignment. That is the window in which the backdoor is installed. After that, the backdoor stands on its own.

Step 2: The administrator removes the assignment

The application administrator removes the malicious user from the user assignment in the existing SAML application, as shown below.

From the original on secureworks.com

From the administrator's point of view, the job is done: the user is off the list, so the user should no longer get in. This is the moment the vulnerability becomes visible, because the user can still get in.

Step 3: Request tokens through the backdoor

The malicious user requests tokens for the SAML application using the application configured in step 1. The backdoor application used in the PoC requests tokens by leveraging an unrelated app retrofitted with malicious code added to its getCode.js file. The lines referencing the requested token contain the following vulnerable parameter combination that bypasses the user assignment verification:

JavaScript
"requested_token_type":"urn:ietf:params:oauth:token-type:saml2",
JavaScript
"requested_token_use":"on_behalf_of"

Line by line:

  • "requested_token_type":"urn:ietf:params:oauth:token-type:saml2" tells Azure AD what kind of token to return. Normally an OAuth request asks for an ordinary access token. Here it asks specifically for a SAML 2.0 token. The value on the right is a standard identifier (a URN) that names the SAML 2.0 token type.
  • "requested_token_use":"on_behalf_of" tells Azure AD which flow to use. Setting it to on_behalf_of selects the middle-tier exchange described earlier.

Together, these two parameters say: "use the on-behalf-of flow, and give me back a SAML token". The first parameter asks for a token of SAML 2.0 type rather than the usual access token, and the second selects the on-behalf-of flow. Together with the access token from the first leg, supplied as the assertion, they produce a SAML token for the target application even though the user assignment has been removed.

Why this works: the on-behalf-of flow was built to let a middle tier call a back-end API, and chaining it with these parameters bypassed the user assignment setting. The request looked like a legitimate middle-tier exchange, so it was treated like one.

Evaluating the SAML token

The objective is to acquire a SAML token with a valid signature, issuer, audience and claims, as shown below. The malicious user receives a SAML token comparable to one emitted using a legitimate access pattern, despite the lack of user assignment for the application. Testing concluded that additional claims configured for the SAML application, such as groups, were included in the maliciously obtained SAML token.

From the original on secureworks.com

Why this matters: the token is comparable to one emitted using a legitimate access pattern, with a valid signature, issuer, audience and claims, despite the lack of user assignment. To the target application, the token looks exactly like one issued through the normal route.

What the attacker needed to know

Although the vulnerability was trivially exploitable, the malicious user needed a deep understanding of Azure AD applications and their configurations. The malicious user had to backdoor applications while they possessed a valid user assignment. The following knowledge is required to exploit this issue:

  • Understanding on-behalf-of flows in Azure AD.
  • Understanding the use of non-standard flows to request a SAML token with a JWT.
  • Understanding Azure AD application consents and application permissions.
  • Understanding the use of SAML tokens outside the normal use pattern. The PoC code abuses a CLI application with device code flow to gain a JWT, and later exchanges it for a SAML token using the on-behalf-of pattern. This technique differs from the typical use case of having a web browser receive the SAML token via interfacing directly the browser application.

A few of those terms in plain words:

  • A JWT (JSON Web Token) is a compact, signed token format. It is a string that carries claims and a signature, and it is widely used in OAuth 2.0.
  • A CLI application is a program you run from a command line rather than a browser window.
  • Device code flow is a sign-in pattern for devices that cannot easily show a browser, such as a TV or a command-line tool. The device shows you a short code, you type it into a browser on another device, and the device receives a token.
  • Consent is the act of granting an application permission to act toward another application or resource.

What Microsoft said

CTU researchers reported their initial findings about this vulnerability to Microsoft on August 4, 2022 and provided additional details on October 7. Microsoft confirmed the attack pattern on October 10 and categorized it as an "important" elevation of privilege issue. Microsoft addressed the issue in mitigations initially deployed on October 25 and provided the following response:

Microsoft has fixed an issue in the Azure Active Directory (Azure AD) OAuth2.0 protocol access token request when those requests are made by middle-tier applications who in turn use Security Assertion Markup Language (SAML) based authorization to access back-end APIs. Under certain circumstances, this issue would allow users within a tenant inappropriate access to back-end application functionality.

Microsoft has fixed the issue. Only correctly configured users will have access to the functionality of the back-end application.

In plain words: the bug was in the token request path used by middle-tier applications that then use SAML to reach back-end APIs. Microsoft fixed it, and only users who are correctly configured should now have access.

What the impact was

A previously assigned user within the tenant boundary could retain access to an application via a backdoor application after the user assignment was removed, establishing persistence and potentially elevating privileges on targeted SAML applications. This was only possible if the user had valid access when the backdoor application was configured.

Two ideas in that paragraph deserve a plain explanation:

  • Persistence means keeping access over time, even after the normal route is closed. The backdoor is the persistence mechanism.
  • Elevation of privilege means gaining more access than you are supposed to have. Here, the attacker could reach an application they were no longer assigned to, and in the most lucrative case could provision a new user for themselves in the target service.

The most lucrative target is a SAML application that relies solely on Azure AD's user assignment setting. If the application itself does not enforce assignment, the absence of enforcement in the application could be exploited to provision a new user for the attacker in the target service. In other words, if the application relies solely on Azure AD's user assignment setting, the absence of enforcement could be exploited to provision a new user in the target service.

What limited the exposure

The following mitigating factors applied to this vulnerability:

  • Applications that support IdP-initiated SSO were affected. Applications that only support SP-initiated SSO were not affected because SP-initiated SSO requires the inResponseTo attribute in the SAML response.
  • Applications that perform additional checks for user permissions or roles when receiving the token could prevent access even if the malicious user was able to bypass the user assignment on Azure AD.

Plain words for the first point:

  • IdP-initiated SSO means the identity provider (Azure AD) starts the sign-in and pushes the token to the application. The application did not ask first; it just receives the token.
  • SP-initiated SSO means the application (the service provider) starts the sign-in by asking Azure AD for a token. In that case the application includes a value called inResponseTo, and the SAML response must echo it back. SP-initiated SSO requires the inResponseTo attribute in the SAML response, which is why SP-initiated-only applications were not affected.

The second point is about defence in depth: if the application itself checks the user's permissions or roles when it receives a token, the attacker's token is not enough. The application says no even though Azure AD said yes.

The fix and the recommendation

Microsoft addressed the issue in mitigations initially deployed on 25 October, and stated that only correctly configured users will have access to the functionality of the back-end application.

To reduce risk from similar threats, CTU researchers recommend that organizations prevent users from registering their own applications in the Azure AD tenant. The reasoning is simple: the whole attack depends on the attacker being able to create an application and consent it to a target. If ordinary users cannot register applications, that first step is closed off.

What to take away

  • A rule that is enforced on the normal path may be missing on a side path. When you review access control, check every route that can produce a token, not just the obvious one.
  • Consent given while access is valid can outlive the access itself. When you remove a user, also review what that user's applications were consented to.
  • Applications that do their own permission checks are harder to abuse than applications that trust the identity provider completely.
  • Restricting who can register applications removes a whole class of attack setup.

Glossary

  • Access token: a short-lived credential an application presents to an API to prove it is allowed to call it.
  • API (Application Programming Interface): a defined way for one piece of software to request data or actions from another.
  • Application (in Azure AD): a service registered in Azure AD that users sign in to, such as an internal portal or a third-party tool.
  • Assertion: in SAML, the signed statement about a user; also the name of the parameter that carries a token into the on-behalf-of exchange.
  • Audience: the application a token is intended for. A token for one application should not be accepted by another.
  • Azure Active Directory (Azure AD): Microsoft's cloud identity service that handles sign-in and access for organisations.
  • Claim: a fact inside a token, such as a user's name or group membership.
  • CLI application: a program run from a command line rather than a browser.
  • Consent: the act of granting an application permission to act toward another application or resource.
  • Device code flow: a sign-in pattern for devices that cannot easily show a browser; the device shows a code, the user enters it in a browser elsewhere, and the device receives a token.
  • Elevation of privilege: gaining more access than you are supposed to have.
  • IdP-initiated SSO: single sign-on where the identity provider starts the sign-in and pushes the token to the application.
  • inResponseTo: a SAML attribute that ties a response to a specific request; required by SP-initiated SSO.
  • Issuer: the system that created a token, here Azure AD.
  • JWT (JSON Web Token): a compact, signed token format widely used in OAuth 2.0.
  • OAuth 2.0: a standard for granting one application limited access to something on your behalf, without sharing your password.
  • On-behalf-of flow: an OAuth 2.0 pattern where a middle-tier application exchanges a user's token for a new token to call a back-end API on the user's behalf.
  • Persistence: keeping access over time, even after the normal route is closed.
  • Proof of concept (PoC): a small demonstration that shows a vulnerability is real.
  • SAML (Security Assertion Markup Language): a standard for one system to tell another that a user is authenticated and to pass facts about them.
  • SAML token / SAML assertion: the signed document that carries those facts.
  • Signature: cryptographic proof that a token was created by the claimed issuer and has not been altered.
  • Single sign-on (SSO): signing in once and having that sign-in accepted by many services.
  • SP-initiated SSO: single sign-on where the application starts the sign-in by asking the identity provider for a token.
  • Tenant: an organisation's own isolated instance of Azure AD, containing its users and applications.
  • Token: a small piece of data that proves something, such as that a user is authenticated or allowed in.
  • User assignment: an Azure AD setting requiring users to be on a list before they can access an application.
  • URN: a standard identifier string, such as urn:ietf:params:oauth:token-type:saml2, that names a specific thing.

More by Secureworks

View all

2 more disclosed reports, best first.

More from Microsoft (Azure)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.