diff --git a/authlib/jose/rfc7518/oct_key.py b/authlib/jose/rfc7518/oct_key.py index 1db321a7..44e1f724 100644 --- a/authlib/jose/rfc7518/oct_key.py +++ b/authlib/jose/rfc7518/oct_key.py @@ -6,6 +6,16 @@ from ..rfc7517 import Key +POSSIBLE_UNSAFE_KEYS = ( + b"-----BEGIN ", + b"---- BEGIN ", + b"ssh-rsa ", + b"ssh-dss ", + b"ssh-ed25519 ", + b"ecdsa-sha2-", +) + + class OctKey(Key): """Key class of the ``oct`` key type.""" @@ -65,6 +75,11 @@ def import_key(cls, raw, options=None): key._dict_data = raw else: raw_key = to_bytes(raw) + + # security check + if raw_key.startswith(POSSIBLE_UNSAFE_KEYS): + raise ValueError("This key may not be safe to import") + key = cls(raw_key=raw_key, options=options) return key