Skip to content

Flask: plugins (JWT/API-key auth), enable_cors, publish_swagger, openapi_insecure - #45

Merged
thorwhalen merged 2 commits into
masterfrom
feat/42-flask-auth-cors-swagger
Oct 13, 2026
Merged

thorwhalen merged 2 commits into
masterfrom
feat/42-flask-auth-cors-swagger

Conversation

@thorwhalen

@thorwhalen thorwhalen commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #42 (the auth/CORS/swagger part; the leftovers from the #43 review are now #44).

  • JWTPlugin / ApiKeyAuthPlugin gain a framework-independent authenticate(header, *, method, endpoint) (reusing py2http.auth); the Bottle plugins now call it, behaviour unchanged.
  • New py2http/flask_plugins.py: before_request auth hook (plugins run outermost-first as under Bottle; /ping public; /openapi public iff openapi_insecure — note the issue text had this inverted, Bottle's code is followed; unmatched routes run no view; with CORS the OPTIONS preflight is open, as Bottle's CORS plugin answers before auth), after_request CORS headers, claims on request.token (reachable through current_request).
  • A plugin without authenticate (Bottle-only) still raises NotImplementedError: never silently dropped.
  • publish_swagger via swagger_ui.api_doc (Flask supported); guarded by the plugins like any route (as under Bottle).
  • Tests parametrized over bottle/flask (test_flask_plugins.py): 295 passed (271 before).

Auth is security-sensitive. Adversarial review (fresh Opus, security): round 1 found a MEDIUM bypass (ping/openapi exempted by endpoint name, so a user function named openapi with openapi_insecure was public under Flask) and a LOW (duck-typed authenticate). Both fixed (exemption by view-function identity; plugins must subclass py2http.auth.AuthPlugin) with regression tests. Round 2 on the fixed state: PASS, no bypass, Bottle behaviour identical to master across the request matrix. Tests: 297 passed.

🤖 Generated with Claude Code

thorwhalen and others added 2 commits October 13, 2026 16:25
…er, openapi_insecure (#42)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…require AuthPlugin (review fixes)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 06f773d into master Oct 13, 2026
6 checks passed
@thorwhalen
thorwhalen deleted the feat/42-flask-auth-cors-swagger branch October 13, 2026 16:31
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.

Flask: support the Bottle-only configs (plugins/JWT auth, enable_cors, publish_swagger, openapi_insecure)

1 participant