Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Commit b0df452

Browse files
authored
fix: validate address param in getUsernames endpoint (#2914)
1 parent ee9a5a1 commit b0df452

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • apps/web/app/(basenames)/api/basenames/getUsernames

apps/web/app/(basenames)/api/basenames/getUsernames/route.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { NextRequest, NextResponse } from 'next/server';
2+
import { isAddress } from 'viem';
23

34
import type { ManagedAddressesResponse } from 'apps/web/src/types/ManagedAddresses';
45
import { cdpBaseUri } from 'apps/web/src/cdp/constants';
56

67
export async function GET(request: NextRequest) {
78
const address = request.nextUrl.searchParams.get('address');
8-
if (!address) {
9-
return NextResponse.json({ error: 'No address provided' }, { status: 400 });
9+
if (!address || !isAddress(address)) {
10+
return NextResponse.json({ error: 'Invalid address provided' }, { status: 400 });
1011
}
1112

1213
const network = request.nextUrl.searchParams.get('network') ?? 'base-mainnet';
@@ -29,6 +30,10 @@ export async function GET(request: NextRequest) {
2930
},
3031
});
3132

33+
if (!response.ok) {
34+
return NextResponse.json({ error: 'Failed to fetch usernames' }, { status: response.status });
35+
}
36+
3237
const data = (await response.json()) as ManagedAddressesResponse;
3338

3439
return NextResponse.json(data, { status: 200 });

0 commit comments

Comments
 (0)