Repository navigation
Hotfix: every request authenticates as its own user - #265
Merged
Merged
Conversation
configure_app pushed an app context that was never popped. Flask reuses an active app context for a request instead of pushing its own, so flask.g outlived each request within a uWSGI worker, and middle_auth_client's auth_required skips authentication when flask.g.auth_token is already set. A request to any endpoint without @reset_auth ran as whoever that worker last authenticated, with no token at all included: wrongly refused (a 403 for a user who has the permission) or wrongly allowed (another user's, or an admin's, permissions). - configure_app no longer pushes an app context. It was added in 2019 so celery tasks could read current_app; tasks now run in their own context (ContextTask), as do the Ray entrypoints and workers. - create_app registers a before_request hook that clears flask.g.auth_token and flask.g.auth_user, so no endpoint depends on carrying a decorator. - The per-endpoint @reset_auth decorators are removed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
fcollman
added a commit
that referenced
this pull request
Oct 29, 2026
#265 stopped configure_app pushing an app context for the process, relying on ContextTask for every task. Four tasks never had it, and since then fail on their first current_app access: run_periodic_materialization (no minnie frozen version on Oct 28 or 29), run_periodic_database_update, remove_expired_databases and update_database_workflow. - create_celery sets ContextTask before anything reads celery.conf. The first read fires on_after_configure, and setup_periodic_tasks builds the scheduled tasks then, from whatever celery.Task was at that moment. - LockedTask, a base of its own, enters the same app context in __call__ (call_in_app_context, shared with ContextTask). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
configure_apppushed an app context that was never popped. Flask 2.3 reuses an already active app context for a request instead of pushing its own, soflask.goutlived each request within a uWSGI worker process.middle_auth_client'sauth_requiredskips authentication whenflask.g.auth_tokenis already set.On any endpoint without
@reset_auth, a request ran as whoever that worker last authenticated, including a request with no token at all. That covered most ofupload/api.py(inspect, start, cancel, status, user-jobs, admin cleanup) and the datastack/table views inviews.py. Requests were:Missing permission: edit for dataset minnie65from the upload wizard's inspect step;Reproduced on minnie (v5.33.0) with the app's test client: a request with a token, then one without, and the second returned 200 as the first user.
Fix
configure_appno longer pushes an app context. It was added in 2019 (f01dd3d) so early celery tasks could readcurrent_app. Tasks now run in their own context (ContextTask), as do the Ray entrypoints and Ray workers, and the celery signal handlers either don't use the app or push their own context. Code with no context falls back to the environment, as before, throughget_config_param.create_appregisters abefore_requesthook that clearsflask.g.auth_tokenandflask.g.auth_user, so no endpoint depends on carrying a decorator.@reset_authdecorators are removed.Tests
tests/test_reset_auth.py:editpermission follows the request's token;configure_appleaves no context pushed.Full suite on a fresh PostGIS: 701 passed, 2 skipped.
🤖 Generated with Claude Code