Skip to content

Implement Redis-Backed Rate Limiting#454

Open
adityapichikala wants to merge 16 commits into
imDarshanGK:mainfrom
adityapichikala:fix/share-xss
Open

Implement Redis-Backed Rate Limiting#454
adityapichikala wants to merge 16 commits into
imDarshanGK:mainfrom
adityapichikala:fix/share-xss

Conversation

@adityapichikala
Copy link
Copy Markdown
Contributor

Description

Migrated the rate limiter to use fastapi-limiter with a Redis backend to ensure scalability and persistence across container restarts.

  • Implemented a dynamic fallback dependency (dynamic_rate_limiter) that gracefully falls back to the existing in-memory deque if the Redis connection fails or isn't configured.
  • Moved the rate limit check from a global middleware to a router-level Depends block, ensuring it only targets the heavy AI endpoints.
  • Added a redis container to docker-compose.yml and updated .env.example.

Related Issue

Fixes #443

Type of change

  • Bug fix
  • New feature / enhancement
  • Documentation update
  • Test addition
  • Refactor

Checklist

  • I have read CONTRIBUTING.md
  • My branch is up to date with main
  • I have run pytest -v and all tests pass
  • I have not introduced duplicate issues or features
  • My PR title follows the format: feat/fix/docs/test: short description
  • I have added tests for new features (Level 2 and 3 issues)
  • No hardcoded secrets or API keys in my code
  • This PR is linked to a GSSoC 2026 issue

Screenshots (if frontend change)

N/A (Backend logic only)

Test evidence

pytest -v
# ... (omitting verbose initialization) ...
tests/test_ai_provider.py::test_call_llm_success PASSED                  [  0%]
tests/test_ai_provider.py::test_call_llm_timeout_retries PASSED          [  1%]
# ... (omitting middle tests for brevity) ...
tests/test_python_ast_analyzer.py::test_detects_division_by_zero_inside_function_call PASSED [ 96%]
tests/test_python_ast_analyzer.py::test_detects_out_of_range_list_index PASSED [ 96%]
tests/test_python_ast_analyzer.py::test_detects_out_of_range_string_index PASSED [ 97%]
tests/test_python_ast_analyzer.py::test_detects_string_integer_concatenation PASSED [ 98%]
tests/test_share.py::test_create_and_fetch_share PASSED                  [ 99%]
tests/test_share.py::test_expired_share_returns_404 PASSED               [100%]

============================== warnings summary ===============================
..\..\..\..\..\AppData\Roaming\Python\Python314\site-packages\fastapi\testclient.py:1
  C:\Users\adity\AppData\Roaming\Python\Python314\site-packages\fastapi\testclient.py:1: StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
    from starlette.testclient import TestClient as TestClient  # noqa

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================= 128 passed, 1 warning in 6.81s ========================

@adityapichikala
Copy link
Copy Markdown
Contributor Author

hi @imDarshanGK ,
would please check this and verify,if any changes are required i will be doing it

@imDarshanGK
Copy link
Copy Markdown
Owner

@adityapichikala update your branch with the latest main changes and resolve conflicts

@adityapichikala
Copy link
Copy Markdown
Contributor Author

hi @imDarshanGK ,
check it out ,everything is set

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.

[Feature]: Upgrade to Redis-Backed Rate Limiting for Production-Scale Resilience

2 participants