Removed direct references to 'vertexai_project_id' from openai.js and related files, ensuring it is now managed through backend secrets for enhanced security.

1e2bec1751ef06beb4b769dd290b7496b1df127a

InterestingDarkness <computeridiot999@gmail.com>

6 files changed, +27 -18Ignore whitespace
public/scripts/extensions/shared.js+1 -2
@@ -59,7 +59,6 @@ export async function getMultimodalCaption(base64Img, prompt) {
5959 // Add Vertex AI specific parameters if using Vertex AI
6060 if (extension_settings.caption.multimodal_api === 'vertexai') {
6161 requestBody.vertexai_auth_mode = oai_settings.vertexai_auth_mode;
62- requestBody.vertexai_project_id = oai_settings.vertexai_project_id;
6362 requestBody.vertexai_region = oai_settings.vertexai_region;
6463 }
6564
@@ -185,7 +184,7 @@ function throwIfInvalidModel(useReverseProxy) {
185184 if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) {
186185 throw new Error('Service Account JSON is required for Vertex AI Full mode. Please validate and save your Service Account JSON.');
187186 }
188187 if (!oai_settingssecret_state[SECRET_KEYS.vertexai_project_idVERTEXAI_PROJECT_ID]) {
189188 throw new Error('Project ID is required for Vertex AI Full mode.');
190189 }
191190 if (!oai_settings.vertexai_region) {
public/scripts/openai.js+13 -14
@@ -235,7 +235,6 @@ const sensitiveFields = [
235235 'custom_include_body',
236236 'custom_exclude_body',
237237 'custom_include_headers',
238- 'vertexai_project_id',
239238 'vertexai_region',
240239];
241240
@@ -309,7 +308,6 @@ export const settingsToUpdate = {
309308 claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true, false],
310309 use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true, false],
311310 vertexai_auth_mode: ['#vertexai_auth_mode', 'vertexai_auth_mode', false, true],
312- vertexai_project_id: ['#vertexai_project_id', 'vertexai_project_id', false, true],
313311 vertexai_region: ['#vertexai_region', 'vertexai_region', false, true],
314312 use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true, true],
315313 squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true, false],
@@ -393,7 +391,6 @@ const default_settings = {
393391 claude_use_sysprompt: false,
394392 use_makersuite_sysprompt: true,
395393 vertexai_auth_mode: 'express',
396- vertexai_project_id: '',
397394 vertexai_region: 'us-central1',
398395 use_alt_scale: false,
399396 squash_system_messages: false,
@@ -480,7 +477,6 @@ const oai_settings = {
480477 claude_use_sysprompt: false,
481478 use_makersuite_sysprompt: true,
482479 vertexai_auth_mode: 'express',
483- vertexai_project_id: '',
484480 vertexai_region: 'us-central1',
485481 use_alt_scale: false,
486482 squash_system_messages: false,
@@ -2201,7 +2197,6 @@ async function sendOpenAIRequest(type, messages, signal) {
22012197 generate_data['use_makersuite_sysprompt'] = oai_settings.use_makersuite_sysprompt;
22022198 if (isVertexAI) {
22032199 generate_data['vertexai_auth_mode'] = oai_settings.vertexai_auth_mode;
2204- generate_data['vertexai_project_id'] = oai_settings.vertexai_project_id;
22052200 generate_data['vertexai_region'] = oai_settings.vertexai_region;
22062201 }
22072202 }
@@ -3444,7 +3439,6 @@ function loadOpenAISettings(data, settings) {
34443439 if (settings.claude_use_sysprompt !== undefined) oai_settings.claude_use_sysprompt = !!settings.claude_use_sysprompt;
34453440 if (settings.use_makersuite_sysprompt !== undefined) oai_settings.use_makersuite_sysprompt = !!settings.use_makersuite_sysprompt;
34463441 if (settings.vertexai_auth_mode !== undefined) oai_settings.vertexai_auth_mode = settings.vertexai_auth_mode;
3447- if (settings.vertexai_project_id !== undefined) oai_settings.vertexai_project_id = settings.vertexai_project_id;
34483442 if (settings.vertexai_region !== undefined) oai_settings.vertexai_region = settings.vertexai_region;
34493443 if (settings.use_alt_scale !== undefined) { oai_settings.use_alt_scale = !!settings.use_alt_scale; updateScaleForm(); }
34503444 $('#stream_toggle').prop('checked', oai_settings.stream_openai);
@@ -3502,7 +3496,8 @@ function loadOpenAISettings(data, settings) {
35023496 $('#claude_use_sysprompt').prop('checked', oai_settings.claude_use_sysprompt);
35033497 $('#use_makersuite_sysprompt').prop('checked', oai_settings.use_makersuite_sysprompt);
35043498 $('#vertexai_auth_mode').val(oai_settings.vertexai_auth_mode);
3505- $('#vertexai_project_id').val(oai_settings.vertexai_project_id);
3499+ // Don't display Project ID in input - it's stored in backend secrets
3500+ $('#vertexai_project_id').val('');
35063501 $('#vertexai_region').val(oai_settings.vertexai_region);
35073502 // Don't display Service Account JSON in textarea - it's stored in backend secrets
35083503 $('#vertexai_service_account_json').val('');
@@ -3830,7 +3825,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
38303825 claude_use_sysprompt: settings.claude_use_sysprompt,
38313826 use_makersuite_sysprompt: settings.use_makersuite_sysprompt,
38323827 vertexai_auth_mode: settings.vertexai_auth_mode,
3833- vertexai_project_id: settings.vertexai_project_id,
38343828 vertexai_region: settings.vertexai_region,
38353829 use_alt_scale: settings.use_alt_scale,
38363830 squash_system_messages: settings.squash_system_messages,
@@ -5021,11 +5015,20 @@ async function onConnectButtonClick(e) {
50215015 }
50225016 } else {
50235017 // Full version - use service account
5024- if (!oai_settings.vertexai_project_id.trim()) {
5018+ // Check if we have a saved project ID, otherwise use the input value
5025- toastr.error('Project ID is required for Vertex AI full version');
5019+ const savedProjectId = secret_state[SECRET_KEYS.VERTEXAI_PROJECT_ID];
5020+ const inputProjectId = String($('#vertexai_project_id').val()).trim();
5021+
5022+ if (!savedProjectId && !inputProjectId) {
5023+ toastr.error(t`Project ID is required for Vertex AI full version`);
50265024 return;
50275025 }
50285026
5027+ // Save project ID to secrets if we have an input value
5028+ if (inputProjectId.length) {
5029+ await writeSecret(SECRET_KEYS.VERTEXAI_PROJECT_ID, inputProjectId);
5030+ }
5031+
50295032 // Check if service account JSON is saved in backend
50305033 if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) {
50315034 toastr.error('Service Account JSON is required for Vertex AI full version. Please validate and save your Service Account JSON.');
@@ -6128,10 +6131,6 @@ export function initOpenAI() {
61286131 $('#model_google_select').on('change', onModelChange);
61296132 $('#model_vertexai_select').on('change', onModelChange);
61306133 $('#vertexai_auth_mode').on('change', onVertexAIAuthModeChange);
6131- $('#vertexai_project_id').on('input', function () {
6132- oai_settings.vertexai_project_id = String($(this).val());
6133- saveSettingsDebounced();
6134- });
61356134 $('#vertexai_region').on('input', function () {
61366135 oai_settings.vertexai_region = String($(this).val());
61376136 saveSettingsDebounced();
public/scripts/secrets.js+1 -0
@@ -44,6 +44,7 @@ export const SECRET_KEYS = {
4444 SERPER: 'api_key_serper',
4545 FALAI: 'api_key_falai',
4646 XAI: 'api_key_xai',
47+ VERTEXAI_PROJECT_ID: 'vertexai_project_id',
4748 VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json',
4849};
4950
src/endpoints/backends/chat-completions.js+6 -1
@@ -527,7 +527,12 @@ async function sendMakerSuiteRequest(request, response) {
527527 url = `${apiUrl.toString().replace(/\/$/, '')}/v1/publishers/google/models/${model}:${responseType}?key=${keyParam}${stream ? '&alt=sse' : ''}`;
528528 } else if (authType === 'full') {
529529 // For Full mode (service account authentication), use project-specific URL
530- const projectId = request.body.vertexai_project_id || 'your-project-id';
530+ // Only use project ID from secrets
531+ const projectId = readSecret(request.user.directories, SECRET_KEYS.VERTEXAI_PROJECT_ID);
532+ if (!projectId) {
533+ console.warn('Vertex AI project ID is missing.');
534+ return response.status(400).send({ error: true });
535+ }
531536 const region = request.body.vertexai_region || 'us-central1';
532537 // Handle global region differently - no region prefix in hostname
533538 if (region === 'global') {
src/endpoints/google.js+5 -1
@@ -133,7 +133,11 @@ router.post('/caption-image', async (request, response) => {
133133 url = `${apiUrl.origin}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}`;
134134 } else if (authType === 'full') {
135135 // Full mode: use project-specific URL with Authorization header
136136 const projectId = readSecret(request.bodyuser.vertexai_project_id ||directories, 'your-project-id'SECRET_KEYS.VERTEXAI_PROJECT_ID);
137+ if (!projectId) {
138+ console.warn('Vertex AI project ID is missing.');
139+ return response.status(400).send({ error: true });
140+ }
137141 const region = request.body.vertexai_region || 'us-central1';
138142 // Handle global region differently - no region prefix in hostname
139143 if (region === 'global') {
src/endpoints/secrets.js+1 -0
@@ -54,6 +54,7 @@ export const SECRET_KEYS = {
5454 DEEPSEEK: 'api_key_deepseek',
5555 SERPER: 'api_key_serper',
5656 XAI: 'api_key_xai',
57+ VERTEXAI_PROJECT_ID: 'vertexai_project_id',
5758 VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json',
5859};
5960