@cccsaurora/howler-ui 3.2.0-dev.1911.1 → 3.2.0-dev.1925.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/elements/display/Markdown.d.ts +1 -0
- package/components/elements/display/Markdown.js +7 -3
- package/components/elements/display/Markdown.test.d.ts +1 -0
- package/components/elements/display/Markdown.test.js +67 -1
- package/components/elements/hit/HitNotebooks.test.js +3 -1
- package/components/routes/action/shared/OperationStep.js +9 -6
- package/components/routes/action/shared/OperationStep.test.js +19 -0
- package/components/routes/hits/view/LeadRenderer.js +9 -1
- package/components/routes/hits/view/LeadRenderer.test.d.ts +1 -0
- package/components/routes/hits/view/LeadRenderer.test.js +30 -0
- package/locales/en/translation.json +2 -0
- package/locales/fr/translation.json +2 -0
- package/models/ActionTypes.d.ts +1 -0
- package/package.json +1 -1
|
@@ -34,10 +34,11 @@ const customComponents = (type, children) => {
|
|
|
34
34
|
return _jsx("code", { children: child });
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
const Markdown = ({ md, components = {}, disableLinks = false }) => {
|
|
37
|
+
const Markdown = ({ md, components = {}, disableLinks = false, untrusted = false }) => {
|
|
38
38
|
const theme = useTheme();
|
|
39
39
|
const { isDark } = useAppTheme();
|
|
40
40
|
const { t } = useTranslation();
|
|
41
|
+
const transformUrl = (value) => untrusted && !(value.startsWith('#') || (value.startsWith('/') && !value.startsWith('//'))) ? '' : value;
|
|
41
42
|
useEffect(() => {
|
|
42
43
|
mermaid.initialize({
|
|
43
44
|
startOnLoad: false,
|
|
@@ -58,9 +59,9 @@ const Markdown = ({ md, components = {}, disableLinks = false }) => {
|
|
|
58
59
|
useEffect(() => {
|
|
59
60
|
void mermaid.run();
|
|
60
61
|
});
|
|
61
|
-
return (_jsx(ReactMarkdown, { remarkPlugins: [remarkGfm, codeTabs], rehypePlugins: [rehypeRaw], urlTransform:
|
|
62
|
+
return (_jsx(ReactMarkdown, { remarkPlugins: untrusted ? [remarkGfm] : [remarkGfm, codeTabs], rehypePlugins: untrusted ? [] : [rehypeRaw], urlTransform: transformUrl, components: {
|
|
62
63
|
code({ node, className, children, ...props }) {
|
|
63
|
-
if (!node) {
|
|
64
|
+
if (untrusted || !node) {
|
|
64
65
|
return (_jsx("code", { className: className, ...props, children: children }));
|
|
65
66
|
}
|
|
66
67
|
if (node.children?.length === 1 && node.children[0].type === 'text') {
|
|
@@ -103,6 +104,9 @@ const Markdown = ({ md, components = {}, disableLinks = false }) => {
|
|
|
103
104
|
},
|
|
104
105
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
106
|
img({ node, ...props }) {
|
|
107
|
+
if (untrusted) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
106
110
|
// eslint-disable-next-line jsx-a11y/alt-text
|
|
107
111
|
return _jsx(Image, { ...props, style: { ...props.style, maxWidth: '75%' } });
|
|
108
112
|
},
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** @vitest-environment-options {"url": "https://howler.test/hits/hit-1"} */
|
|
2
3
|
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { MemoryRouter } from 'react-router';
|
|
3
5
|
import { describe, expect, it, vi } from 'vitest';
|
|
4
6
|
import Markdown from './Markdown';
|
|
5
|
-
vi.mock('
|
|
7
|
+
vi.mock('@tui/core', () => ({
|
|
6
8
|
useAppTheme: () => ({ isDark: false })
|
|
7
9
|
}));
|
|
8
10
|
vi.mock('mermaid', () => ({
|
|
@@ -22,4 +24,68 @@ describe('Markdown', () => {
|
|
|
22
24
|
render(_jsx(Markdown, { md: '```json[hideSearch=true]\n{"value":"visible"}\n```' }));
|
|
23
25
|
expect(screen.getByTestId('json-viewer')).toHaveTextContent(JSON.stringify({ data: { value: 'visible' }, hideSearch: true }));
|
|
24
26
|
});
|
|
27
|
+
it('renders untrusted markdown without raw HTML, images, or external links', () => {
|
|
28
|
+
const md = [
|
|
29
|
+
'<img src="https://attacker.invalid/raw" onerror="alert(1)" />',
|
|
30
|
+
'',
|
|
31
|
+
'[external](https://attacker.invalid/page)',
|
|
32
|
+
'[protocol relative](//evil.com)'
|
|
33
|
+
].join('\n\n');
|
|
34
|
+
const { container } = render(_jsx(MemoryRouter, { children: _jsx(Markdown, { untrusted: true, disableLinks: true, md: md }) }));
|
|
35
|
+
expect(container.querySelector('img')).toBeNull();
|
|
36
|
+
expect(container.querySelector('[onerror]')).toBeNull();
|
|
37
|
+
expect(container.querySelector('a[href*="attacker.invalid"]')).toBeNull();
|
|
38
|
+
expect(container.querySelector('a[href^="//"]')).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
it.each([
|
|
41
|
+
{
|
|
42
|
+
name: 'a raw backslash destination',
|
|
43
|
+
md: String.raw `[test](/\attacker.invalid/path)`,
|
|
44
|
+
expectedHref: '/%5Cattacker.invalid/path'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'an angle-bracket backslash destination',
|
|
48
|
+
md: String.raw `[test](</\attacker.invalid/path>)`,
|
|
49
|
+
expectedHref: '/%5Cattacker.invalid/path'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'a percent-encoded backslash destination',
|
|
53
|
+
md: '[test](/%5Cattacker.invalid/path)',
|
|
54
|
+
expectedHref: '/%5Cattacker.invalid/path'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'an angle-bracket tab destination',
|
|
58
|
+
md: '[test](</\t/attacker.invalid/path>)',
|
|
59
|
+
expectedHref: '/%09/attacker.invalid/path'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'a percent-encoded tab destination',
|
|
63
|
+
md: '[test](/%09/attacker.invalid/path)',
|
|
64
|
+
expectedHref: '/%09/attacker.invalid/path'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'a root-relative hit link',
|
|
68
|
+
md: '[test](/hits/hit-1)',
|
|
69
|
+
expectedHref: '/hits/hit-1'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'a fragment link',
|
|
73
|
+
md: '[test](#summary)',
|
|
74
|
+
expectedHref: '#summary'
|
|
75
|
+
}
|
|
76
|
+
])('keeps $name on the application origin in untrusted markdown with links disabled', ({ md, expectedHref }) => {
|
|
77
|
+
render(_jsx(MemoryRouter, { initialEntries: ['/hits/hit-1'], children: _jsx(Markdown, { untrusted: true, disableLinks: true, md: md }) }));
|
|
78
|
+
const link = screen.getByRole('link', { name: 'test' });
|
|
79
|
+
expect(link).toHaveAttribute('href', expectedHref);
|
|
80
|
+
expect(window.location.origin).toBe('https://howler.test');
|
|
81
|
+
expect(new URL(link.href).origin).toBe(window.location.origin);
|
|
82
|
+
});
|
|
83
|
+
it('removes protocol-relative destinations in untrusted markdown with links disabled', () => {
|
|
84
|
+
render(_jsx(MemoryRouter, { children: _jsx(Markdown, { untrusted: true, disableLinks: true, md: "[protocol relative](//attacker.invalid/path)" }) }));
|
|
85
|
+
const link = screen.getByText('protocol relative');
|
|
86
|
+
expect(screen.queryByRole('link', { name: 'protocol relative' })).not.toBeInTheDocument();
|
|
87
|
+
expect(link).toHaveAttribute('href', '');
|
|
88
|
+
expect(window.location.origin).toBe('https://howler.test');
|
|
89
|
+
expect(new URL(link.href).origin).toBe(window.location.origin);
|
|
90
|
+
});
|
|
25
91
|
});
|
|
@@ -112,10 +112,11 @@ describe('HitNotebooks', () => {
|
|
|
112
112
|
link: 'link-a',
|
|
113
113
|
hit: { howler: { id: 'hit-1' } }
|
|
114
114
|
}));
|
|
115
|
+
await waitFor(() => expect(screen.getByText('hit.notebook.goTo')).toBeEnabled());
|
|
115
116
|
fireEvent.click(screen.getByText('hit.notebook.goTo'));
|
|
116
117
|
await waitFor(() => expect(globalThis.fetch).toHaveBeenCalledWith('https://nb.example/api/contents/Loaded Notebook - hit-1.ipynb', expect.any(Object)));
|
|
117
118
|
await waitFor(() => expect(globalThis.fetch).toHaveBeenCalledWith('https://nb.example/post/Loaded Notebook - hit-1.ipynb', expect.objectContaining({ method: 'post' })));
|
|
118
|
-
expect(globalThis.open).toHaveBeenCalledWith('https://nb.example/lab/tree/Loaded Notebook - hit-1.ipynb', '_blank');
|
|
119
|
+
await waitFor(() => expect(globalThis.open).toHaveBeenCalledWith('https://nb.example/lab/tree/Loaded Notebook - hit-1.ipynb', '_blank'));
|
|
119
120
|
});
|
|
120
121
|
it('confirms overwrite for existing notebooks and can hide itself when notebooks are disabled', async () => {
|
|
121
122
|
configValue = { configuration: { features: { notebook: false } } };
|
|
@@ -131,6 +132,7 @@ describe('HitNotebooks', () => {
|
|
|
131
132
|
rerender(_jsx(HitNotebooks, { analytic: { notebooks: [{ name: 'Notebook A', value: 'link-a' }] }, selectedNotebook: "Notebook A" }));
|
|
132
133
|
fireEvent.click(screen.getByRole('button', { name: /hit\.notebook\.tooltip/i }));
|
|
133
134
|
await waitFor(() => expect(mockDispatchApi).toHaveBeenCalledTimes(2));
|
|
135
|
+
await waitFor(() => expect(screen.getByText('hit.notebook.goTo')).toBeEnabled());
|
|
134
136
|
fireEvent.click(screen.getByText('hit.notebook.goTo'));
|
|
135
137
|
await waitFor(() => expect(mockShowModal).toHaveBeenCalled());
|
|
136
138
|
await waitFor(() => expect(globalThis.fetch).toHaveBeenCalledWith('https://nb.example/post/Notebook A.ipynb', expect.objectContaining({ method: 'post' })));
|
|
@@ -24,7 +24,7 @@ const OperationStep = ({ step, query, values, setValues, readonly, loading }) =>
|
|
|
24
24
|
: errorResponse || warnResponse
|
|
25
25
|
? 'success'
|
|
26
26
|
: null;
|
|
27
|
-
const args = useMemo(() => getArgsByContext(step.args, values), [step.args, values]);
|
|
27
|
+
const args = useMemo(() => [...getArgsByContext(step.args, values), ...(step.optional_args ?? [])], [step.args, step.optional_args, values]);
|
|
28
28
|
const parsedValues = useMemo(() => JSON.parse(values), [values]);
|
|
29
29
|
/**
|
|
30
30
|
* Substitute the current user values into a given validation query
|
|
@@ -33,11 +33,14 @@ const OperationStep = ({ step, query, values, setValues, readonly, loading }) =>
|
|
|
33
33
|
/**
|
|
34
34
|
* Get a well formatted label based on the argument key
|
|
35
35
|
*/
|
|
36
|
-
const getLabel = useCallback((argId) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
const getLabel = useCallback((argId) => {
|
|
37
|
+
const label = argId
|
|
38
|
+
.replace(/[-_]/g, ' ')
|
|
39
|
+
.split(' ')
|
|
40
|
+
.map(part => capitalize(part))
|
|
41
|
+
.join(' ');
|
|
42
|
+
return step.optional_args?.includes(argId) ? `${label} (${t('route.actions.optional')})` : label;
|
|
43
|
+
}, [step.optional_args, t]);
|
|
41
44
|
/**
|
|
42
45
|
* Run validation on the data provided for this step of the operation
|
|
43
46
|
*/
|
|
@@ -81,4 +81,23 @@ describe('OperationStep', () => {
|
|
|
81
81
|
expect(screen.getByLabelText('Name')).toBeDisabled();
|
|
82
82
|
expect(mockDispatchApi).not.toHaveBeenCalled();
|
|
83
83
|
});
|
|
84
|
+
it.each([false, true])('renders an editable optional prompt (autocomplete: %s)', async (autocomplete) => {
|
|
85
|
+
const setValues = vi.fn();
|
|
86
|
+
mockDispatchApi.mockResolvedValueOnce({ total: 0 });
|
|
87
|
+
render(_jsx(OperationStep, { query: "status:open", values: "{}", setValues: setValues, step: {
|
|
88
|
+
args: {},
|
|
89
|
+
optional_args: ['prompt'],
|
|
90
|
+
options: autocomplete ? { prompt: ['chosen'] } : {},
|
|
91
|
+
validation: { warn: { query: 'warn-query' } }
|
|
92
|
+
} }));
|
|
93
|
+
await waitFor(() => expect(screen.getByText('route.actions.alert.success')).toBeInTheDocument());
|
|
94
|
+
if (autocomplete) {
|
|
95
|
+
fireEvent.click(screen.getByText('choose'));
|
|
96
|
+
expect(setValues).toHaveBeenCalledWith('{"prompt":"chosen"}');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
fireEvent.change(screen.getByLabelText('Prompt (route.actions.optional)'), { target: { value: 'Focus' } });
|
|
100
|
+
expect(setValues).toHaveBeenCalledWith('{"prompt":"Focus"}');
|
|
101
|
+
}
|
|
102
|
+
});
|
|
84
103
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Divider, Stack, Typography } from '@mui/material';
|
|
3
3
|
import HandlebarsMarkdown from '@cccsaurora/howler-ui/components/elements/display/HandlebarsMarkdown';
|
|
4
|
+
import Markdown from '@cccsaurora/howler-ui/components/elements/display/Markdown';
|
|
4
5
|
import { memo } from 'react';
|
|
5
6
|
import { useTranslation } from 'react-i18next';
|
|
6
7
|
import { usePluginStore } from 'react-pluggable';
|
|
@@ -8,9 +9,16 @@ const LeadRenderer = ({ lead, hit }) => {
|
|
|
8
9
|
const { t } = useTranslation();
|
|
9
10
|
const pluginStore = usePluginStore();
|
|
10
11
|
if (lead.format === 'markdown') {
|
|
12
|
+
let isAiTriageLead = false;
|
|
13
|
+
try {
|
|
14
|
+
isAiTriageLead = JSON.parse(lead.metadata ?? '{}').owner === 'howler.ai_triage';
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Invalid metadata is treated as a regular, trusted lead.
|
|
18
|
+
}
|
|
11
19
|
return (_jsx(Box, { sx: {
|
|
12
20
|
mt: -2
|
|
13
|
-
}, children: _jsx(HandlebarsMarkdown, { disableLinks: true, md: lead.content, object: hit ?? lead }) }));
|
|
21
|
+
}, children: isAiTriageLead ? (_jsx(Markdown, { md: lead.content, disableLinks: true, untrusted: true })) : (_jsx(HandlebarsMarkdown, { disableLinks: true, md: lead.content, object: hit ?? lead })) }));
|
|
14
22
|
}
|
|
15
23
|
const pluginLead = pluginStore.executeFunction(`lead.${lead.format}`, lead.content, lead.metadata, hit);
|
|
16
24
|
if (pluginLead) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/// <reference types="vitest" />
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
vi.mock('components/elements/display/Markdown', () => ({
|
|
6
|
+
default: ({ untrusted }) => _jsx("div", { id: "markdown", children: String(!!untrusted) })
|
|
7
|
+
}));
|
|
8
|
+
vi.mock('components/elements/display/HandlebarsMarkdown', () => ({
|
|
9
|
+
default: ({ object }) => _jsx("div", { id: "handlebars", children: JSON.stringify(object) })
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('react-i18next', () => ({
|
|
12
|
+
useTranslation: () => ({ t: (key) => key })
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('react-pluggable', () => ({
|
|
15
|
+
usePluginStore: () => ({ executeFunction: vi.fn() })
|
|
16
|
+
}));
|
|
17
|
+
import LeadRenderer from './LeadRenderer';
|
|
18
|
+
const renderLead = (metadata) => render(_jsx(LeadRenderer, { lead: { format: 'markdown', content: 'body', metadata }, hit: { user: { email: 'a@b.c' } } }));
|
|
19
|
+
describe('LeadRenderer', () => {
|
|
20
|
+
it('renders AI triage leads as untrusted markdown, never as a template with hit context', () => {
|
|
21
|
+
renderLead(JSON.stringify({ owner: 'howler.ai_triage' }));
|
|
22
|
+
expect(screen.getByTestId('markdown')).toHaveTextContent('true');
|
|
23
|
+
expect(screen.queryByTestId('handlebars')).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
it.each([undefined, '{}', JSON.stringify({ owner: 'another.plugin' }), 'not-json'])('keeps other leads (metadata: %s) as templates evaluated against the hit', metadata => {
|
|
26
|
+
renderLead(metadata);
|
|
27
|
+
expect(screen.getByTestId('handlebars')).toHaveTextContent('a@b.c');
|
|
28
|
+
expect(screen.queryByTestId('markdown')).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -445,6 +445,7 @@
|
|
|
445
445
|
"open": "Open",
|
|
446
446
|
"operations.add_label": "Add Label",
|
|
447
447
|
"operations.add_to_case": "Add to Case",
|
|
448
|
+
"operations.ai_triage": "AI Triage",
|
|
448
449
|
"operations.change_field": "Change Field",
|
|
449
450
|
"operations.demote": "Demote Hit",
|
|
450
451
|
"operations.prioritization": "Change Prioritization",
|
|
@@ -679,6 +680,7 @@
|
|
|
679
680
|
"route.actions.name": "Action Name",
|
|
680
681
|
"route.actions.open": "Open Query",
|
|
681
682
|
"route.actions.operation.add": "Add New Operation",
|
|
683
|
+
"route.actions.optional": "optional",
|
|
682
684
|
"route.actions.query.empty": "Query cannot be empty.",
|
|
683
685
|
"route.actions.report": "Action Report",
|
|
684
686
|
"route.actions.restart": "Restart",
|
|
@@ -445,6 +445,7 @@
|
|
|
445
445
|
"open": "Ouvert",
|
|
446
446
|
"operations.add_label": "Ajouter un label",
|
|
447
447
|
"operations.add_to_case": "Ajouter au cas",
|
|
448
|
+
"operations.ai_triage": "Triage IA",
|
|
448
449
|
"operations.change_field": "Modifier un champs",
|
|
449
450
|
"operations.demote": "Rétrograder un hit",
|
|
450
451
|
"operations.prioritization": "Modifier l'ordre de priorité",
|
|
@@ -679,6 +680,7 @@
|
|
|
679
680
|
"route.actions.name": "Nom de l'action",
|
|
680
681
|
"route.actions.open": "Ouvrir la requête",
|
|
681
682
|
"route.actions.operation.add": "Ajouter une nouvelle opération",
|
|
683
|
+
"route.actions.optional": "facultatif",
|
|
682
684
|
"route.actions.query.empty": "La requête ne peut pas être vide.",
|
|
683
685
|
"route.actions.report": "Rapport d'action",
|
|
684
686
|
"route.actions.restart": "Redémarrer",
|
package/models/ActionTypes.d.ts
CHANGED
package/package.json
CHANGED