Skip to content

🚨 Flash: [CRITICAL] Fix API Key DoS Vulnerability - #17

Merged
Shreyassp002 merged 2 commits into
mainfrom
fix-api-key-verification-dos-630936692844794017
Apr 3, 2026
Merged

Shreyassp002 merged 2 commits into
mainfrom
fix-api-key-verification-dos-630936692844794017

Conversation

@Shreyassp002

Copy link
Copy Markdown
Member
  • Category: Security
  • Priority: P0
  • 💡 What: The verifyApiKey function in src/lib/api/verify-api-key.ts was doing an O(N) lookup. It would fetch all enabled merchants and run a computationally expensive bcrypt.compare operation against each one until it found a match.
  • 🎯 Why: An attacker could send a flood of random, invalid API keys. Because bcrypt.compare is designed to be slow, forcing the server to hash and compare against every single merchant in the database for each invalid request would quickly exhaust server resources and cause a Denial of Service (DoS).
  • 📊 Impact: Reduces authentication lookup from O(N) bcrypt.compare operations to an O(1) database query followed by at most one bcrypt.compare operation.
  • ✅ Verification: Code review confirmed the logic is correct and successfully mitigates the DoS vulnerability while preserving the collision-handling loop. Checked that package.json was restored to its original state. Run npm run lint and npm run build locally.

PR created automatically by Jules for task 630936692844794017 started by @Shreyassp002

This modifies `verifyApiKey` to use `api_key_prefix` (the first 16 characters of the key) to perform an O(1) database lookup instead of fetching all enabled merchants and running an O(N) `bcrypt.compare` on every single one. This neutralizes a critical Denial of Service (DoS) vulnerability.

Co-authored-by: Shreyassp002 <96625037+Shreyassp002@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Apr 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flash-protocol Ready Ready Preview, Comment Apr 3, 2026 6:21am

- Fixed `any` type casting on Supabase client across multiple files (`route.ts`).
- Fixed unused `payment_links` variable from transaction queries by explicitly ignoring them.
- Fixed other unused variables identified by ESLint in CI.

Co-authored-by: Shreyassp002 <96625037+Shreyassp002@users.noreply.github.com>
@Shreyassp002
Shreyassp002 merged commit 3da70c3 into main Apr 3, 2026
2 of 6 checks passed

This branch was successfully deployed

1 active deployment
Preview — b59d8ac6 Deployed Apr 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant