Skip to content

fix(api): enforce WIKI_AUTH_MODE everywhere and cap task admission - #595

Open
carfeii wants to merge 1 commit into
AsyncFuncAI:mainfrom
carfeii:fix/wiki-auth-and-admission-limits
Open

carfeii wants to merge 1 commit into
AsyncFuncAI:mainfrom
carfeii:fix/wiki-auth-and-admission-limits

Conversation

@carfeii

@carfeii carfeii commented Oct 5, 2026

Copy link
Copy Markdown

Two related fixes:

  • WIKI_AUTH_MODE previously only protected DELETE /api/wiki_cache; every other sensitive/costly route (wiki generation, repo indexing, chat, codemap, cache reads) performed no authorization check at all, so an operator who enabled the one documented protection mechanism got no actual protection anywhere but that single endpoint. Adds a shared check_wiki_auth_code() dependency (api/routers/auth.py) and an authorization_code field on RepoRequestBase, applied to every route that generates, indexes, chats, or reads cached wiki content.
  • Wiki task submission (POST /wiki/tasks) and repo indexing (POST /repo/prepare) each admitted a new asyncio task into their respective tracking state unconditionally, before any concurrency limit applied. A caller varying repo_url could queue an unbounded number of pending clone/embedding jobs. Adds an admission cap on distinct non-terminal tasks (TaskRegistry.max_pending, default 10x the execution semaphore) and a parallel cap on /repo/prepare's own in-flight job set, both returning 429 once full.

Test plan

  • pytest tests/backend/routers/test_wiki_auth_enforcement.py tests/backend/services/test_wiki_task.py: new regression tests pass.
  • pytest tests/: full suite passes with no regressions.
  • Confirmed each new auth test fails (401 expected, 200 returned) against the pre-fix code, and the admission tests fail to even import (TaskQueueFullError didn't exist).

Two related fixes:

- WIKI_AUTH_MODE previously only protected DELETE /api/wiki_cache; every
  other sensitive/costly route (wiki generation, repo indexing, chat,
  codemap, cache reads) performed no authorization check at all, so an
  operator who enabled the one documented protection mechanism got no
  actual protection anywhere but that single endpoint. Adds a shared
  check_wiki_auth_code() dependency (api/routers/auth.py) and an
  authorization_code field on RepoRequestBase, applied to every route
  that generates, indexes, chats, or reads cached wiki content.

- Wiki task submission (POST /wiki/tasks) and repo indexing (POST
  /repo/prepare) each admitted a new asyncio task into their
  respective tracking state unconditionally, before any concurrency
  limit applied. A caller varying repo_url could queue an unbounded
  number of pending clone/embedding jobs. Adds an admission cap on
  distinct non-terminal tasks (TaskRegistry.max_pending, default
  10x the execution semaphore) and a parallel cap on /repo/prepare's
  own in-flight job set, both returning 429 once full.

Adds regression tests in tests/backend/routers/test_wiki_auth_enforcement.py
(new) and tests/backend/services/test_wiki_task.py, including fail-before
coverage run against the unpatched code.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

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