DevPath icon indicating copy to clipboard operation
DevPath copied to clipboard

No rate limiting on /api/recommend endpoint enables abuse

Open Siddh2024 opened this issue 6 months ago • 7 comments

Type: Security Bug File: routes/main_routes.py, line 47

The recommendation endpoint runs without rate limiting. Attackers can send high-volume requests to exhaust server resources.

Siddh2024 avatar May 30 '26 16:05 Siddh2024

Hi maintainers,

I would like to work on this issue under GSSoC'26.

After reviewing the project structure, I noticed that the recommendation endpoint (POST /api/recommend) is a publicly accessible API and currently lacks rate limiting protection. Since this endpoint performs recommendation processing on every request, it could be abused through automated high-frequency requests, potentially leading to resource exhaustion, degraded performance, or denial-of-service scenarios.

Proposed Solution Analyze the current implementation in routes/main_routes.py. Implement rate limiting on the recommendation endpoint using a well-established Flask-compatible solution (e.g., Flask-Limiter). Configure sensible limits such as: Requests per minute per IP Burst protection for rapid consecutive requests Return proper HTTP 429 Too Many Requests responses when limits are exceeded. Ensure the implementation remains configurable for future scaling needs. Add/update tests to verify rate-limiting behavior and prevent regressions. Document the configuration for contributors and maintainers. Relevant Experience

My background is primarily in backend development and API engineering, including:

Node.js and Express API development Authentication and authorization mechanisms Database-backed applications Security-focused backend design Building and securing web applications for production use Experience identifying and mitigating API abuse vectors

Could you please assign this issue to me under GSSoC'26?

Thank you!

varshneytarang avatar May 30 '26 17:05 varshneytarang

Hi @komalharshita - I would like to work on this issue under GSSoC 2026. Please assign this to me!

boss477 avatar May 30 '26 21:05 boss477

Hi @komalharshita , I'd like to work on this issue under GSSoC'26. Please assign it to me.

prasannaPratapSingh avatar May 31 '26 17:05 prasannaPratapSingh

Hey team, I'd love to claim this issue if it hasn't been assigned yet!

I noticed the recommend endpoint is wide open to resource exhaustion if someone decides to spam it. I've already set up a local fix on my end that integrates Flask-Limiter to pull the user's remote IP address and throttle requests to a safe limit of 5 per minute.

Here is a quick look at the route protection logic I've got ready:

from flask import Blueprint, render_template, request, jsonify, send_from_directory, abort, make_response
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

# Create the Blueprint that app.py will register
main = Blueprint("main", __name__)

# Initialize rate limiter using the user's remote IP address
limiter = Limiter(key_func=get_remote_address)

# Professional Error Handler: Catches rate-limit breaches gracefully
@main.errorhandler(429)
def ratelimit_handler(e):
    return jsonify({
        "status": 429,
        "error": "Too Many Requests",
        "message": "You have exceeded the allowed request limit (5 per minute). Please slow down and try again later."
    }), 429

@main.route("/api/recommend", methods=["POST"])
@limiter.limit("5 per minute")
def recommend():
    """
    Accept a JSON body with user inputs and return matching project recommendations.
    """
    # ... rest of the existing route logic stays exactly the same ...

The app handles the middleware setup cleanly and boots up without any issues. Could you please assign this to me (@Shubham-Gotawade) so I can open a pull request? Thanks!

Shubham-Gotawade avatar Jun 02 '26 05:06 Shubham-Gotawade

I’m interested in contributing to this project and would love to work on this issue. I would be happy to implement the required changes. Please assign me this issue. /assign

Gurudutta22 avatar Jun 04 '26 07:06 Gurudutta22

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Nov 20 '26 08:11 github-actions[bot]

This issue was closed because it has been inactive for an extended period. If this issue is still relevant, feel free to reopen it or create a new one.

github-actions[bot] avatar Nov 27 '26 09:11 github-actions[bot]