fix(db): enforce stricter validation for api key model access

This commit is contained in:
nyatoru
2026-02-24 00:14:50 +07:00
parent d2bee37e76
commit 7ed40c2139

View File

@@ -291,7 +291,10 @@ export async function getApiKeyMetadata(key) {
* @returns {boolean} - true if allowed, false if not
*/
export async function isModelAllowedForKey(key, modelId) {
if (!key || !modelId) return true; // No key or model = allow (backward compatibility)
// If no key provided, allow (request may be using different auth method like JWT)
// If no modelId provided, deny (invalid request)
if (!key) return true;
if (!modelId) return false;
// Create cache key
const cacheKey = `${key}:${modelId}`;
@@ -304,7 +307,8 @@ export async function isModelAllowedForKey(key, modelId) {
}
const metadata = await getApiKeyMetadata(key);
if (!metadata) return true; // Key not found = allow (backward compatibility)
// SECURITY: Key not found in database = deny access (invalid/non-existent key)
if (!metadata) return false;
const { allowedModels } = metadata;