Skip to content

Fix/ssrf secrets openapi - #85

Merged
NEFORCEO merged 8 commits into
masterfrom
fix/ssrf-secrets-openapi
Jul 3, 2026
Merged

Fix/ssrf secrets openapi#85
NEFORCEO merged 8 commits into
masterfrom
fix/ssrf-secrets-openapi

Conversation

@NEFORCEO

@NEFORCEO NEFORCEO commented Jul 3, 2026

Copy link
Copy Markdown
Member

x## 🚀 Description

Fixes a handful of correctness and security bugs found during a repo audit:

  • openapi/generator.py: BasicAuth/BearerAuth/DigestAuth/OAuth2ClientCredentials were imported only under TYPE_CHECKING but used at runtime in isinstance() checks — this raised NameError whenever OpenAPI generation hit a route with auth set. Moved the import to module level.
  • security/ssrf.py: check_url() failed open (allowed the request) when DNS resolution raised socket.gaierror. Changed to fail closed (block), consistent with the other exception branch.
  • security/secrets.py: SecretsMasking.mask_url() was a no-op in the pure-Python fallback (no compiled fasthttp._core), silently leaving secrets in query strings (?api_key=..., ?token=...) unmasked. Implemented a real fallback using the existing SECRET_PARAM_REGEX.
  • app.py: split _run_sse into _run_sse (reconnect/backoff loop) + _stream_sse (connection + event parsing) to remove duplicated retry code and drop cyclomatic complexity below the lint threshold; narrowed the blind except Exception with an explicit # noqa: BLE001.
  • routing.py: added # noqa: TC001 to the auth import — it looks type-only to ruff, but Route is a pydantic model and the field is resolved at runtime, so the import can't move into TYPE_CHECKING.
  • response.py: removed an unused httpx import; moved datetime under TYPE_CHECKING (used only in annotations).
  • dependencies/dependencies.py: minor comment cleanup.
  • Removed a stray duplicate file, examples/middleware/retry_middleware 2.py.

No documentation changes in this PR.


🧩 Type of Change

Please select one:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation update
  • refactor: Code refactoring
  • ci: CI/CD changes
  • chore: Maintenance

✅ Checklist

  • Tests added or updated
  • Documentation updated
  • No breaking changes
  • Code follows project style

ruff check fasthttp/ is clean and the full test suite passes (559 passed).


🔗 Related Issues

Fixes #


📸 Additional Context

Found via a manual security/lint audit of fasthttp/, not tied to a filed issue. The openapi/generator.py and security/secrets.py fixes are the most impactful — both are silent runtime bugs with no existing test coverage.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for your contribution, @NEFORCEO!

Please make sure:

  • Code is clean and formatted
  • Tests are passing
  • PR description is clear

Maintainers will review it soon.

@fasthttp-bot fasthttp-bot added the bug Something isn't working label Jul 3, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 42.38%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
✅ 6 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_response_req_text_from_json 213.2 µs 135.3 µs +57.56%
test_response_repr 196.4 µs 131.6 µs +49.22%
test_response_property_access 194.5 µs 131.2 µs +48.25%
test_response_json_parsing 205.6 µs 141.6 µs +45.22%
test_response_creation 201.3 µs 140.3 µs +43.49%
test_middleware_after_response 403.1 µs 351.4 µs +14.71%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/ssrf-secrets-openapi (3b65f26) with master (6f3d441)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (e7a0dd8) during the generation of this report, so 6f3d441 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@NEFORCEO
NEFORCEO merged commit 74b2194 into master Jul 3, 2026
17 checks passed
@NEFORCEO
NEFORCEO deleted the fix/ssrf-secrets-openapi branch July 3, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants