@cccsaurora/howler-ui 3.2.0-dev.1879.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.
@@ -5,6 +5,7 @@ export interface MarkdownProps {
5
5
  [index: string]: ReactElement;
6
6
  };
7
7
  disableLinks?: boolean;
8
+ untrusted?: boolean;
8
9
  }
9
10
  declare const _default: import("react").NamedExoticComponent<MarkdownProps>;
10
11
  export default _default;
@@ -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: (value) => value, components: {
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 +1,2 @@
1
+ /** @vitest-environment-options {"url": "https://howler.test/hits/hit-1"} */
1
2
  export {};
@@ -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('commons/components/app/hooks', () => ({
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
+ '![remote](https://attacker.invalid/image)',
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) => (argId ?? '')
37
- .replace(/[-_]/g, ' ')
38
- .split(' ')
39
- .map(part => capitalize(part))
40
- .join(' '), []);
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",
@@ -4,6 +4,7 @@ export interface ActionOperationStep {
4
4
  args: {
5
5
  [index: string]: string[];
6
6
  };
7
+ optional_args?: string[];
7
8
  options: {
8
9
  [index: string]: string[] | { [index: string]: string[] };
9
10
  };
package/package.json CHANGED
@@ -24,7 +24,7 @@
24
24
  "@jsonforms/core": "^3.8.0",
25
25
  "@jsonforms/material-renderers": "^3.8.0",
26
26
  "@jsonforms/react": "^3.8.0",
27
- "@microlink/react-json-view": "^1.31.48",
27
+ "@microlink/react-json-view": "^1.31.50",
28
28
  "@monaco-editor/react": "^4.7.0",
29
29
  "@tui/a11y": "file:./tui/a11y-4.0.12.tgz",
30
30
  "@tui/apps": "file:./tui/apps-4.0.12.tgz",
@@ -32,13 +32,13 @@
32
32
  "@tui/drawer": "file:./tui/drawer-4.0.12.tgz",
33
33
  "ajv": "^8.20.0",
34
34
  "ajv-i18n": "^4.2.0",
35
- "axios": "^1.21.0",
35
+ "axios": "^1.21.1",
36
36
  "axios-retry": "^3.9.1",
37
37
  "chart.js": "^4.6.1",
38
38
  "chartjs-adapter-dayjs-4": "^1.0.4",
39
39
  "chartjs-plugin-zoom": "^2.2.0",
40
40
  "dayjs": "^1.11.23",
41
- "dompurify": "^3.4.17",
41
+ "dompurify": "^3.4.18",
42
42
  "flat": "^6.0.1",
43
43
  "fuse.js": "^7.5.0",
44
44
  "handlebars": "^4.7.10",
@@ -97,7 +97,7 @@
97
97
  "url": "https://github.com/CybercentreCanada/howler"
98
98
  },
99
99
  "type": "module",
100
- "version": "3.2.0-dev.1879.1",
100
+ "version": "3.2.0-dev.1925.1",
101
101
  "exports": {
102
102
  "./i18n": "./i18n.js",
103
103
  "./index.css": "./index.css",