mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 16:38:59 +08:00
fix: fix html escape and json string parsing in qb (#8039)
Co-authored-by: Aditya Singh <adityasingh@Adityas-MacBook-Pro.local>
This commit is contained in:
parent
51d3ca16f7
commit
b6180f6957
@ -16,6 +16,7 @@ import JSONView from 'container/LogDetailedView/JsonView';
|
|||||||
import Overview from 'container/LogDetailedView/Overview';
|
import Overview from 'container/LogDetailedView/Overview';
|
||||||
import {
|
import {
|
||||||
aggregateAttributesResourcesToString,
|
aggregateAttributesResourcesToString,
|
||||||
|
escapeHtml,
|
||||||
removeEscapeCharacters,
|
removeEscapeCharacters,
|
||||||
unescapeString,
|
unescapeString,
|
||||||
} from 'container/LogDetailedView/utils';
|
} from 'container/LogDetailedView/utils';
|
||||||
@ -118,7 +119,7 @@ function LogDetail({
|
|||||||
const htmlBody = useMemo(
|
const htmlBody = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
__html: convert.toHtml(
|
__html: convert.toHtml(
|
||||||
dompurify.sanitize(unescapeString(log?.body || ''), {
|
dompurify.sanitize(unescapeString(escapeHtml(log?.body || '')), {
|
||||||
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
@ -7,7 +7,7 @@ import cx from 'classnames';
|
|||||||
import LogDetail from 'components/LogDetail';
|
import LogDetail from 'components/LogDetail';
|
||||||
import { VIEW_TYPES } from 'components/LogDetail/constants';
|
import { VIEW_TYPES } from 'components/LogDetail/constants';
|
||||||
import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
|
import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
|
||||||
import { unescapeString } from 'container/LogDetailedView/utils';
|
import { escapeHtml, unescapeString } from 'container/LogDetailedView/utils';
|
||||||
import { FontSize } from 'container/OptionsMenu/types';
|
import { FontSize } from 'container/OptionsMenu/types';
|
||||||
import dompurify from 'dompurify';
|
import dompurify from 'dompurify';
|
||||||
import { useActiveLog } from 'hooks/logs/useActiveLog';
|
import { useActiveLog } from 'hooks/logs/useActiveLog';
|
||||||
@ -58,7 +58,7 @@ function LogGeneralField({
|
|||||||
const html = useMemo(
|
const html = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
__html: convert.toHtml(
|
__html: convert.toHtml(
|
||||||
dompurify.sanitize(unescapeString(fieldValue), {
|
dompurify.sanitize(unescapeString(escapeHtml(fieldValue)), {
|
||||||
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
@ -5,7 +5,7 @@ import { DrawerProps } from 'antd';
|
|||||||
import LogDetail from 'components/LogDetail';
|
import LogDetail from 'components/LogDetail';
|
||||||
import { VIEW_TYPES, VIEWS } from 'components/LogDetail/constants';
|
import { VIEW_TYPES, VIEWS } from 'components/LogDetail/constants';
|
||||||
import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
|
import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
|
||||||
import { unescapeString } from 'container/LogDetailedView/utils';
|
import { escapeHtml, unescapeString } from 'container/LogDetailedView/utils';
|
||||||
import LogsExplorerContext from 'container/LogsExplorerContext';
|
import LogsExplorerContext from 'container/LogsExplorerContext';
|
||||||
import dompurify from 'dompurify';
|
import dompurify from 'dompurify';
|
||||||
import { useActiveLog } from 'hooks/logs/useActiveLog';
|
import { useActiveLog } from 'hooks/logs/useActiveLog';
|
||||||
@ -177,7 +177,7 @@ function RawLogView({
|
|||||||
const html = useMemo(
|
const html = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
__html: convert.toHtml(
|
__html: convert.toHtml(
|
||||||
dompurify.sanitize(unescapeString(text), {
|
dompurify.sanitize(unescapeString(escapeHtml(text)), {
|
||||||
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
@ -21,8 +21,10 @@ import { FORBID_DOM_PURIFY_TAGS } from 'utils/app';
|
|||||||
|
|
||||||
import { DataType } from '../TableView';
|
import { DataType } from '../TableView';
|
||||||
import {
|
import {
|
||||||
|
escapeHtml,
|
||||||
filterKeyForField,
|
filterKeyForField,
|
||||||
jsonToDataNodes,
|
jsonToDataNodes,
|
||||||
|
parseFieldValue,
|
||||||
recursiveParseJSON,
|
recursiveParseJSON,
|
||||||
removeEscapeCharacters,
|
removeEscapeCharacters,
|
||||||
unescapeString,
|
unescapeString,
|
||||||
@ -85,7 +87,7 @@ export function TableViewActions(
|
|||||||
record.field === 'body'
|
record.field === 'body'
|
||||||
? {
|
? {
|
||||||
__html: convert.toHtml(
|
__html: convert.toHtml(
|
||||||
dompurify.sanitize(unescapeString(record.value), {
|
dompurify.sanitize(unescapeString(escapeHtml(record.value)), {
|
||||||
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
FORBID_TAGS: [...FORBID_DOM_PURIFY_TAGS],
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@ -155,7 +157,11 @@ export function TableViewActions(
|
|||||||
<ArrowDownToDot size={14} style={{ transform: 'rotate(90deg)' }} />
|
<ArrowDownToDot size={14} style={{ transform: 'rotate(90deg)' }} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onClick={onClickHandler(OPERATORS['='], fieldFilterKey, fieldData.value)}
|
onClick={onClickHandler(
|
||||||
|
OPERATORS['='],
|
||||||
|
fieldFilterKey,
|
||||||
|
parseFieldValue(fieldData.value),
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="Filter out value">
|
<Tooltip title="Filter out value">
|
||||||
@ -171,7 +177,7 @@ export function TableViewActions(
|
|||||||
onClick={onClickHandler(
|
onClick={onClickHandler(
|
||||||
OPERATORS['!='],
|
OPERATORS['!='],
|
||||||
fieldFilterKey,
|
fieldFilterKey,
|
||||||
fieldData.value,
|
parseFieldValue(fieldData.value),
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
@ -259,6 +259,24 @@ export const getDataTypes = (value: unknown): DataTypes => {
|
|||||||
return determineType(value);
|
return determineType(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// prevent html rendering in the value
|
||||||
|
export const escapeHtml = (unsafe: string): string =>
|
||||||
|
unsafe
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
|
||||||
|
// parse field value to remove escaping characters
|
||||||
|
export const parseFieldValue = (value: string): string => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(value);
|
||||||
|
} catch (error) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// now we do not want to render colors everywhere like in tooltip and monaco editor hence we remove such codes to make
|
// now we do not want to render colors everywhere like in tooltip and monaco editor hence we remove such codes to make
|
||||||
// the log line readable
|
// the log line readable
|
||||||
export const removeEscapeCharacters = (str: string): string =>
|
export const removeEscapeCharacters = (str: string): string =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user