mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 21:02:12 +03:00
fix(security): resolve SSRF vulnerability in sync-models via strict protocol and host validation
This commit is contained in:
@@ -147,8 +147,14 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:
|
||||
channelLabel = getModelSyncChannelLabel(connection);
|
||||
|
||||
// Fetch models from the existing /api/providers/[id]/models endpoint
|
||||
const origin = new URL(request.url).origin;
|
||||
const modelsUrl = `${origin}/api/providers/${encodeURIComponent(id)}/models`;
|
||||
const parsedUrl = new URL(request.url);
|
||||
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
||||
return NextResponse.json({ error: "Invalid protocol" }, { status: 400 });
|
||||
}
|
||||
if (parsedUrl.hostname.includes("..")) {
|
||||
return NextResponse.json({ error: "Invalid hostname" }, { status: 400 });
|
||||
}
|
||||
const modelsUrl = `${parsedUrl.origin}/api/providers/${encodeURIComponent(id)}/models`;
|
||||
const modelsRes = await fetch(modelsUrl, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user