From de3c828d850ff067cfbfd467ba8c8ebe4ddf431d Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Mon, 12 Oct 2026 22:35:34 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=AB=20fix:=20Stop=20Logging=20Action?= =?UTF-8?q?=20Auth=20Credentials=20to=20the=20Console=20(#17031)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Stop Logging Action Auth Credentials to the Console * test: Assert Saving an Action Writes No Secret to the Console --- .../SidePanel/Builder/ActionsInput.tsx | 1 - .../scenarios/action-auth-console.spec.ts | 113 ++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 e2e/specs/mock/scenarios/action-auth-console.spec.ts diff --git a/client/src/components/SidePanel/Builder/ActionsInput.tsx b/client/src/components/SidePanel/Builder/ActionsInput.tsx index c0279cbbaa..b19f2ee347 100644 --- a/client/src/components/SidePanel/Builder/ActionsInput.tsx +++ b/client/src/components/SidePanel/Builder/ActionsInput.tsx @@ -109,7 +109,6 @@ export default function ActionsInput({ }); const saveAction = handleSubmit((authFormData) => { - console.log('authFormData', authFormData); const currentAssistantId = assistant_id ?? ''; if (!currentAssistantId) { // alert user? diff --git a/e2e/specs/mock/scenarios/action-auth-console.spec.ts b/e2e/specs/mock/scenarios/action-auth-console.spec.ts new file mode 100644 index 0000000000..63f05f0213 --- /dev/null +++ b/e2e/specs/mock/scenarios/action-auth-console.spec.ts @@ -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 { + await page.goto('/c/new', { timeout: 10000 }); + const token = await getAccessToken(page); + return requestJson(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 { + 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[] = []; + 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); + } + }); +});