Skip to content

Commit daf6033

Browse files
Sbussisoclaude
andcommitted
Fix MCP auth vulnerability, clean up imports and CSS
- Reject empty Bearer tokens before hashing (security fix) - Remove unused Context import, fix Session type hint - Move HTTPException to top-level import in mcp_keys - Add standalone .locked-icon CSS for MCP upgrade prompt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 736a095 commit daf6033

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

backend/app/api/mcp_keys.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import hashlib
77
import secrets
88

9-
from fastapi import APIRouter, Depends
9+
from fastapi import APIRouter, Depends, HTTPException
1010
from sqlalchemy.orm import Session
1111

1212
from app.core.auth import AuthUser, require_admin
@@ -79,7 +79,6 @@ async def revoke_mcp_key(
7979
.first()
8080
)
8181
if not mcp_key:
82-
from fastapi import HTTPException
8382
raise HTTPException(status_code=404, detail="Key not found")
8483

8584
mcp_key.revoked = True

backend/app/mcp/server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
from datetime import datetime, timedelta
1212
from typing import Annotated
1313

14-
from fastmcp import FastMCP, Context
14+
from fastmcp import FastMCP
1515
from fastmcp.server.dependencies import get_http_headers
1616
from fastmcp.exceptions import ToolError
1717
from pydantic import Field
18+
from sqlalchemy.orm import Session
1819

1920
from app.core.database import SessionLocal
2021
from app.models.models import (
@@ -47,7 +48,7 @@
4748
# Auth helper — resolve Bearer token to org_id
4849
# ---------------------------------------------------------------------------
4950

50-
def _resolve_org(headers: dict | None) -> tuple[str, SessionLocal]:
51+
def _resolve_org(headers: dict | None) -> tuple[str, Session]:
5152
"""Validate the Bearer token and return (org_id, db_session)."""
5253
if not headers:
5354
raise ToolError("Unauthorized: no headers present")
@@ -57,6 +58,9 @@ def _resolve_org(headers: dict | None) -> tuple[str, SessionLocal]:
5758
raise ToolError("Unauthorized: missing Bearer token")
5859

5960
raw_key = auth.split(" ", 1)[1].strip()
61+
if not raw_key:
62+
raise ToolError("Unauthorized: empty Bearer token")
63+
6064
key_hash = hashlib.sha256(raw_key.encode()).hexdigest()
6165

6266
db = SessionLocal()

frontend/src/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,8 @@ body {
20592059
margin: 0 auto;
20602060
}
20612061

2062-
.upgrade-icon {
2062+
.upgrade-icon,
2063+
.locked-icon {
20632064
font-size: 3rem;
20642065
margin-bottom: 1rem;
20652066
}

0 commit comments

Comments
 (0)