mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-19 22:43:38 +00:00
🤫 fix: Stop Logging Action Auth Credentials to the Console (#17031)
* fix: Stop Logging Action Auth Credentials to the Console * test: Assert Saving an Action Writes No Secret to the Console
This commit is contained in:
parent
6a1a97adef
commit
de3c828d85
2 changed files with 113 additions and 1 deletions
|
|
@ -109,7 +109,6 @@ export default function ActionsInput({
|
|||
});
|
||||
|
||||
const saveAction = handleSubmit((authFormData) => {
|
||||
console.log('authFormData', authFormData);
|
||||
const currentAssistantId = assistant_id ?? '';
|
||||
if (!currentAssistantId) {
|
||||
// alert user?
|
||||
|
|
|
|||
113
e2e/specs/mock/scenarios/action-auth-console.spec.ts
Normal file
113
e2e/specs/mock/scenarios/action-auth-console.spec.ts
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { ConsoleMessage, Page } from '@playwright/test';
|
||||
import { getAccessToken, requestJson } from '../helpers';
|
||||
import { openSidebar } from './sidebar';
|
||||
|
||||
/**
|
||||
* Saving an assistant Action used to `console.log` the whole auth form, which
|
||||
* holds the plaintext API key, so the secret reached the browser console where
|
||||
* extensions, session-replay and error-monitoring SDKs can read it. This drives
|
||||
* the real Action builder with an API key and asserts the save request carries
|
||||
* the key while nothing written to the console does.
|
||||
*/
|
||||
|
||||
type CreatedAssistant = { id: string };
|
||||
|
||||
const ASSISTANT_NAME = 'E2E action auth console assistant';
|
||||
const API_KEY = 'e2e-action-secret-7f3c91d2';
|
||||
|
||||
const OPENAPI_SPEC = JSON.stringify({
|
||||
openapi: '3.0.0',
|
||||
info: { title: 'E2E Console Secret API', version: '1.0.0' },
|
||||
servers: [{ url: 'https://example.com' }],
|
||||
paths: {
|
||||
'/widgets': {
|
||||
get: { operationId: 'e2eConsoleListWidgets', responses: { '200': { description: 'ok' } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
async function createAssistant(page: Page): Promise<CreatedAssistant> {
|
||||
await page.goto('/c/new', { timeout: 10000 });
|
||||
const token = await getAccessToken(page);
|
||||
return requestJson<CreatedAssistant>(page, {
|
||||
path: '/api/assistants/v2',
|
||||
token,
|
||||
method: 'POST',
|
||||
body: { endpoint: 'assistants', model: 'gpt-4o-mini', name: ASSISTANT_NAME },
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteAssistant(page: Page, assistantId: string) {
|
||||
const token = await getAccessToken(page);
|
||||
await requestJson(page, {
|
||||
path: `/api/assistants/v2/${encodeURIComponent(assistantId)}?endpoint=assistants&model=gpt-4o-mini`,
|
||||
token,
|
||||
method: 'DELETE',
|
||||
body: { endpoint: 'assistants' },
|
||||
});
|
||||
}
|
||||
|
||||
async function openBuilder(page: Page) {
|
||||
await page.goto('/c/new?endpoint=assistants&model=gpt-4o-mini', { timeout: 10000 });
|
||||
await openSidebar(page);
|
||||
/** The mobile drawer opens on chat history; its panels are items of the Control Panel menu. */
|
||||
const controlPanel = page.getByRole('button', { name: 'Control Panel' });
|
||||
if (await controlPanel.isVisible()) {
|
||||
await controlPanel.click();
|
||||
await page.getByRole('menuitemcheckbox', { name: 'Assistant Builder' }).click();
|
||||
} else {
|
||||
await page.getByRole('button', { name: 'Assistant Builder' }).first().click();
|
||||
}
|
||||
await expect(
|
||||
page.getByTestId('select-dropdown-button').first().getByText(ASSISTANT_NAME, { exact: true }),
|
||||
).toBeVisible();
|
||||
}
|
||||
|
||||
/** Serializes every argument, so an object logged by reference is searched by its contents. */
|
||||
async function consoleText(message: ConsoleMessage): Promise<string> {
|
||||
const args = await Promise.all(message.args().map((arg) => arg.jsonValue().catch(() => '')));
|
||||
return `${message.text()} ${JSON.stringify(args)}`;
|
||||
}
|
||||
|
||||
test.describe('action auth console', () => {
|
||||
test('saving an Action with an API key writes no secret to the console @scenario:action-auth-no-console-secret', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const pending: Promise<string>[] = [];
|
||||
page.on('console', (message) => {
|
||||
pending.push(consoleText(message));
|
||||
});
|
||||
|
||||
const assistant = await createAssistant(page);
|
||||
try {
|
||||
await openBuilder(page);
|
||||
await page.getByRole('button', { name: 'Add Actions' }).click();
|
||||
|
||||
await page.locator('#schemaInput').fill(OPENAPI_SPEC);
|
||||
await expect(page.getByText('e2eConsoleListWidgets')).toBeVisible();
|
||||
|
||||
await page.getByRole('button', { name: /^None/ }).click();
|
||||
const dialog = page.getByRole('dialog', { name: 'Authentication' });
|
||||
await dialog.getByRole('radio', { name: 'API Key' }).click();
|
||||
await dialog.locator('#auth-api-key').fill(API_KEY);
|
||||
await dialog.getByRole('button', { name: 'Done' }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
|
||||
const saveRequest = page.waitForRequest(
|
||||
(request) =>
|
||||
request.method() === 'POST' &&
|
||||
request.url().includes(`/api/assistants/v2/actions/${assistant.id}`),
|
||||
);
|
||||
await page.getByRole('button', { name: 'Create', exact: true }).click();
|
||||
expect((await saveRequest).postData() ?? '').toContain(API_KEY);
|
||||
await expect(page.getByText('Successfully created or updated Action')).toBeVisible();
|
||||
|
||||
const logged = await Promise.all(pending);
|
||||
expect(logged.filter((line) => line.includes(API_KEY))).toEqual([]);
|
||||
} finally {
|
||||
await deleteAssistant(page, assistant.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue