Subdomain Pages Bypass
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
This sample allows subdomains to be accessed from the root domain:
https://hello.vercel.pub could be accessed by going to https://vercel.pub/s/hello
Adding in
// Block access to the subdomain pages from the root domain
if (pathname.startsWith('/s/')) {
return NextResponse.rewrite(new URL('/404', request.url))
}
would fix it.
middleware.ts
export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
const subdomain = extractSubdomain(request);
if (subdomain) {
// Block access to admin page from subdomains
if (pathname.startsWith('/admin')) {
return NextResponse.redirect(new URL('/', request.url));
}
// For the root path on a subdomain, rewrite to the subdomain page
if (pathname === '/') {
return NextResponse.rewrite(new URL(`/s/${subdomain}`, request.url));
}
}
// Block access to the subdomain pages from the root domain
if (pathname.startsWith('/s/')) {
return NextResponse.rewrite(new URL('/404', request.url))
}
// On the root domain, allow normal access
return NextResponse.next();
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in middleware.ts and trace the handling of /s/ paths for the root domain and subdomains. Verify that https://vercel.pub/s/hello no longer exposes the subdomain page, while https://hello.vercel.pub still rewrites its root path to the subdomain page and admin paths remain blocked.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, typescript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100