Skip to content

Use native FastAPI websocket security when available - #384

Merged
timkpaine merged 1 commit into
mainfrom
feature/native-fastapi-websocket-security
Oct 20, 2026
Merged

timkpaine merged 1 commit into
mainfrom
feature/native-fastapi-websocket-security

Conversation

@timkpaine

Copy link
Copy Markdown
Member

Description

Use FastAPI's native API-key dependencies when their request annotations support HTTPConnection, first released in FastAPI 0.144.0 via fastapi/fastapi#10147. Retain the existing websocket-compatible fallback on older versions without raising the dependency floor.

  • Share the selector across API-key, external API-key, and simple-auth middleware.
  • Keep auto_error=False so native FastAPI's different default errors do not change gateway authentication responses.
  • Cover native/fallback selection, query/header/cookie credentials over HTTP and websockets, OpenAPI security schemes, and unchanged 403 responses.

Verified on FastAPI 0.141.1 and 0.144.0. The full Python suite on 0.144.0 passed: 1,101 passed, 7 skipped, 1 expected failure. All 15 focused compatibility tests pass on both versions. make lint and all 5 JavaScript tests pass.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup
  • CI / build configuration
  • Other (describe below)

Checklist

  • Linting passes (make lint)
  • Tests pass (full Python suite and make test-js)
  • New tests added for new functionality
  • Documentation updated (not applicable)
  • Changelog / version bump (not applicable)

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

1 130 tests  +15   1 120 ✅ +15   11m 5s ⏱️ + 1m 16s
    1 suites ± 0      10 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit a0413d4. ± Comparison against base commit 652b6a6.

This pull request removes 1 and adds 16 tests. Note that renamed tests count towards both.
csp_gateway.tests.server.modules.web.test_outputs.TestOutputsApi ‑ test_file_types_without_libmagic[app.log.gz-\x1f\x8b\x08\x00\x1e#\xd1j\x02\xff\xcb\xc9OW\xc8\xc9\xccK\xe5\x02\x00G\x11\xd2\xbc\t\x00\x00\x00-application/gzip-download-]
csp_gateway.tests.server.modules.web.test_outputs.TestOutputsApi ‑ test_file_types_without_libmagic[app.log.gz-\x1f\x8b\x08\x00nX\xd5j\x02\xff\xcb\xc9OW\xc8\xc9\xccK\xe5\x02\x00G\x11\xd2\xbc\t\x00\x00\x00-application/gzip-download-]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[-cookie]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[-header]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[-query]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[None-cookie]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[None-header]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[None-query]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[valid-cookie]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[valid-header]
csp_gateway.tests.server.web.test_webserver ‑ test_api_key_security_http_and_websocket_credentials[valid-query]
…

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.64865% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.28%. Comparing base (652b6a6) to head (a0413d4).

Files with missing lines Patch % Lines
csp_gateway/tests/server/web/test_webserver.py 98.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
- Coverage   88.37%   88.28%   -0.09%     
==========================================
  Files         165      166       +1     
  Lines       20875    20946      +71     
  Branches     1914     1920       +6     
==========================================
+ Hits        18448    18493      +45     
- Misses       2427     2453      +26     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@timkpaine
timkpaine marked this pull request as ready for review October 20, 2026 16:48
@timkpaine
timkpaine merged commit 446b31c into main Oct 20, 2026
9 of 10 checks passed
@timkpaine
timkpaine deleted the feature/native-fastapi-websocket-security branch October 20, 2026 16:48
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.

1 participant