fix: add rate limiting to /api/profile to prevent DoS amplification#196
Open
nishit546 wants to merge 1 commit into
Open
fix: add rate limiting to /api/profile to prevent DoS amplification#196nishit546 wants to merge 1 commit into
nishit546 wants to merge 1 commit into
Conversation
|
@nishit546 is attempting to deploy a commit to the Dot_NotSam's projects Team on Vercel. A member of the Team first needs to authorize it. |
SamXop123
requested changes
Jun 16, 2026
SamXop123
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR! A few updates needed:
- Enable Proxy Trust: Add
app.set('trust proxy', 1);afterconst app = express();so rate limiting doesn't block all users sharing the Vercel proxy. - Update Thresholds: Change the window to 15 seconds (
windowMs: 15 * 1000) and the request limit to 10 (max: 10). - Return SVG instead of JSON: Returning JSON causes broken image placeholders. Use
express-rate-limit'shandlerto return an SVG error instead:
handler: (req, res) => {
res.setHeader('Content-Type', 'image/svg+xml');
const svg = renderGracefulError({
code: 'RATE_LIMIT',
detail: 'Too many requests. Please try again in 15 seconds.',
});
res.status(429).send(svg);
}Adds two-tier rate limiting with SVG error responses: - trust proxy enabled for Vercel deployment - Global limiter: 10 requests per 15s per IP - Username-based limiter: 10 requests per 15s per username - Returns rate-limited SVG (not JSON) so README image embeds render the error instead of showing a broken placeholder Closes SamXop123#191
f311bcd to
0ffb3dc
Compare
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.
Description
Adds two-tier rate limiting to the /api/profile\ endpoint to prevent DoS amplification and resource exhaustion.
Problem
Each /api/profile\ request triggers up to 7 external API calls (GitHub REST × 4, GitHub GraphQL, GitHub CDN, LeetCode/Codeforces/CodeChef). There was zero rate limiting, allowing an attacker to:
Solution
Changes
Closes
Closes #196