#2810·DocsGPT

Bug Report: handle_auth accepts malformed Authorization headers; mutable default arg

Author: yxiaoGitCreated Sep 19, 2026Updated Sep 19, 2026

Description

docsgpt/auth.py:

function: def handle_auth(request, data={})

(1) data={} mutable default; (2) jwt_token.replace("Bearer ", "") strips the substring anywhere (corrupts tokens containing the word "Bearer"), accepts wrong schemes (Token xyz), bare "Bearer", and crashes on non-string header values. Suggest strict Bearer parse returning invalid_token, data=None default.

Reproduction steps

  1. In terminal 1, At /Path/DocsGPT, add the following settings in .env: (if not set the simple_jwt auth type, all will pass as local) AUTH_TYPE=simple_jwt JWT_SECRET_KEY=Bearer123

  2. start the backend server( each time need to restart after the .env JWT_SECRET_KEY change): source .venv/bin/activate uvicorn docsgpt.asgi:asgi_app --host 0.0.0.0 --port 7091 --reload

  3. in terminal 2, mint the token to pass into the authorization header: source .venv/bin/activate
    python -c "from jose import jwt; print(jwt.encode({'sub': 'testuser'}, 'Bearer123', algorithm='HS256'))"

  4. test with: curl -i http://127.0.0.1:7091/api/user/me -H "Authorization: Bearer " it will respond 401 , invalid token.

Expected behavior

when user set the token as 'Beareer123', etc, which contains the 'Bearer', the authorization should still pass with "HTTP/1.1 200 OK".

Actual Behavior with Screenshots

It actually responds with 404

Image

Operating system

MacOS

What browsers are you seeing the problem on?

No response

What development environment are you experiencing this bug on?

Docker

Did you set the correct environment variables in the right path? List the environment variable names (not values please!)

in .env,
AUTH_TYPE=simple_jwt JWT_SECRET_KEY=Bearer123

Provide any additional context for the Bug.

handle_auth runs on every request through two chokepoints: authenticate_request (docsgpt/app.py:315, Flask
before_request) and authenticate() (docsgpt/api/asgi_auth.py:35, Starlette routes). Production serves docsgpt.asgi:asgi_app via gunicorn, which wires in those same handlers — so with AUTH_TYPE=simple_jwt/session_jwt/oidc, this code authenticates production traffic.

the default local setup runs auth-disabled ({"sub": "local"} path, header never read), and the test suite patches handle_auth in dozens of places rather than exercising it — so few eyes ever hit the parsing lines. The fix matters most for self-hosted production with JWT auth on;
for local dev with auth off, it's latent.

Relevant log output

bash

Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes, I am willing to submit a PR!

‍⚖️ Code of Conduct

  • I agree to follow this project's Code of Conduct