mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(gemini): validate native model id to block path traversal
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,6 +12,8 @@ import { initTranslators } from "open-sse/translator/index.js";
|
||||
|
||||
let initialized = false;
|
||||
const GEMINI_NATIVE_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/models";
|
||||
// Gemini model id charset (matches sanitizeGeminiFunctionName); blocks path traversal in upstream URL.
|
||||
const GEMINI_NATIVE_MODEL_PATTERN = /^[a-zA-Z0-9_.:-]+$/;
|
||||
|
||||
/**
|
||||
* Initialize translators once
|
||||
@@ -238,6 +240,9 @@ async function forwardGeminiNativeRequest(request, body, model, action) {
|
||||
if (authError) return authError;
|
||||
|
||||
const modelId = normalizeGeminiNativeModel(model);
|
||||
if (!GEMINI_NATIVE_MODEL_PATTERN.test(modelId)) {
|
||||
return Response.json({ error: { message: "Invalid model" } }, { status: 400 });
|
||||
}
|
||||
const excludeConnectionIds = new Set();
|
||||
const bodyText = JSON.stringify(body);
|
||||
let lastError = null;
|
||||
|
||||
Reference in New Issue
Block a user