Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/api/metadata/proxy/feature/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function checkURLForPrivateIP(uri: URL | string) {
for (const address of addresses) {
if (isPrivateIP(address.address)) {
return true;
}
}
}
} else {
const singleResult = addresses as unknown as LookupAddressResult;
Expand Down
5 changes: 4 additions & 1 deletion app/api/metadata/proxy/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TIMEOUT = process.env.NEXT_PUBLIC_METADATA_TIMEOUT
/**
* Respond with error in a JSON format
*/
function respondWithError(status: keyof typeof errors, message?: string){
function respondWithError(status: keyof typeof errors, message?: string) {
return NextResponse.json({ error: message ?? errors[status].message }, { status });
}

Expand Down Expand Up @@ -47,14 +47,17 @@ export async function GET(

// check that uri has supported protocol despite of any other checks
if (!isHTTPProtocol(parsedUrl)) {
console.error('Unsupported protocol', parsedUrl.protocol);
return respondWithError(400);
}

const isPrivate = await checkURLForPrivateIP(parsedUrl);
if (isPrivate) {
console.error('Private IP detected', parsedUrl.hostname);
return respondWithError(403);
}
} catch (_error) {
console.error(_error);
return respondWithError(400);
}

Expand Down