Skip to content

fix(security): enforce API key auth on saved views router [#2035]#2037

Merged
utksh1 merged 2 commits into
utksh1:mainfrom
namann5:fix/auth-bypass-saved-views
Jul 20, 2026
Merged

fix(security): enforce API key auth on saved views router [#2035]#2037
utksh1 merged 2 commits into
utksh1:mainfrom
namann5:fix/auth-bypass-saved-views

Conversation

@namann5

@namann5 namann5 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Enforce API key authentication on the saved views router, closing an authentication bypass vulnerability.

Closes #2035

Problem

The saved_views_router in backend/secuscan/saved_views.py was registered in main.py without the require_api_key dependency. This allowed unauthenticated access to all CRUD endpoints:

  • GET /api/v1/saved-views — enumerate all saved views
  • POST /api/v1/saved-views — create views
  • PUT /api/v1/saved-views/{view_id} — modify views
  • DELETE /api/v1/saved-views/{view_id} — delete views

Compare with the protected main router in routes.py:133:

router = APIRouter(prefix="/api/v1", dependencies=[Depends(require_api_key)])

Fix

Added dependencies=[Depends(require_api_key)] to the saved_views_router definition, matching the pattern used by the main API router:

saved_views_router = APIRouter(
    prefix="/api/v1/saved-views",
    tags=["saved-views"],
    dependencies=[Depends(require_api_key)],
)

Impact

  • Before: Any HTTP client without an API key could read, create, modify, and delete saved views
  • After: All saved views endpoints require a valid API key via Authorization: Bearer <key>, X-Api-Key: <key>, or a valid session cookie

Testing

  1. Start the application
  2. curl http://localhost:8000/api/v1/saved-views → returns 401
  3. curl -H "X-Api-Key: <valid-key>" http://localhost:8000/api/v1/saved-views → returns 200

Labels

type:security, level:critical, priority:high, area:backend

The saved_views_router was registered in main.py without the
require_api_key dependency, allowing unauthenticated access to all
CRUD endpoints for saved views. This is an authentication bypass
that exposes filter configurations and enables data tampering.

Add Depends(require_api_key) to the router definition, matching
the pattern used by the main API router in routes.py.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b91001d029

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

saved_views_router = APIRouter(
prefix="/api/v1/saved-views",
tags=["saved-views"],
dependencies=[Depends(require_api_key)],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Route saved-view calls through the authenticated client

After this dependency is added, the existing saved-views frontend client still uses a private fetch helper that only passes signal (frontend/src/hooks/useSavedViews.ts:129-132) instead of the shared authenticated request path that adds credentials: 'include' and X-Api-Key (frontend/src/api.ts:404-415). In deployments where API_BASE is absolute, including the local preview/static path in frontend/src/api.ts:5-9, those saved-view requests no longer send the session cookie or API key, so every backend sync is treated as unavailable and the feature silently falls back to localStorage even after login.

Useful? React with 👍 / 👎.

Export getApiKey from api.ts and update useSavedViews apiFetch to include
X-Api-Key header and credentials:'include', matching the authenticated
request pattern used by the rest of the API client.

Without this, saved-view requests silently fail with 401 in deployments
where API_BASE is absolute, causing the feature to fall back to
localStorage even after login.
@utksh1

utksh1 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Rebased with main to pick up test fixes from #2040 and #2041.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Critical security fix addressing authentication bypass vulnerability (#2035).

The saved views router was missing require_api_key dependency, allowing unauthenticated access to:

  • GET /api/v1/saved-views (enumerate all views)
  • POST /api/v1/saved-views (create views)
  • PUT /api/v1/saved-views/{view_id} (modify views)
  • DELETE /api/v1/saved-views/{view_id} (delete views)

Fix adds dependencies=[Depends(require_api_key)] to the router definition, matching the pattern used by other protected routes.

Rebased with main. Approving for merge.

@utksh1
utksh1 merged commit a4d5f1e into utksh1:main Jul 20, 2026
20 of 21 checks passed
@utksh1 utksh1 added type:security Security work category bonus label area:backend Backend API, database, or service work level:critical 80 pts difficulty label for critical or high-impact PRs gssoc:approved Admin validation: approved for GSSoC scoring labels Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work gssoc:approved Admin validation: approved for GSSoC scoring level:critical 80 pts difficulty label for critical or high-impact PRs type:security Security work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CRITICAL] Authentication Bypass: Saved Views Router Missing API Key Enforcement

2 participants