Skip to content

Commit

Permalink
attempt logging in with fernet tokens as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsapenna committed Nov 24, 2021
1 parent 854a6a6 commit bb09e7b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion swift_browser_ui/ui/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import hashlib
import json
import re
import base64
import binascii

# aiohttp
import aiohttp.web
Expand Down Expand Up @@ -94,7 +96,16 @@ def test_token(
if unscoped is None:
raise aiohttp.web.HTTPBadRequest(reason="Token missing from query")
if not (re.match("[a-f0-9]{32}", unscoped) and len(unscoped) == 32):
raise aiohttp.web.HTTPBadRequest(reason="Token is malformed")
try:
# Check the magic byte matches a fernet token
if (
not base64.urlsafe_b64decode(unscoped.encode("utf-8"))[:1]
== b"\x80"
):
raise aiohttp.web.HTTPBadRequest(reason="Token is malformed")
# Handle failures in base64decode
except (binascii.Error, UnicodeDecodeError):
raise aiohttp.web.HTTPBadRequest(reason="Token is malformed")

log.info("Got OS token in login return")

Expand Down

0 comments on commit bb09e7b

Please sign in to comment.