1

I'm looking at using Azure AD to handle user accounts for my Web App.

I've implemented something similar to Microsoft's sample code shown here (Linked from here).

It uses the following authentication scenario (this):

Azure AD Authentication Scenario for Web Browser to Web Application

As far as I understand it, once the the user is authenticated, OWIN creates and sets its own session cookie for the specific domain. As long as this cookie hasn't expired or become corrupted, the user will stay logged in. Our app only ever talks to the authentication provider when a user logs out or logs in again.

So this raises the question: What happens when a user is deactivated, or deleted, from the AD while they are still logged in?

Let's say I have some sensitive information stored in my web app's database that is only modifiable by authorized users. The permissions for authorization are kept in a local database which is keyed to the user's OID.

Bob is an administrator for our company's Web App. For reasons undisclosed, we have had to terminate his employment. Our domain administrator locks his AD account out and Bob is escorted out of the premises. Everything should be fine.

Everything is not fine.

Disgruntled Bob arrives home and looks at his laptop, his browser is open on our web app. He thinks, "Surely it must have been locked out?". He browses to the Administration part of the site and sees he is still able to access it. In a petty way to get his own back at the company, he goes in and modifies some of the sensitive information.

Bob is still authenticated (Bob's credentials still identify Bob), but he should no longer be authorized to access the service. However, the session cookie is still valid. Bob is still logged in and can still has access the web app until this cookie expires, or until he ends the session.

How can I stop this from happening? (Besides not sleeping with Bob's wife.)

A few "solutions" I have thought of:

  1. Call to Azure's graph API for every [Authorize] action, which returns whether the user is valid and is not locked out. Then make the user end their own session.

  2. Call to a user metadata table on the application for every [Authorize] action which checks if the user is disabled or not. (Not ideal: Disparity between AD and local DB)

  3. Use BearerAuthentication some how. (Help with this would be greatly appreciated, the only examples I can find are for web-api)

  4. Do nothing and deal with this unlikely situation (Not ideal)

Community
  • 1
  • 1
Mardoxx
  • 4,372
  • 7
  • 41
  • 67

2 Answers2

1

As long as this cookie hasn't expired or become corrupted, the user will stay logged in.

Not true.

Both OAuth2 and WS-Fed tokens contain the token expiration date among other attributes.

Thus, in reality, Bob will be able to use the application until the expiration date in the token passes. Usually token providers issue tokens that are valid for few hours at most.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • Ah yes, quite right! The problem still exists however. – Mardoxx Sep 09 '16 at 11:41
  • Yes, there is a short timespan where a user could possibly be already inactive at the provider's side but active in your app. If you really need immediate termination, the 2. from your list sounds like a possible approach. – Wiktor Zychla Sep 09 '16 at 11:45
  • What I don't like about 2. is then we have to disable the AD account, then go in to our web app and disable the account there as well. – Mardoxx Sep 09 '16 at 11:56
  • It sounds like this is your own policy/requirement to be able to disable accounts and terminate sessions together. Taking this as a requirement, you don't have much choice. – Wiktor Zychla Sep 09 '16 at 12:06
1

You can make the token info in the cookie expire quickly, say every half an hour. Behind the scenes, you can use the refresh token to get new credentials, so users aren't inconvenienced. You could do this in a httpfilter. If a user has been removed from AD, the refresh operation will fail. This lessens your window of vulnerability. I suppose you could even shut that window down to a few minutes.

You might also force token refreshing before sensitive operations.

Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
  • Interesting, this certainly cuts down on the number of external requests. I shall have to look in to this, thank you. Do you have any pointers on what I should look up? – Mardoxx Sep 09 '16 at 11:56