Skip to content

security: unauthenticated HTTP API endpoints expose database queries and index operations #1008

Closed

Description

@shreyasfegade

The FastAPI router in src/codegraphcontext/api/router.py exposes several management and query endpoints—including /index, /query (proxying to execute_cypher_query), and /tools/call—without any authentication middleware.

Anyone with network access to the API port can execute arbitrary Cypher queries (and bypass the regex blocklist), start arbitrary indexing jobs on the host, or call backend MCP tools, which presents a critical security risk.

Where it is:

  • File: src/codegraphcontext/api/router.py
  • Function/Section: All route definitions (e.g., /index, /query, /tools/call)

Why it matters:
An unauthenticated API allows arbitrary actors to execute Cypher queries against the database, trigger indexing jobs on the host, or call internal tools, leading to potential data exposure and unauthorized actions.

Steps to reproduce / observe:

  1. Start the FastAPI server (e.g. running the visualizer or API).
  2. Perform a POST request to http://localhost:<port>/api/v1/query with an empty or custom Cypher payload from a separate terminal without supplying any auth headers.
  3. Observe that the API processes the request successfully.

Suggested direction:
Introduce an API key or Token-based authentication layer. Read a secure token from configuration (config.yaml or .env), validate it in a FastAPI dependency (e.g., checking the Authorization header), and return 401 Unauthorized for invalid or missing keys. We can auto-generate a secure token on first run if none is set.

Activity

  1. github-actions commented on May 28, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. shreyasfegade commented on May 28, 2026

    @shreyasfegade
    Author

    I would like to work on this issue. I propose implementing a security dependency/middleware in FastAPI using HTTPBearer or a custom header checker. This dependency will read a secure API token/key from the configuration (config.yaml or .env), validate incoming requests on all router endpoints (excluding health checks if appropriate), and return a 401 Unauthorized response on validation failure. I'll also implement a startup hook that generates a secure default key if none exists. Please assign this issue to me.

  3. srinithithirumaran commented on May 29, 2026

    @srinithithirumaran

    Hi, I would like to work on this issue under GSSoC 2026. Could you please assign it to me?

  4. Shashankss1205 commented on Jun 1, 2026

    @Shashankss1205
    Collaborator

    Heyyy @shreyasfegade go ahead!
    @srinithithirumaran can you please create or work on other issue?

  5. moved this from Backlog tasks to In progress in CGC Progress Boardon Jul 26, 2026
  6. moved this from In progress to Done in CGC Progress Boardon Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions