Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Missing Authorization Checks#107

Open
daggerstuff wants to merge 1 commit intostagingfrom
security/missing-authorization-check-dataset-api-id773-3826732354342097834
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Missing Authorization Checks#107
daggerstuff wants to merge 1 commit intostagingfrom
security/missing-authorization-check-dataset-api-id773-3826732354342097834

Conversation

@daggerstuff
Copy link
Copy Markdown
Owner

@daggerstuff daggerstuff commented Mar 31, 2026

🚨 Severity: CRITICAL\nπŸ’‘ Vulnerability: Missing authorization checks on dataset API endpoints allowed any authenticated user to read datasets regardless of their permissions.\nπŸ”§ Fix: Added PermissionLevel.READ checks to list_datasets, get_dataset_metadata, and query_dataset.\nβœ… Verification: Review tests and confirm 403 Forbidden is returned for users without READ scopes.


PR created automatically by Jules for task 3826732354342097834 started by @daggerstuff

Summary by Sourcery

Enforce read-scope authorization on dataset API endpoints to prevent unauthorized data access.

Bug Fixes:

  • Require READ permission scope for listing datasets, fetching dataset metadata, and querying datasets, returning 403 for insufficient permissions.

Documentation:

  • Document the need to explicitly enforce API permission scopes in Sentinel security notes.

Summary by cubic

Added missing authorization checks to dataset API endpoints to require PermissionLevel.READ, blocking access for users without the correct scope. Unauthorized requests now return 403 with clear error messages.

  • Bug Fixes
    • Enforced PermissionLevel.READ in list_datasets, get_dataset_metadata, and query_dataset.
    • Added guidance to .Jules/sentinel.md to always verify scopes when using get_current_active_user_or_api_key.

Written for commit fd63503. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Added missing authorization checks to dataset endpoints to enforce proper access control and prevent unauthorized data access
  • Documentation

    • Documented authorization control requirements for API endpoints

Co-authored-by: daggerstuff <261005129+daggerstuff@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 31, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds missing READ-scope authorization checks to critical dataset API endpoints and documents the security learning in the Sentinel log.

Sequence diagram for READ scope authorization on dataset endpoints

sequenceDiagram
    actor User
    participant API as DatasetAPI
    participant Auth as AuthDependency
    participant DB as Database

    User->>API: HTTP GET /datasets
    API->>Auth: get_current_active_user_or_api_key()
    Auth-->>API: current_auth_entity(scopes)
    API->>API: check PermissionLevel.READ in scopes
    alt has READ scope
        API->>DB: list tables
        DB-->>API: datasets
        API-->>User: 200 OK with datasets
    else missing READ scope
        API-->>User: 403 Forbidden (insufficient permissions)
    end
Loading

Flow diagram for READ permission checks on dataset endpoints

flowchart TD
    A[Incoming request to dataset endpoint
list_datasets / get_dataset_metadata / query_dataset] --> B[Resolve current_auth_entity via get_current_active_user_or_api_key]
    B --> C{Does current_auth_entity.scopes
contain PermissionLevel.READ?}
    C -->|Yes| D[Execute endpoint logic
Connect to database and perform operation]
    D --> E[Return 200 OK with result]
    C -->|No| F[Raise HTTPException 403
Insufficient permissions]
    F --> G[Return 403 Forbidden to client]
Loading

File-Level Changes

Change Details Files
Enforce READ permission checks on dataset listing, metadata retrieval, and querying endpoints before executing any database logic.
  • Added a PermissionLevel.READ scope check at the start of list_datasets and return 403 Forbidden when absent.
  • Added a PermissionLevel.READ scope check at the start of get_dataset_metadata and return 403 Forbidden when absent.
  • Added a PermissionLevel.READ scope check at the start of query_dataset and return 403 Forbidden when absent.
api/dataset_api.py
Document the new authorization requirement and associated vulnerability in the Sentinel security log.
  • Appended a Sentinel entry describing the missing authorization vulnerability and the requirement to verify PermissionLevel scopes on endpoints using get_current_active_user_or_api_key.
.Jules/sentinel.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai Error Error Mar 31, 2026 1:43pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

πŸ“ Walkthrough

Walkthrough

Authorization control checks are introduced through a sentinel documentation entry and implemented in three dataset API endpoints. The endpoints (list_datasets, get_dataset_metadata, query_dataset) now explicitly verify PermissionLevel.READ scope presence before executing database access logic, raising HTTPException with status 403 if scope is insufficient.

Changes

Cohort / File(s) Summary
Authorization Documentation
.Jules/sentinel.md
Sentinel entry documenting authorization control requirement: endpoints using get_current_active_user_or_api_key must verify applicable PermissionLevel against authenticated entity's scopes before executing endpoint logic.
Dataset API Authorization Checks
api/dataset_api.py
Added scope verification checks to three endpoints (list_datasets, get_dataset_metadata, query_dataset). Each validates PermissionLevel.READ presence in current_auth_entity["scopes"] before database access; raises HTTPException(403) with endpoint-specific permission denied messages if check fails.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Endpoint as FastAPI Endpoint
    participant Auth as Scope Verifier
    participant DB as Database
    participant Response

    Client->>Endpoint: Request (GET /datasets)
    Endpoint->>Auth: Check PermissionLevel.READ<br/>in current_auth_entity["scopes"]
    
    alt Scope Present
        Auth->>DB: Scope verified, execute query
        DB->>Auth: Return data
        Auth->>Response: 200 OK with data
    else Scope Missing
        Auth->>Response: 403 Forbidden<br/>"Insufficient permissions"
    end
    
    Response->>Client: HTTP Response
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly Related PRs

Poem

🐰 A scope check hops in with care,
Guarding datasets left and right,
"Read first, or no access there!"
The sentinel keeps permission tight. ✨

πŸš₯ Pre-merge checks | βœ… 3
βœ… Passed checks (3 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly identifies the main change (fixing missing authorization checks) and aligns with the core objective of adding authorization checks to dataset endpoints.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/missing-authorization-check-dataset-api-id773-3826732354342097834

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The authorization checks assume current_auth_entity always has a "scopes" key and that it’s iterable; consider using a safer access pattern (e.g., .get("scopes", [])) or a typed object to avoid runtime errors when the auth shape changes.
  • The PermissionLevel.READ checks are duplicated across three endpoints; consider extracting a small helper (e.g., enforce_scope(current_auth_entity, PermissionLevel.READ, action_description)) or a dependency to centralize scope enforcement and keep the handlers focused on their core logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The authorization checks assume `current_auth_entity` always has a `"scopes"` key and that it’s iterable; consider using a safer access pattern (e.g., `.get("scopes", [])`) or a typed object to avoid runtime errors when the auth shape changes.
- The `PermissionLevel.READ` checks are duplicated across three endpoints; consider extracting a small helper (e.g., `enforce_scope(current_auth_entity, PermissionLevel.READ, action_description)`) or a dependency to centralize scope enforcement and keep the handlers focused on their core logic.

Fix all in Cursor


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

πŸ€– Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/dataset_api.py`:
- Around line 139-140: The permission checks directly index
current_auth_entity["scopes"] which can be missing for token-auth users; change
each check in list-datasets, get_dataset_metadata, and query_dataset to first
read scopes = current_auth_entity.get("scopes") or [] and then test
PermissionLevel.READ in scopes (and similarly for other PermissionLevel checks)
so missing scopes default to an empty list and return a proper 403 instead of
causing a 500.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f8e0f54-9d6a-4b28-af79-3921d3b6cc69

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 5e91c81 and fd63503.

πŸ“’ Files selected for processing (2)
  • .Jules/sentinel.md
  • api/dataset_api.py

Comment on lines +139 to +140
if PermissionLevel.READ not in current_auth_entity["scopes"]:
raise HTTPException(status_code=403, detail="Insufficient permissions to list datasets")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

READ checks depend on a broken user-scope source and can fail for JWT users

These checks assume current_auth_entity["scopes"] is always valid, but Line 105 builds scopes from user.permissions. Based on the auth model (security/api_authentication.py:106-121), permissions are role-derived, so this can throw for token-auth users and produce 500s instead of clean auth decisions.

πŸ”§ Proposed fix
 async def get_current_active_user_or_api_key(
     request: Request, api_key: Optional[str] = Depends(api_key_header)
 ):
@@
     user = getattr(request.state, "authenticated_user", None)
     if user:
+        scopes = auth_system.role_permissions.get(user.role, [])
         return {
             "username": user.username,
-            "scopes": user.permissions,
+            "scopes": scopes,
             "auth_type": "user_token",
         }
-    if PermissionLevel.READ not in current_auth_entity["scopes"]:
+    scopes = current_auth_entity.get("scopes") or []
+    if PermissionLevel.READ not in scopes:
         raise HTTPException(status_code=403, detail="Insufficient permissions to list datasets")

Apply the same scopes = ...get("scopes") or [] guard to the checks in get_dataset_metadata and query_dataset.

Also applies to: 202-204, 267-269

πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/dataset_api.py` around lines 139 - 140, The permission checks directly
index current_auth_entity["scopes"] which can be missing for token-auth users;
change each check in list-datasets, get_dataset_metadata, and query_dataset to
first read scopes = current_auth_entity.get("scopes") or [] and then test
PermissionLevel.READ in scopes (and similarly for other PermissionLevel checks)
so missing scopes default to an empty list and return a proper 403 instead of
causing a 500.

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