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.

Fix: Escape HTML rendering in log body (#9413)

Aditya Singh7b1ca9a1a627
diff --git a/frontend/src/components/Logs/TableView/useTableView.tsx b/frontend/src/components/Logs/TableView/useTableView.tsx
index a355c6372a..6bd9dcff25 100644
--- a/frontend/src/components/Logs/TableView/useTableView.tsx
+++ b/frontend/src/components/Logs/TableView/useTableView.tsx
@@ -153,7 +153,9 @@ export const useTableView = (props: UseTableViewProps): UseTableViewResult => {
children: (
<TableBodyContent
dangerouslySetInnerHTML={{
- __html: getSanitizedLogBody(field as string),
+ __html: getSanitizedLogBody(field as string, {
+ shouldEscapeHtml: true,
+ }),
}}
fontSize={fontSize}
linesPerRow={linesPerRow}
diff --git a/frontend/src/container/LogDetailedView/utils.tsx b/frontend/src/container/LogDetailedView/utils.tsx
index 97c13474f9..6a29d8aa86 100644
--- a/frontend/src/container/LogDetailedView/utils.tsx
+++ b/frontend/src/container/LogDetailedView/utils.tsx
@@ -5,7 +5,7 @@ import dompurify from 'dompurify';
import { uniqueId } from 'lodash-es';
import { ILog, ILogAggregateAttributesResources } from 'types/api/logs/log';
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
-import { FORBID_DOM_PURIFY_TAGS } from 'utils/app';
+import { FORBID_DOM_PURIFY_ATTR, FORBID_DOM_PURIFY_TAGS } from 'utils/app';
import BodyTitleRenderer from './BodyTitleRenderer';
import { typeToArrayTypeMapper } from './config';
@@ -352,6 +352,7 @@ export const getSanitizedLogBody = (
return convertInstance.toHtml(
dompurify.sanitize(unescapeString(escapedText), {
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
+ FORBID_ATTR: [...FORBID_DOM_PURIFY_ATTR],
}),
);
} catch (error) {
diff --git a/frontend/src/utils/app.ts b/frontend/src/utils/app.ts
index 726c33a9d6..fbb156f24f 100644
--- a/frontend/src/utils/app.ts
+++ b/frontend/src/utils/app.ts
@@ -23,7 +23,8 @@ export const checkVersionState = (
};
// list of forbidden tags to remove in dompurify
-export const FORBID_DOM_PURIFY_TAGS = ['img', 'form'];
+export const FORBID_DOM_PURIFY_TAGS = ['img', 'form', 'style'];
+export const FORBID_DOM_PURIFY_ATTR = ['style'];
export const isFeatureKeys = (key: string): key is keyof typeof FeatureKeys =>
Object.keys(FeatureKeys).includes(key);