Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(ownership): reject identity-less callers instead of sharing a sentinel scope

user758b4883269e
diff --git a/litellm/llms/litellm_proxy/skills/handler.py b/litellm/llms/litellm_proxy/skills/handler.py
index 086dccd4032..1129af64e14 100644
--- a/litellm/llms/litellm_proxy/skills/handler.py
+++ b/litellm/llms/litellm_proxy/skills/handler.py
@@ -133,6 +133,17 @@ class LiteLLMSkillsHandler:
skill_id = f"litellm_skill_{uuid.uuid4()}"
owner = get_primary_resource_owner_scope(user_api_key_dict) or user_id
+ if owner is None:
+ # Caller has no identity scope (no user_id / team_id / org_id /
+ # api_key / token). Stamping a placeholder would let any two
+ # identity-less callers see each other's skills via the shared
+ # owner — the cross-tenant primitive we avoid.
+ from fastapi import HTTPException
+
+ raise HTTPException(
+ status_code=403,
+ detail="Unable to record skill ownership: caller has no identity scope.",
+ )
skill_data: Dict[str, Any] = {
"skill_id": skill_id,
diff --git a/litellm/proxy/common_utils/resource_ownership.py b/litellm/proxy/common_utils/resource_ownership.py
index 9b55554fbc6..936c4e18bde 100644
--- a/litellm/proxy/common_utils/resource_ownership.py
+++ b/litellm/proxy/common_utils/resource_ownership.py
@@ -2,8 +2,6 @@ from typing import List, Optional
from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth
-UNSCOPED_RESOURCE_OWNER_SCOPE = "__litellm_unscoped_proxy__"
-
def is_proxy_admin(user_api_key_dict: Optional[UserAPIKeyAuth]) -> bool:
if user_api_key_dict is None:
@@ -22,8 +20,14 @@ def get_resource_owner_scopes(
Return ownership scopes that may access a user-created proxy resource.
Raw user_id is included for rows created before scope prefixes existed.
- Prefixes avoid collisions when falling back to team/org/key ownership for
- keys that do not have a user_id.
+ Prefixes avoid collisions when falling back to team/org/key ownership
+ for keys that do not have a user_id.
+
+ Identity-less callers (no user_id, team_id, org_id, api_key, or token)
+ return ``[]`` — they share no scope with any other caller, so access
+ checks against an existing owner always fail and creates that depend
+ on a primary scope must reject up front. Returning a shared sentinel
+ here would let any two identity-less callers see each other's data.
"""
if user_api_key_dict is None:
return []
@@ -45,8 +49,6 @@ def get_resource_owner_scopes(
_add(f"key:{user_api_key_dict.api_key}")
if user_api_key_dict.token:
_add(f"key:{user_api_key_dict.token}")
- if not scopes:
- _add(UNSCOPED_RESOURCE_OWNER_SCOPE)
return scopes
@@ -54,6 +56,13 @@ def get_resource_owner_scopes(
def get_primary_resource_owner_scope(
user_api_key_dict: Optional[UserAPIKeyAuth],
) -> Optional[str]:
+ """Return the canonical owner scope to stamp on newly-created rows.
+
+ ``None`` for identity-less callers — callers that depend on a primary
+ scope to record ownership must surface that as a hard error rather
+ than fall back to a shared sentinel (which would collapse every
+ identity-less caller into the same logical owner).
+ """
if user_api_key_dict is None:
return None
@@ -67,7 +76,7 @@ def get_primary_resource_owner_scope(
return f"key:{user_api_key_dict.api_key}"
if user_api_key_dict.token:
return f"key:{user_api_key_dict.token}"
- return UNSCOPED_RESOURCE_OWNER_SCOPE
+ return None
def user_can_access_resource_owner(
diff --git a/litellm/proxy/container_endpoints/ownership.py b/litellm/proxy/container_endpoints/ownership.py
index 6bfea87ebf6..b5b340fe2be 100644
--- a/litellm/proxy/container_endpoints/ownership.py
+++ b/litellm/proxy/container_endpoints/ownership.py
@@ -147,7 +147,15 @@ async def record_container_owner(
)
return response
if owner is None:
- raise HTTPException(status_code=500, detail="Unable to track container")
+ # Caller has no identity (no user_id / team_id / org_id / api_key /
+ # token) we can stamp on the row. Recording with a placeholder
+ # would collapse every such caller into a single shared owner —
+ # the cross-tenant data-access primitive we explicitly avoid.
+ # Reject with 403 rather than fall back to a sentinel.
+ raise HTTPException(
+ status_code=403,
+ detail="Unable to record container ownership: caller has no identity scope.",
+ )
original_container_id, resolved_provider = decode_container_id_for_ownership(
container_id,
diff --git a/tests/test_litellm/containers/test_container_proxy_ownership.py b/tests/test_litellm/containers/test_container_proxy_ownership.py
index 2e82b5b6b2d..850c5a96e53 100644
--- a/tests/test_litellm/containers/test_container_proxy_ownership.py
+++ b/tests/test_litellm/containers/test_container_proxy_ownership.py
@@ -138,7 +138,12 @@ async def test_should_record_token_owner_for_keys_without_user_team_or_org(monke
@pytest.mark.asyncio
-async def test_should_record_unscoped_owner_for_identityless_proxy_auth(monkeypatch):
+async def test_should_reject_record_for_identityless_proxy_auth(monkeypatch):
+ """Identity-less callers (no user_id / team_id / org_id / api_key /
+ token) cannot record ownership — stamping a shared sentinel would let
+ any two such callers see each other's containers."""
+ from fastapi import HTTPException
+
monkeypatch.setattr(
ownership,
"_get_prisma_client",
@@ -146,23 +151,15 @@ async def test_should_record_unscoped_owner_for_identityless_proxy_auth(monkeypa
)
auth = UserAPIKeyAuth()
- await ownership.record_container_owner(
- response=_container("cntr_provider"),
- user_api_key_dict=auth,
- custom_llm_provider="openai",
- )
-
- assert (
- ownership._IN_MEMORY_CONTAINER_OWNERS["container:openai:cntr_provider"]
- == "__litellm_unscoped_proxy__"
- )
- original_id, provider = await ownership.assert_user_can_access_container(
- container_id="cntr_provider",
- user_api_key_dict=auth,
- custom_llm_provider="openai",
- )
- assert original_id == "cntr_provider"
- assert provider == "openai"
+ with pytest.raises(HTTPException) as exc:
+ await ownership.record_container_owner(
+ response=_container("cntr_provider"),
+ user_api_key_dict=auth,
+ custom_llm_provider="openai",
+ )
+ assert exc.value.status_code == 403
+ assert "identity scope" in str(exc.value.detail)
+ assert ownership._IN_MEMORY_CONTAINER_OWNERS == {}
@pytest.mark.asyncio
diff --git a/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py b/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py
index cef5f8a554b..8b189be4921 100644
--- a/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py
+++ b/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py
@@ -150,9 +150,11 @@ def test_should_build_resource_owner_scopes_for_auth_context():
assert resource_ownership.get_resource_owner_scopes(
UserAPIKeyAuth(token="token-hash")
) == ["key:token-hash"]
- assert resource_ownership.get_resource_owner_scopes(UserAPIKeyAuth()) == [
- resource_ownership.UNSCOPED_RESOURCE_OWNER_SCOPE
- ]
+ # Identity-less callers get an empty scope set — sharing a sentinel
+ # would collapse every identity-less caller into the same logical
+ # owner, which is a cross-tenant data-access primitive.
+ assert resource_ownership.get_resource_owner_scopes(UserAPIKeyAuth()) == []
+ assert resource_ownership.get_primary_resource_owner_scope(UserAPIKeyAuth()) is None
def test_should_allow_admin_and_anonymous_resource_owner_paths():
@@ -259,9 +261,13 @@ async def test_should_store_token_owner_for_keys_without_user_team_or_org(monkey
@pytest.mark.asyncio
-async def test_should_store_unscoped_owner_for_identityless_proxy_auth(monkeypatch):
+async def test_should_reject_skill_create_for_identityless_proxy_auth(monkeypatch):
+ """Identity-less callers cannot create skills — stamping a shared
+ sentinel as ``created_by`` would let any two such callers see each
+ other's skills via the resulting shared owner scope."""
+ from fastapi import HTTPException
+
table = AsyncMock()
- table.create.side_effect = lambda data: _skill(data["skill_id"], data["created_by"])
prisma_client = type(
"Prisma", (), {"db": type("DB", (), {"litellm_skillstable": table})()}
)()
@@ -273,16 +279,14 @@ async def test_should_store_unscoped_owner_for_identityless_proxy_auth(monkeypat
auth = UserAPIKeyAuth()
- skill = await LiteLLMSkillsHandler.create_skill(
- data=NewSkillRequest(display_title="skill"),
- user_api_key_dict=auth,
- )
-
- assert skill.created_by == "__litellm_unscoped_proxy__"
- assert (
- table.create.await_args.kwargs["data"]["updated_by"]
- == "__litellm_unscoped_proxy__"
- )
+ with pytest.raises(HTTPException) as exc:
+ await LiteLLMSkillsHandler.create_skill(
+ data=NewSkillRequest(display_title="skill"),
+ user_api_key_dict=auth,
+ )
+ assert exc.value.status_code == 403
+ assert "identity scope" in str(exc.value.detail)
+ table.create.assert_not_awaited()
@pytest.mark.asyncio