Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🚷 fix: Isolate Jina Credential Provenance (#16134)
Danny Avila7b645f4eaf9a
diff --git a/packages/api/src/web/web.spec.ts b/packages/api/src/web/web.spec.tsindex be0748b779..6dc6af2104 100644--- a/packages/api/src/web/web.spec.ts+++ b/packages/api/src/web/web.spec.ts@@ -671,6 +671,115 @@ describe('web.ts', () => {}});+ it('should not send a system Jina key to a user-provided API URL', async () => {+ const originalApiKey = process.env.JINA_API_KEY;+ const originalApiUrl = process.env.JINA_API_URL;+ process.env.JINA_API_KEY = 'system-jina-key';+ process.env.JINA_API_URL = AuthType.USER_PROVIDED;+ mockIsSSRFTarget.mockReturnValue(false);+ mockResolveHostnameSSRF.mockResolvedValue(false);+ mockLoadAuthValues.mockImplementation(({ authFields }) => {+ const result: Record<string, string> = {};+ authFields.forEach((field: string) => {+ if (field === 'JINA_API_KEY') {+ result[field] = 'system-jina-key';+ } else if (field === 'JINA_API_URL') {+ result[field] = 'https://user-jina.example.com/v1/rerank';+ } else {+ result[field] =+ field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key';+ }+ });+ return Promise.resolve(result);+ });++ try {+ const result = await loadWebSearchAuth({+ userId,+ webSearchConfig: {+ ...webSearchConfig,+ rerankerType: RerankerTypes.JINA,+ },+ loadAuthValues: mockLoadAuthValues,+ });++ expect(result.authResult.jinaApiKey).toBe('system-jina-key');+ expect(result.authResult.jinaApiUrl).toBe('https://api.jina.ai/v1/rerank');+ expect(result.authTypes).toContainEqual([+ SearchCategories.RERANKERS,+ AuthType.SYSTEM_DEFINED,+ ]);+ expect(mockResolveHostnameSSRF).toHaveBeenCalledWith(+ 'user-jina.example.com',+ undefined,+ '443',+ );+ } finally {+ if (originalApiKey == null) {+ delete process.env.JINA_API_KEY;+ } else {+ process.env.JINA_API_KEY = originalApiKey;+ }+ if (originalApiUrl == null) {+ delete process.env.JINA_API_URL;+ } else {+ process.env.JINA_API_URL = originalApiUrl;+ }+ }+ });++ it("should keep a user-provided Jina URL with the same user's key", async () => {+ const originalApiKey = process.env.JINA_API_KEY;+ const originalApiUrl = process.env.JINA_API_URL;+ delete process.env.JINA_API_KEY;+ delete process.env.JINA_API_URL;+ mockIsSSRFTarget.mockReturnValue(false);+ mockResolveHostnameSSRF.mockResolvedValue(false);+ mockLoadAuthValues.mockImplementation(({ authFields }) => {+ const result: Record<string, string> = {};+ authFields.forEach((field: string) => {+ if (field === 'JINA_API_KEY') {+ result[field] = 'user-jina-key';+ } else if (field === 'JINA_API_URL') {+ result[field] = 'https://user-jina.example.com/v1/rerank';+ } else {+ result[field] =+ field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key';+ }+ });+ return Promise.resolve(result);+ });++ try {+ const result = await loadWebSearchAuth({+ userId,+ webSearchConfig: {+ ...webSearchConfig,+ rerankerType: RerankerTypes.JINA,+ },+ loadAuthValues: mockLoadAuthValues,+ });++ expect(result.authResult.jinaApiKey).toBe('user-jina-key');+ expect(result.authResult.jinaApiUrl).toBe('https://user-jina.example.com/v1/rerank');+ expect(result.authTypes).toContainEqual([+ SearchCategories.RERANKERS,+ AuthType.USER_PROVIDED,+ ]);+ } finally {+ if (originalApiKey == null) {+ delete process.env.JINA_API_KEY;+ } else {+ process.env.JINA_API_KEY = originalApiKey;+ }+ if (originalApiUrl == null) {+ delete process.env.JINA_API_URL;+ } else {+ process.env.JINA_API_URL = originalApiUrl;+ }+ }+ });+it('should treat a whitespace-only Keenable URL env value as user-provided', async () => {const originalApiKey = process.env.KEENABLE_API_KEY;const originalApiUrl = process.env.KEENABLE_API_URL;@@ -2486,7 +2595,7 @@ describe('web.ts', () => {loadAuthValues: mockLoadAuthValues,});- expect(result.authResult.jinaApiUrl).toBeUndefined();+ expect(result.authResult.jinaApiUrl).toBe('https://api.jina.ai/v1/rerank');expect(mockIsSSRFTarget).toHaveBeenCalledWith('localhost', undefined, '8080');});@@ -2961,7 +3070,7 @@ describe('web.ts', () => {loadAuthValues: mockLoadAuthValues,});- expect(result.authResult.jinaApiUrl).toBeUndefined();+ expect(result.authResult.jinaApiUrl).toBe('https://api.jina.ai/v1/rerank');expect(result.authenticated).toBe(true);const rerankersAuth = result.authTypes.find(([c]) => c === 'rerankers')?.[1];expect(rerankersAuth).toBe(AuthType.SYSTEM_DEFINED);diff --git a/packages/api/src/web/web.ts b/packages/api/src/web/web.tsindex b4ba2949ad..bb56a7c2b8 100644--- a/packages/api/src/web/web.ts+++ b/packages/api/src/web/web.ts@@ -32,6 +32,7 @@ const USER_PROVIDED_OPT_IN_URL_KEYS = new Set<TWebSearchKeys>([const SEARCH_PROVIDER_VALUES = new Set<string>(Object.values(SearchProviders));const SCRAPER_PROVIDER_VALUES = new Set<string>(Object.values(ScraperProviders));const RERANKER_VALUES = new Set<string>(Object.values(RerankerTypes));+const DEFAULT_JINA_API_URL = 'https://api.jina.ai/v1/rerank';function isUserProvidedEnabled(field: string): boolean {return process.env[field] === AuthType.USER_PROVIDED;@@ -480,6 +481,12 @@ export async function loadWebSearchAuth({throwError,});+ const jinaApiKeyIndex = allKeys.indexOf('jinaApiKey');+ const jinaApiKeyField = allAuthFields[jinaApiKeyIndex];+ const jinaApiKeyValue = jinaApiKeyField ? authValues[jinaApiKeyField] : undefined;+ const isJinaApiKeyUserProvided =+ jinaApiKeyValue != null && process.env[jinaApiKeyField] !== jinaApiKeyValue;+let allFieldsAuthenticated = true;for (let j = 0; j < allAuthFields.length; j++) {const field = allAuthFields[j];@@ -519,6 +526,10 @@ export async function loadWebSearchAuth({}continue;}++ if (originalKey === 'jinaApiUrl' && isFieldUserProvided && !isJinaApiKeyUserProvided) {+ continue;+ }if (originalKey) {authResult[originalKey] = value;contributed = true;@@ -529,6 +540,10 @@ export async function loadWebSearchAuth({}}+ if (jinaApiKeyValue && authResult.jinaApiUrl == null) {+ authResult.jinaApiUrl = DEFAULT_JINA_API_URL;+ }+if (!allFieldsAuthenticated) {continue;}