🔒 (logs) Remove some logs from API response to avoid sensit…
This commit is contained in:
@ -5,8 +5,9 @@ import { getSession } from '@typebot.io/bot-engine/queries/getSession'
|
|||||||
import { saveStateToDatabase } from '@typebot.io/bot-engine/saveStateToDatabase'
|
import { saveStateToDatabase } from '@typebot.io/bot-engine/saveStateToDatabase'
|
||||||
import { continueBotFlow } from '@typebot.io/bot-engine/continueBotFlow'
|
import { continueBotFlow } from '@typebot.io/bot-engine/continueBotFlow'
|
||||||
import { parseDynamicTheme } from '@typebot.io/bot-engine/parseDynamicTheme'
|
import { parseDynamicTheme } from '@typebot.io/bot-engine/parseDynamicTheme'
|
||||||
import { isDefined } from '@typebot.io/lib/utils'
|
import { isDefined, isNotDefined } from '@typebot.io/lib/utils'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
import { filterPotentiallySensitiveLogs } from '@typebot.io/bot-engine/logs/filterPotentiallySensitiveLogs'
|
||||||
|
|
||||||
export const continueChat = publicProcedure
|
export const continueChat = publicProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@ -74,12 +75,14 @@ export const continueChat = publicProcedure
|
|||||||
visitedEdges,
|
visitedEdges,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isPreview = isNotDefined(session.state.typebotsQueue[0].resultId)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
input,
|
input,
|
||||||
clientSideActions,
|
clientSideActions,
|
||||||
dynamicTheme: parseDynamicTheme(newSessionState),
|
dynamicTheme: parseDynamicTheme(newSessionState),
|
||||||
logs,
|
logs: isPreview ? logs : logs?.filter(filterPotentiallySensitiveLogs),
|
||||||
lastMessageNewFormat,
|
lastMessageNewFormat,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
import { startSession } from '@typebot.io/bot-engine/startSession'
|
import { startSession } from '@typebot.io/bot-engine/startSession'
|
||||||
import { saveStateToDatabase } from '@typebot.io/bot-engine/saveStateToDatabase'
|
import { saveStateToDatabase } from '@typebot.io/bot-engine/saveStateToDatabase'
|
||||||
import { restartSession } from '@typebot.io/bot-engine/queries/restartSession'
|
import { restartSession } from '@typebot.io/bot-engine/queries/restartSession'
|
||||||
|
import { filterPotentiallySensitiveLogs } from '@typebot.io/bot-engine/logs/filterPotentiallySensitiveLogs'
|
||||||
|
|
||||||
export const startChat = publicProcedure
|
export const startChat = publicProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@ -76,7 +77,7 @@ export const startChat = publicProcedure
|
|||||||
input,
|
input,
|
||||||
resultId,
|
resultId,
|
||||||
dynamicTheme,
|
dynamicTheme,
|
||||||
logs,
|
logs: logs?.filter(filterPotentiallySensitiveLogs),
|
||||||
clientSideActions,
|
clientSideActions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,9 @@ import prisma from '@typebot.io/lib/prisma'
|
|||||||
import { parseVariables } from '@typebot.io/variables/parseVariables'
|
import { parseVariables } from '@typebot.io/variables/parseVariables'
|
||||||
import { defaultSendEmailOptions } from '@typebot.io/schemas/features/blocks/integrations/sendEmail/constants'
|
import { defaultSendEmailOptions } from '@typebot.io/schemas/features/blocks/integrations/sendEmail/constants'
|
||||||
|
|
||||||
|
export const sendEmailSuccessDescription = 'Email successfully sent'
|
||||||
|
export const sendEmailErrorDescription = 'Email not sent'
|
||||||
|
|
||||||
export const executeSendEmailBlock = async (
|
export const executeSendEmailBlock = async (
|
||||||
state: SessionState,
|
state: SessionState,
|
||||||
block: SendEmailBlock
|
block: SendEmailBlock
|
||||||
@ -143,7 +146,7 @@ const sendEmail = async ({
|
|||||||
if (!emailBody) {
|
if (!emailBody) {
|
||||||
logs.push({
|
logs.push({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
description: 'Email not sent',
|
description: sendEmailErrorDescription,
|
||||||
details: {
|
details: {
|
||||||
error: 'No email body found',
|
error: 'No email body found',
|
||||||
transportConfig,
|
transportConfig,
|
||||||
@ -177,7 +180,7 @@ const sendEmail = async ({
|
|||||||
await transporter.sendMail(email)
|
await transporter.sendMail(email)
|
||||||
logs.push({
|
logs.push({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
description: 'Email successfully sent',
|
description: sendEmailSuccessDescription,
|
||||||
details: {
|
details: {
|
||||||
transportConfig: {
|
transportConfig: {
|
||||||
...transportConfig,
|
...transportConfig,
|
||||||
@ -189,7 +192,7 @@ const sendEmail = async ({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
logs.push({
|
logs.push({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
description: 'Email not sent',
|
description: sendEmailErrorDescription,
|
||||||
details: {
|
details: {
|
||||||
error: err instanceof Error ? err.toString() : err,
|
error: err instanceof Error ? err.toString() : err,
|
||||||
transportConfig: {
|
transportConfig: {
|
||||||
|
@ -41,6 +41,9 @@ export const longReqTimeoutWhitelist = [
|
|||||||
'https://api.anthropic.com',
|
'https://api.anthropic.com',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const webhookSuccessDescription = `Webhook successfuly executed.`
|
||||||
|
export const webhookErrorDescription = `Webhook returned an error.`
|
||||||
|
|
||||||
type Params = { disableRequestTimeout?: boolean }
|
type Params = { disableRequestTimeout?: boolean }
|
||||||
|
|
||||||
export const executeWebhookBlock = async (
|
export const executeWebhookBlock = async (
|
||||||
@ -201,7 +204,7 @@ export const executeWebhook = async (
|
|||||||
const response = await got(request.url, omit(request, 'url'))
|
const response = await got(request.url, omit(request, 'url'))
|
||||||
logs.push({
|
logs.push({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
description: `Webhook successfuly executed.`,
|
description: webhookSuccessDescription,
|
||||||
details: {
|
details: {
|
||||||
statusCode: response.statusCode,
|
statusCode: response.statusCode,
|
||||||
request,
|
request,
|
||||||
@ -224,7 +227,7 @@ export const executeWebhook = async (
|
|||||||
}
|
}
|
||||||
logs.push({
|
logs.push({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
description: `Webhook returned an error.`,
|
description: webhookErrorDescription,
|
||||||
details: {
|
details: {
|
||||||
statusCode: error.response.statusCode,
|
statusCode: error.response.statusCode,
|
||||||
request,
|
request,
|
||||||
|
20
packages/bot-engine/logs/filterPotentiallySensitiveLogs.ts
Normal file
20
packages/bot-engine/logs/filterPotentiallySensitiveLogs.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import {
|
||||||
|
sendEmailErrorDescription,
|
||||||
|
sendEmailSuccessDescription,
|
||||||
|
} from '../blocks/integrations/sendEmail/executeSendEmailBlock'
|
||||||
|
import {
|
||||||
|
webhookErrorDescription,
|
||||||
|
webhookSuccessDescription,
|
||||||
|
} from '../blocks/integrations/webhook/executeWebhookBlock'
|
||||||
|
|
||||||
|
export const filterPotentiallySensitiveLogs = (log: {
|
||||||
|
status: string
|
||||||
|
description: string
|
||||||
|
details?: unknown
|
||||||
|
}) =>
|
||||||
|
![
|
||||||
|
webhookErrorDescription,
|
||||||
|
webhookSuccessDescription,
|
||||||
|
sendEmailErrorDescription,
|
||||||
|
sendEmailSuccessDescription,
|
||||||
|
].includes(log.description)
|
Reference in New Issue
Block a user