Skip to content

fix(quiz): cap question count at 20 and rate-limit /api/quiz/generate to 10 requests per minute - #293

Merged
mugenkyou merged 1 commit into
mugenkyou:mainfrom
anshul23102:fix/290-quiz-rate-limit
Jun 4, 2026
Merged

fix(quiz): cap question count at 20 and rate-limit /api/quiz/generate to 10 requests per minute#293
mugenkyou merged 1 commit into
mugenkyou:mainfrom
anshul23102:fix/290-quiz-rate-limit

Conversation

@anshul23102

Copy link
Copy Markdown

Pull Request Summary

The /api/quiz/generate endpoint had no upper bound on the count parameter and no rate limiting. A caller could send count=100000 to a single request, forcing the Groq LLM to attempt an enormous quiz and exhausting all available tokens in one call. Combined with unlimited concurrent requests, this could drain the project's Groq API quota within seconds and block the feature for all users.

Fixes #290


Changes Introduced

  • app.py: Added Flask-Limiter import and wired a per-IP Limiter instance to the Flask app using in-memory storage with no global default limit so only explicitly decorated routes are throttled.
  • app.py: Added MAX_QUIZ_QUESTIONS = 20 constant. Both the JSON body and multipart form-data code paths now clamp count with min(int(count), MAX_QUIZ_QUESTIONS) before the value reaches the LLM prompt.
  • app.py: Applied @limiter.limit("10 per minute") decorator to generate_quiz to throttle per-IP request volume.
  • requirements.txt: Added Flask-Limiter==3.5.0.

Screenshots / Demo (for UI changes)

Not applicable. This is a backend change with no UI impact.


Checklist

  • Code follows project conventions and best practices.
  • Feature or fix works correctly on both mobile and desktop.
  • No new console errors or accessibility regressions.
  • Documentation updated if applicable.
  • Visuals attached for UI-related updates (not applicable here).

Additional Notes

The rate limit (10/min per IP) and the question cap (MAX_QUIZ_QUESTIONS = 20) are both constants that can be adjusted without touching any other code. The in-memory storage backend is appropriate for a single-process deployment; if the app scales horizontally a Redis URI can be passed to storage_uri without any other changes.


Could you please add the appropriate NSoC '26 label to this PR? It helps with tracking and scoring under NSoC '26. Thank you!

… to 10/min

/api/quiz/generate had no upper bound on the 'count' parameter and no rate
limiting. Any caller could pass count=100000 or make unlimited concurrent
requests, exhausting the project's Groq API quota within seconds.

Changes:
- Added Flask-Limiter dependency (3.5.0) to requirements.txt.
- Wired a per-IP Limiter instance to the Flask app using in-memory storage.
- Added MAX_QUIZ_QUESTIONS = 20 constant. Both the JSON and form-data code
  paths now call min(int(count), MAX_QUIZ_QUESTIONS) before passing count
  to the LLM prompt.
- Applied @limiter.limit('10 per minute') decorator to generate_quiz so a
  single IP cannot exhaust Groq quota through rapid requests.

Closes mugenkyou#290
@github-actions github-actions Bot added awaiting review enhancement New feature or request level-2 Intermediate issue; moderate JS or UI work, needs some project understanding. nsoc26 labels May 29, 2026
@github-actions
github-actions Bot requested a review from mugenkyou May 29, 2026 22:20
@github-actions

Copy link
Copy Markdown

📥 Pull Request Received

Thank you for your contribution to College Daddy. Your pull request has been received and is currently under review.

🔗 Linked Issues

✅ Pre-Merge Checklist

Please ensure the following requirements are met:

  • Changes adhere to contribution guidelines
  • Related issues are referenced in description
  • All changes tested and verified locally
  • Code follows project standards

👤 Reviewer Assigned

@mugenkyou has been assigned to review this pull request.


Our team will review your submission shortly. We appreciate your effort in improving the platform for students.

@anshul23102

Copy link
Copy Markdown
Author

Hi @mugenkyou, a gentle follow-up on this PR. It has been 2 days since any activity. There are no merge conflicts. Please review when you have a moment. Happy to address any feedback.

@mugenkyou
mugenkyou merged commit 990033f into mugenkyou:main Jun 4, 2026
1 of 2 checks passed
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🎉 Pull Request Merged Successfully

Contributor: @anshul23102

Your pull request has been successfully merged into the main codebase. Thank you for your valuable contribution to College Daddy.

🚀 Next Steps

We encourage you to:

  • ⭐ Star the repository to support the project
  • 👀 Watch for updates and participate in discussions
  • 🔄 Continue contributing to enhance the platform

We value your commitment to improving educational technology and look forward to your continued involvement.

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

Labels

enhancement New feature or request level-2 Intermediate issue; moderate JS or UI work, needs some project understanding. nsoc26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Level 2] app.py: /api/quiz/generate has no rate limit and no upper bound on question count, enabling Groq API quota exhaustion

2 participants