Skip to content

Commit

Permalink
Merge pull request #493 from mozilla-iam/IAM-1269
Browse files Browse the repository at this point in the history
IAM-1269 sso-dashboard invalid JWT tokens return 500 error
  • Loading branch information
frosemond authored Apr 16, 2024
2 parents 5e87055 + 64dd5ad commit 5a5e654
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 0 additions & 1 deletion dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def forbidden():
jws = request.args.get("error").encode()

token_verifier = oidc_auth.tokenVerification(jws=jws, public_key=app.config["FORBIDDEN_PAGE_PUBLIC_KEY"])
"""TODO: add code here to catch when the token is invalid"""
token_verifier.verify

return render_template("forbidden.html", token_verifier=token_verifier)
Expand Down
13 changes: 13 additions & 0 deletions dashboard/oidc_auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import logging
import traceback
from josepy.jwk import JWK
from josepy.jws import JWS
from josepy.error import JWSErrors

"""Class that governs all authentication with open id connect."""
from flask_pyoidc import OIDCAuthentication
Expand Down Expand Up @@ -95,6 +97,17 @@ def _verified(self):
self.jws_data["connection_name"] = self._get_connection_name(self.jws_data["connection"])
return True
except UnicodeDecodeError:
logger.warning("UnicodeDecodeError: The jws {jws}".format(jws=self.jws))
return False
except JWSErrors.DeserializationError:
logger.warning("DeserializationError jws {jws}".format(jws=self.jws))
return False
except Exception: # pylint: disable=broad-exception-caught
# This is a broad except to catch every error. It's not great but since we're
# in _validate, our job is to pass/fail everything, and letting code raise out
# of here blows up the website in front of customers. Let's do something better
# as a last-choice, maybe we need more exceptions caught above
logger.warning("Unknown error occurred "+traceback.format_exc())
return False

def error_message(self):
Expand Down

0 comments on commit 5a5e654

Please sign in to comment.