Skip to content

fix(docker): enforce JWT on job endpoints instead of 500 (resolve credentials correctly)#1997

Open
jacksimplified wants to merge 1 commit into
unclecode:mainfrom
jacksimplified:fix/job-jwt-500
Open

fix(docker): enforce JWT on job endpoints instead of 500 (resolve credentials correctly)#1997
jacksimplified wants to merge 1 commit into
unclecode:mainfrom
jacksimplified:fix/job-jwt-500

Conversation

@jacksimplified
Copy link
Copy Markdown

What & why

Fixes #1996.

The job router wires its auth dependency as Depends(lambda: _token_dep()). Wrapping the dependency in a lambda prevents FastAPI from resolving the Bearer credentials sub-dependency declared inside jwt_required, so verify_token receives a Depends object and raises AttributeErrorHTTP 500 whenever security.jwt_enabled is true. This affects all four job endpoints (/llm/job, /llm/job/{id}, /crawl/job, /crawl/job/{id}) for every request, with or without a token, making them unusable. With jwt_enabled: false the bug is masked because _token_dep is lambda: None.

Change

Replace the broken lambda with a module-level dependency _job_token_dep that mirrors auth.get_token_dependency:

  • declares credentials properly (via HTTPBearer(auto_error=False)) so FastAPI resolves the Bearer header,
  • enforces a valid token when jwt_enabled is true (401 otherwise),
  • is a no-op when jwt_enabled is false,
  • reads jwt_enabled from the injected _config, preserving the existing late-binding via init_job_router.

The four Depends(lambda: _token_dep()) are replaced with Depends(_job_token_dep).

Verified behavior (on the published image)

jwt_enabled: true:

Request Before After
POST /llm/job no token 500 401
POST /crawl/job no token 500 401
POST /llm/job invalid token 500 401
POST /llm/job valid token 500 202 (auth passes)
POST /md no token (control) 401 401

jwt_enabled: false:

Request Before After
POST /llm/job no token 202 202 (no regression)

The job router wired auth as Depends(lambda: _token_dep()), which prevents
FastAPI from resolving the Bearer credentials sub-dependency. With
security.jwt_enabled=true this raised AttributeError -> HTTP 500 on
/llm/job, /llm/job/{id}, /crawl/job, /crawl/job/{id} for every request
(with or without a token), making the async job endpoints unusable.

Replace the broken lambda with a module-level _job_token_dep that mirrors
auth.get_token_dependency: declare credentials properly so FastAPI resolves
the Bearer header, enforce a valid token when jwt_enabled is true, and
no-op when it is false (reading jwt_enabled from the injected _config).

Verified on the published image: job endpoints now return 401 without a
token, 401 on an invalid token, and proceed with a valid token; behavior
with jwt_enabled=false is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

[Bug]: Docker job endpoints (/llm/job, /crawl/job) return 500 instead of enforcing JWT when security.jwt_enabled is true

1 participant