Skip to content

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

@jacksimplified

Description

@jacksimplified

Summary

When security.jwt_enabled: true, the async job endpoints registered by deploy/docker/job.pyPOST /llm/job, GET /llm/job/{task_id}, POST /crawl/job, GET /crawl/job/{task_id} — return HTTP 500 for every request, with or without a Bearer token, making them unusable. The synchronous endpoints in server.py (/md, /crawl, /ask, /llm/{url}, …) are unaffected and correctly return 401.

Root cause

The job endpoints wire the auth dependency as:

_td: Dict = Depends(lambda: _token_dep())   # deploy/docker/job.py

Wrapping _token_dep in a lambda prevents FastAPI from resolving the credentials sub-dependency declared inside jwt_required (credentials: HTTPAuthorizationCredentials = Depends(security)). At request time verify_token receives a Depends object instead of the resolved credentials:

File "/app/job.py", line 59, in <lambda>
    _td: Dict = Depends(lambda: _token_dep()),
File "/app/auth.py", line 66, in jwt_required
    return verify_token(credentials)
File "/app/auth.py", line 34, in verify_token
    if not credentials or not credentials.credentials:
AttributeError: 'Depends' object has no attribute 'credentials'

By contrast, server.py injects the same dependency correctly as Depends(token_dep) (no lambda). With jwt_enabled: false the bug is masked, because _token_dep is lambda: None and the wrapped call returns None.

Reproduction (Docker)

config.yml with JWT enabled:

security:
  enabled: false
  jwt_enabled: true
  api_token: "TESTTOK"
docker run -d -p 11235:11235 -e SECRET_KEY=notsecret \
  -v $PWD/config.yml:/app/config.yml unclecode/crawl4ai:latest

# no token -> expect 401, actually 500
curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:11235/llm/job \
  -H 'Content-Type: application/json' -d '{"url":"https://example.com","q":"hi"}'
# -> 500

# mint a token, then retry with Authorization: Bearer <jwt> -> still 500

Affected versions

Reproduced on unclecode/crawl4ai:latest (0.8.6). The same Depends(lambda: _token_dep()) pattern is present on all four job routes in main.

Fix

PR incoming — replaces the broken lambda with a module-level dependency that mirrors auth.get_token_dependency (declares credentials properly, enforces a token when jwt_enabled is true, no-op when false).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions