Skip to content

fixed the middleware bypass risk #1834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chauhan-varun
Copy link

@chauhan-varun chauhan-varun commented May 10, 2025

PR Fixes:

  • Middleware Authentication Bypass

Resolves #1831

Fix Implementation

  1. Middleware Layer (/src/middleware.ts):

    • Block and reject x-middleware-subrequest header manipulation
    • Remove client-provided g headers
    • Add timestamp validation
  2. API Validation (/src/lib/validateAuthHeader.ts):

    • Created reusable validation helper
    • Implemented defense-in-depth validation

Verification

The security fix was verified using curl to attempt the exploit:

curl -i -H "x-middleware-subrequest: src/middleware:src/middleware:src/middleware" -H "g: {\"id\":1,\"email\":\"[email protected]\"}" "http://localhost:3000/api/mobile/search?q=web"

Result: HTTP/1.1 403 Forbidden with {"message":"Unauthorized"} response


image

Checklist before requesting a review
I have performed a self-review of my code
I assure there is no similar/duplicate pull request regarding same issue

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.

bug: Security Issue: Middleware Bypass Risk in API Endpoint
1 participant