Security: Add DoS protection with rate limiting for critical API endpoints - #1
Merged
Merged
Conversation
- Add unified rate limiting library (includes/rate_limit.php) - Fix critical vulnerability: Add rate limiting to Stripe webhook endpoint * Limit: 100 requests per minute per IP * Add payload size validation (10KB max) - Fix high vulnerability: Add rate limiting to membership submission * Limit: 5 submissions per hour per IP - Add rate limiting to membership quote endpoint * Limit: 30 requests per 15 minutes per IP - Add comprehensive security documentation * SECURITY_DOS_REVIEW.md - Full security analysis * DOS_SECURITY_PATCHES.md - Implementation guide Security improvements: - Prevents webhook flooding attacks - Prevents application submission abuse - Prevents database and file system exhaustion - IP-based tracking with automatic cleanup - Configurable rate limits per endpoint - Proxy-aware IP detection with trust settings - Proper HTTP 429 responses with Retry-After headers Related: Security review of DoS attack vectors Co-authored-by: paulhlee1967 <paulhlee1967@users.noreply.github.com>
Co-authored-by: paulhlee1967 <paulhlee1967@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds Denial of Service (DoS) protection to the RC Flight Operations application by implementing rate limiting on critical API endpoints that were previously unprotected.
Security Review Findings
A comprehensive security review identified several DoS vulnerabilities:
Changes in This PR
New Files
includes/rate_limit.php- Unified rate limiting librarySECURITY_DOS_REVIEW.md- Comprehensive security analysisDOS_SECURITY_PATCHES.md- Implementation and deployment guideModified Files
api_stripe_webhook.php✅ Critical fixapi_membership_submit.php✅ High-priority fixapi_membership_quote.php✅ Medium-priority fixTechnical Details
Rate Limiting Implementation
rate_limit_eventsdatabase tableRate Limit Presets
Configuration Example
Security Impact
Vulnerabilities Fixed
Remaining Work
The following improvements are documented but not included in this PR (lower priority):
See
SECURITY_DOS_REVIEW.mdfor complete prioritization and recommendations.Testing
Manual Testing Completed
Testing Instructions
Deployment Notes
Requirements
Deployment Checklist
Rollback Plan
Simple rollback if issues arise:
git revert c27e79f # Or manually remove includes/rate_limit.php and revert API filesDocumentation
All documentation is included in this PR:
SECURITY_DOS_REVIEW.md- Complete security analysisDOS_SECURITY_PATCHES.md- Implementation guidePerformance Impact
Monitoring
Rate limit triggers are logged to PHP error log:
Query rate limit events:
Benefits
✅ Prevents webhook flooding - Protects against Stripe webhook abuse
✅ Prevents application spam - Limits fake membership submissions
✅ Protects database - Prevents connection exhaustion
✅ Protects file system - Limits upload flooding
✅ Configurable - Easy to adjust limits per installation
✅ Monitored - All rate limit events logged
✅ Maintainable - Clean, reusable code with good documentation
✅ No breaking changes - Fully backward compatible
References
Review Checklist
Questions?
See the comprehensive documentation in
SECURITY_DOS_REVIEW.mdandDOS_SECURITY_PATCHES.mdfor answers to: