Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

AI fixes

Blue Mouse79efbc26f0da
diff --git a/backend/apps/cloud/src/ai/ai-chat.service.ts b/backend/apps/cloud/src/ai/ai-chat.service.ts
index 37a29e4c1..219771563 100644
--- a/backend/apps/cloud/src/ai/ai-chat.service.ts
+++ b/backend/apps/cloud/src/ai/ai-chat.service.ts
@@ -84,9 +84,10 @@ export class AiChatService {
if (!chat) return null
if (data.messages) {
+ const previousMessages = chat.messages
chat.messages = data.messages
// Update name if not manually set and we have a new first user message
- if (!chat.name || chat.name === this.generateChatName(chat.messages)) {
+ if (!chat.name || chat.name === this.generateChatName(previousMessages)) {
chat.name = this.generateChatName(data.messages)
}
}
diff --git a/backend/apps/cloud/src/ai/ai.service.ts b/backend/apps/cloud/src/ai/ai.service.ts
index 75a862595..a2eedf407 100644
--- a/backend/apps/cloud/src/ai/ai.service.ts
+++ b/backend/apps/cloud/src/ai/ai.service.ts
@@ -20,6 +20,23 @@ import { TimeBucketType } from '../analytics/dto/getData.dto'
const OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1'
+// Allowed column names for filters to prevent SQL injection
+const ALLOWED_FILTER_COLUMNS = new Set([
+ 'pg',
+ 'cc',
+ 'rg',
+ 'ct',
+ 'br',
+ 'os',
+ 'dv',
+ 'ref',
+ 'so',
+ 'me',
+ 'ca',
+ 'lc',
+ 'host',
+])
+
/**
* Custom fetch wrapper that fixes malformed tool_calls in streaming responses.
* Some OpenAI-compatible providers (like OpenRouter with certain models) return
@@ -1044,6 +1061,11 @@ Available columns for filters:
const params: Record<string, string> = {}
filters.forEach((f, index) => {
+ // Validate column name against allowlist to prevent SQL injection
+ if (!ALLOWED_FILTER_COLUMNS.has(f.column)) {
+ return // Skip invalid columns
+ }
+
const paramName = `filter_${index}`
params[paramName] = f.filter
const operator = f.isExclusive ? '!=' : '='
diff --git a/web/app/api/index.ts b/web/app/api/index.ts
index 36cdd9a0f..8de3d95f7 100644
--- a/web/app/api/index.ts
+++ b/web/app/api/index.ts
@@ -1921,7 +1921,6 @@ export const getRecentAIChats = async (pid: string, limit: number = 5): Promise<
return api
.get(`ai/${pid}/chats`, {
params: { limit },
- headers: { Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : '' },
})
.then((response): AIChatSummary[] => response.data)
.catch((error) => {
@@ -1937,7 +1936,6 @@ export const getAllAIChats = async (
return api
.get(`ai/${pid}/chats/all`, {
params: { skip, take },
- headers: { Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : '' },
})
.then((response): { chats: AIChatSummary[]; total: number } => response.data)
.catch((error) => {
@@ -1947,9 +1945,7 @@ export const getAllAIChats = async (
export const getAIChat = async (pid: string, chatId: string): Promise<AIChat> => {
return api
- .get(`ai/${pid}/chats/${chatId}`, {
- headers: { Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : '' },
- })
+ .get(`ai/${pid}/chats/${chatId}`)
.then((response): AIChat => response.data)
.catch((error) => {
throw _isEmpty(error.response?.data?.message) ? error.response?.data : error.response?.data?.message
@@ -1975,9 +1971,7 @@ export const updateAIChat = async (
data: { messages?: AIChatMessage[]; name?: string },
): Promise<AIChat> => {
return api
- .post(`ai/${pid}/chats/${chatId}`, data, {
- headers: { Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : '' },
- })
+ .post(`ai/${pid}/chats/${chatId}`, data)
.then((response): AIChat => response.data)
.catch((error) => {
throw _isEmpty(error.response?.data?.message) ? error.response?.data : error.response?.data?.message
@@ -1986,9 +1980,7 @@ export const updateAIChat = async (
export const deleteAIChat = async (pid: string, chatId: string): Promise<{ success: boolean }> => {
return api
- .delete(`ai/${pid}/chats/${chatId}`, {
- headers: { Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : '' },
- })
+ .delete(`ai/${pid}/chats/${chatId}`)
.then((response): { success: boolean } => response.data)
.catch((error) => {
throw _isEmpty(error.response?.data?.message) ? error.response?.data : error.response?.data?.message
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 5770acea3..660b5cea5 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -1471,7 +1471,7 @@ const ViewProjectContent = () => {
label: string
icon: any
}[] = useMemo(() => {
- const selfhostedOnly = [
+ const baseTabs = [
{
id: PROJECT_TABS.traffic,
label: t('dashboard.traffic'),
@@ -1507,11 +1507,6 @@ const ViewProjectContent = () => {
label: t('dashboard.goals'),
icon: TargetIcon,
},
- {
- id: PROJECT_TABS.ai,
- label: t('dashboard.askAi'),
- icon: SparklesIcon,
- },
]
const adminTabs = allowedToManage
@@ -1525,11 +1520,16 @@ const ViewProjectContent = () => {
: []
if (isSelfhosted) {
- return [...selfhostedOnly, ...adminTabs]
+ return [...baseTabs, ...adminTabs]
}
const newTabs = [
- ...selfhostedOnly,
+ ...baseTabs,
+ {
+ id: PROJECT_TABS.ai,
+ label: t('dashboard.askAi'),
+ icon: SparklesIcon,
+ },
{
id: PROJECT_TABS.alerts,
label: t('dashboard.alerts'),