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

Figure out a way to invalidate ONE user JWT/Session #277

Open
bbuechler opened this issue Oct 29, 2020 · 1 comment
Open

Figure out a way to invalidate ONE user JWT/Session #277

bbuechler opened this issue Oct 29, 2020 · 1 comment
Labels
enhancement New feature or request security fix Security fix generated by WhiteSource

Comments

@bbuechler
Copy link
Contributor

Right now we can change the JWT secret, but that would invalidate ALL sessions.

It would be nice if we could kill ONE specific user session.

I'm not sure how we could pull it off, but it'd be a useful feature.

@bbuechler bbuechler added enhancement New feature or request security fix Security fix generated by WhiteSource labels Oct 29, 2020
@bbuechler
Copy link
Contributor Author

Assume a blacklist, stored in a reject variable looks like this:

{
  "blacklist": {
    "badguy1231": 1619104148, 
    "user112412": 1617642228
  }
}

We should periodically re-download the list from the external endpoint to keep it fresh.

If our decoded_JWT is this:

{
  "first_name": "Brian",
  "last_name": "Badguy",
  "urs-user-id": "badguy1231",
  "urs-access-token": "longtokenvalue",
  "urs-groups": [  ],
  "iat": 1619103148,
  "exp": 1619707948
}

When we validate the a token signature, we should also validate that our user's token has not been invalidated...

def is_jwt_blacklisted(decoded_JWT, reject):
   
   # Is "badguy1231" in blacklist? 
   if decoded_JWT["urs-user-id"] in reject["blacklist"]:

      # Shortcuts
      urs_user_id = decoded_JWT["urs-user-id"]
      jwt_mint_time = decoded_JWT["iat"]}
      user_blackist_time = reject["blacklist"][urs_user_id]
      log.debug(f"JWT was minted @  {jwt_mint_time}, Blacklist is for cookies BEFORE {user_blackist_time}")

      # Is blackist date "1619104148" >= JWT mint date "1619103148"
      if user_blackist_time >= jwt_mint_time:
         log.info(f"User {urs_user_id}'s JWT was minted before blacklist date and is INVALID")
         return True

      else: 
         # User appears in the blacklist, but this token is newer
         log.info(f"User {urs_user_id's JWT was minted AFTER blacklist date and is still VALID")

   # User is not in the blacklist
   log.info((f"User {urs_user_id} is NOT in the blacklist")
   return False

⬆️ complete untested code, but thats the logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security fix Security fix generated by WhiteSource
Projects
None yet
Development

No branches or pull requests

1 participant