Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: restrict the rendering of img and form tags in the logs content (#4905)

Vikrant Gupta12be6ce02070
diff --git a/frontend/src/components/Logs/ListLogView/index.tsx b/frontend/src/components/Logs/ListLogView/index.tsx
index 47b108e944..fa8a2fb608 100644
--- a/frontend/src/components/Logs/ListLogView/index.tsx
+++ b/frontend/src/components/Logs/ListLogView/index.tsx
@@ -16,6 +16,7 @@ import { useCallback, useMemo, useState } from 'react';
// interfaces
import { IField } from 'types/api/logs/fields';
import { ILog } from 'types/api/logs/log';
+import { FORBID_DOM_PURIFY_TAGS } from 'utils/app';
// components
import AddToQueryHOC, { AddToQueryHOCProps } from '../AddToQueryHOC';
@@ -50,7 +51,11 @@ function LogGeneralField({
}: LogFieldProps): JSX.Element {
const html = useMemo(
() => ({
- __html: convert.toHtml(dompurify.sanitize(fieldValue)),
+ __html: convert.toHtml(
+ dompurify.sanitize(fieldValue, {
+ FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
+ }),
+ ),
}),
[fieldValue],
);
diff --git a/frontend/src/components/Logs/RawLogView/index.tsx b/frontend/src/components/Logs/RawLogView/index.tsx
index 712b97723d..fcb8beeeec 100644
--- a/frontend/src/components/Logs/RawLogView/index.tsx
+++ b/frontend/src/components/Logs/RawLogView/index.tsx
@@ -21,6 +21,7 @@ import {
useMemo,
useState,
} from 'react';
+import { FORBID_DOM_PURIFY_TAGS } from 'utils/app';
import LogLinesActionButtons from '../LogLinesActionButtons/LogLinesActionButtons';
import LogStateIndicator from '../LogStateIndicator/LogStateIndicator';
@@ -144,7 +145,9 @@ function RawLogView({
const html = useMemo(
() => ({
- __html: convert.toHtml(dompurify.sanitize(text)),
+ __html: convert.toHtml(
+ dompurify.sanitize(text, { FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS] }),
+ ),
}),
[text],
);
diff --git a/frontend/src/components/Logs/TableView/useTableView.tsx b/frontend/src/components/Logs/TableView/useTableView.tsx
index be34e998ef..fd37132110 100644
--- a/frontend/src/components/Logs/TableView/useTableView.tsx
+++ b/frontend/src/components/Logs/TableView/useTableView.tsx
@@ -8,6 +8,7 @@ import dompurify from 'dompurify';
import { useIsDarkMode } from 'hooks/useDarkMode';
import { FlatLogData } from 'lib/logs/flatLogData';
import { useMemo } from 'react';
+import { FORBID_DOM_PURIFY_TAGS } from 'utils/app';
import LogStateIndicator from '../LogStateIndicator/LogStateIndicator';
import { getLogIndicatorTypeForTable } from '../LogStateIndicator/utils';
@@ -107,7 +108,11 @@ export const useTableView = (props: UseTableViewProps): UseTableViewResult => {
children: (
<TableBodyContent
dangerouslySetInnerHTML={{
- __html: convert.toHtml(dompurify.sanitize(field)),
+ __html: convert.toHtml(
+ dompurify.sanitize(field, {
+ FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
+ }),
+ ),
}}
linesPerRow={linesPerRow}
isDarkMode={isDarkMode}
diff --git a/frontend/src/utils/app.ts b/frontend/src/utils/app.ts
index 0ab9e6fca7..fdc95ee471 100644
--- a/frontend/src/utils/app.ts
+++ b/frontend/src/utils/app.ts
@@ -31,3 +31,6 @@ export const checkVersionState = (
const versionCore = currentVersion?.split('-')[0];
return versionCore === latestVersion;
};
+
+// list of forbidden tags to remove in dompurify
+export const FORBID_DOM_PURIFY_TAGS = ['img', 'form'];