Skip to content

[NSOC] [GSSoC] Added Rate Limiting + Bot/Abuse Protections - #841

Merged
devanshi14malhotra merged 2 commits into
devanshi14malhotra:mainfrom
Aditya8369:800
May 24, 2026
Merged

devanshi14malhotra merged 2 commits into
devanshi14malhotra:mainfrom
Aditya8369:800

Conversation

@Aditya8369

Copy link
Copy Markdown
Contributor

Pull Request

NSOC and GSSoC

Description

Implemented: rate limiting + abuse protections on sensitive endpoints, with per-IP + per user/session + per endpoint keying, and added targeted tests.

What I changed

  1. Core limiter hardening in backend app
  • Added composite limiter keying logic in app.py:
    • IP component
    • user identity (JWT) when available, otherwise session-cookie hint, otherwise anon
    • endpoint name/path component
  • Added centralized 429 handler wired to Flask-Limiter breach handling so responses include Retry-After through existing rate-limit response utility.
  • Registered limiter and rate-limit error handler on both app instances present in app.py, including limiter.init_app for the later app instance in that file.
  1. Sensitive endpoint limits
  • Auth flows set to 5 per 10 seconds:
    • register, login in app.py
  • AI/cost-sensitive endpoints set to 10 per minute:
    • analyze-mood, mood-tags, mood-search, category-books, generate-note, chat in app.py
  • Library/purchase-link/alert write-like and abuse-prone endpoints set to 20 per minute:
    • add-to-library, library sync, create price alert, purchase-links in app.py
  • Scraping-like exposed endpoint set to 30 per minute:
    • /api/books in app.py
  1. Test coverage added
  • Added test_rate_limiting.py with:
    • login burst limit test verifying 429 and Retry-After
    • purchase-links burst limit test verifying 429 and Retry-After

Validation status

  • Static diagnostics:
    • No syntax/editor errors in app.py
    • No syntax/editor errors in test_rate_limiting.py
  • Runtime tests:
    • I attempted to run the new pytest file, but execution was blocked by missing runtime dependencies in the current venv during collection (first flask-limiter, then flask_migrate). I started dependency installation in the venv, but full backend dependency install is large and was not completed/verified in this run.

Notes

  • This repository currently has two app definitions in app.py. I intentionally registered limiter/error handling for both so protections apply regardless of which app object is active.

Related Issue

Fixes #800

Type of Change

  • Bug Fix
  • Feature
  • Enhancement
  • Documentation

Checklist

  • Code follows guidelines
  • Tested properly
  • Docs updated
  • PR title includes the relevant event tag or a general contribution label

Example:
[NSoC'26] Add authentication system

@netlify

netlify Bot commented May 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for bibliodrift-dm ready!

Name Link
🔨 Latest commit 7353b7b
🔍 Latest deploy log https://app.netlify.com/projects/bibliodrift-dm/deploys/6a1116138bce54000846e7a0
😎 Deploy Preview https://deploy-preview-841--bibliodrift-dm.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Aditya8369

Copy link
Copy Markdown
Contributor Author

@devanshi14malhotra consider my PRs under both NSOC and GSSoC

@Aditya8369

Copy link
Copy Markdown
Contributor Author

@devanshi14malhotra solved the merge conflicts, pr is ready to merge

@devanshi14malhotra devanshi14malhotra added level3 10 points NSoC'26 For issues and PRs which are a part of the Nexus Spring of Code open source event labels May 24, 2026
@devanshi14malhotra
devanshi14malhotra merged commit a3ca8a1 into devanshi14malhotra:main May 24, 2026
5 of 6 checks passed
@Aditya8369

Copy link
Copy Markdown
Contributor Author

@devanshi14malhotra please add gssoc:approved also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level3 10 points NSoC'26 For issues and PRs which are a part of the Nexus Spring of Code open source event

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Add Rate Limiting + Bot/Abuse Protections on Sensitive Endpoints

2 participants