Skip to content

feat(security): implement Next.js Edge Middleware for admin routes - #1255

Merged
ayomideadeniran merged 1 commit into
StellarDevHub:mainfrom
martinshub-tech:fix-admin-middleware
Sep 3, 2026
Merged

feat(security): implement Next.js Edge Middleware for admin routes#1255
ayomideadeniran merged 1 commit into
StellarDevHub:mainfrom
martinshub-tech:fix-admin-middleware

Conversation

@martinshub-tech

Copy link
Copy Markdown

Closes #1087

Description: This PR implements Next.js Edge Middleware to securely protect administrative routes, directly fulfilling the required technical specifications and edge deployment considerations.

Key Features & Implementation Details:

JWT & Session Validation: Validates JWT signatures and session nonces (x-nonce) directly on the Next.js Edge runtime using standard Web Crypto API (crypto.subtle.verify), with zero origin server overhead.
IP Allowlisting & Geo-fencing: Enforces region restrictions (ALLOWED_ADMIN_COUNTRIES) and IP whitelists (ALLOWED_ADMIN_IPS) for all paths matching /admin*.
Bot Detection & Rate Limiting: Introduces early request termination for automated malicious agents, paired with an efficient in-memory token-bucket mechanism deployed at the edge layer.
Secure Redirect Handling: Preserves return paths on unauthenticated requests and automatically validates the returnTo URLs against open-redirect vulnerabilities.
Testing Notes:

JWT_SECRET must be set in your .env to validate admin tokens locally.
Adjust ALLOWED_ADMIN_IPS (comma-separated list of IPs) to simulate the IP allowlist. By default, localhost traffic is permitted.
Run pnpm dev and visit /admin to verify that unauthorized requests successfully redirect to /login?returnTo=/admin

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@martinshub-tech Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@martinshub-tech is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@adeniran19-maker

Copy link
Copy Markdown

@martinshub-tech PR under review — I will get back to you if I find any wrong implementations.

@ayomideadeniran
ayomideadeniran merged commit b612670 into StellarDevHub:main Sep 3, 2026
1 check failed
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.

[Admin Panel] Build Edge Middleware Admin Authentication & Network Perimeter Shield

3 participants