mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-23 16:34:27 +00:00
🚷 fix: Isolate Jina Credential Provenance (#16134)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
This commit is contained in:
parent
50d46a38a5
commit
7b645f4eaf
2 changed files with 126 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue