Skip to content

fix(api): do not synthesize default grants in TokenVerifier when missing - #877

Open
NabiBukhsh-AI wants to merge 1 commit into
livekit:mainfrom
NabiBukhsh-AI:fix/api-token-verifier-missing-grants
Open

NabiBukhsh-AI wants to merge 1 commit into
livekit:mainfrom
NabiBukhsh-AI:fix/api-token-verifier-missing-grants

Conversation

@NabiBukhsh-AI

Copy link
Copy Markdown
Contributor

Summary

When verifying an access token that does not contain grant claims (e.g., video, sip, inference, or observability), TokenVerifier.verify() previously unpacked empty dictionaries into the grant classes:

video_dict = claims.get("video", dict())
video_dict = {camel_to_snake(k): v for k, v in video_dict.items()}
video = VideoGrants(**video_dict)

Because VideoGrants defines defaults of can_publish=True, can_subscribe=True, and can_publish_data=True, any token minted without video grants (such as an agent, webhook, SIP, or backend token) was incorrectly decoded by TokenVerifier as having active video permissions, rather than None.

Changes

  • Use _parse_grants(claims, key, cls) for video, sip, inference, and observability grants so they evaluate to None if the corresponding claim key was omitted or None in the token.
  • Matches the existing behavior of agent, agent_endpoint, and agent_thread grants.
  • Added unit tests in tests/api/test_access_token.py to verify that omitted grants evaluate to None and explicitly provided grants are parsed correctly.

When verifying a token that does not contain grant claims (such as video, sip, inference, or observability), TokenVerifier previously defaulted to instantiating empty grant objects. In particular, VideoGrants(**{}) synthesizes default room permissions (can_publish=True, can_subscribe=True, can_publish_data=True), incorrectly treating tokens minted without video grants as having full room publish/subscribe permissions.

Use _parse_grants consistently across video, sip, inference, and observability grants so that missing grants in claims remain None, matching agent, agent_endpoint, and agent_thread behavior.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant