@automattic/jetpack-scan 1.3.0 → 1.4.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/CHANGELOG.md +22 -0
- package/package.json +22 -25
- package/src/components/threat-severity-badge/index.tsx +8 -4
- package/src/components/threats-data-views/constants.ts +6 -6
- package/src/components/threats-data-views/index.tsx +243 -84
- package/src/components/threats-data-views/styles.module.scss +23 -0
- package/build/components/index.d.ts +0 -4
- package/build/components/index.js +0 -4
- package/build/components/threat-fixer-button/index.d.ts +0 -16
- package/build/components/threat-fixer-button/index.js +0 -56
- package/build/components/threat-modal/fixer-state-notice.d.ts +0 -19
- package/build/components/threat-modal/fixer-state-notice.js +0 -44
- package/build/components/threat-modal/index.d.ts +0 -52
- package/build/components/threat-modal/index.js +0 -49
- package/build/components/threat-modal/threat-actions.d.ts +0 -7
- package/build/components/threat-modal/threat-actions.js +0 -43
- package/build/components/threat-modal/threat-fix-confirmation.d.ts +0 -7
- package/build/components/threat-modal/threat-fix-confirmation.js +0 -21
- package/build/components/threat-modal/threat-fix-details.d.ts +0 -7
- package/build/components/threat-modal/threat-fix-details.js +0 -41
- package/build/components/threat-modal/threat-notice.d.ts +0 -16
- package/build/components/threat-modal/threat-notice.js +0 -26
- package/build/components/threat-modal/threat-summary.d.ts +0 -7
- package/build/components/threat-modal/threat-summary.js +0 -16
- package/build/components/threat-modal/threat-technical-details.d.ts +0 -7
- package/build/components/threat-modal/threat-technical-details.js +0 -31
- package/build/components/threat-severity-badge/index.d.ts +0 -4
- package/build/components/threat-severity-badge/index.js +0 -13
- package/build/components/threat-severity-badge/test/index.test.d.ts +0 -1
- package/build/components/threat-severity-badge/test/index.test.js +0 -9
- package/build/components/threats-data-views/constants.d.ts +0 -42
- package/build/components/threats-data-views/constants.js +0 -37
- package/build/components/threats-data-views/index.d.ts +0 -29
- package/build/components/threats-data-views/index.js +0 -410
- package/build/components/threats-data-views/test/index.test.d.ts +0 -1
- package/build/components/threats-data-views/test/index.test.js +0 -51
- package/build/components/threats-data-views/threats-status-toggle-group-control.d.ts +0 -15
- package/build/components/threats-data-views/threats-status-toggle-group-control.js +0 -97
- package/build/constants/index.d.ts +0 -3
- package/build/constants/index.js +0 -3
- package/build/index.d.ts +0 -4
- package/build/index.js +0 -4
- package/build/index.test.d.ts +0 -1
- package/build/index.test.js +0 -4
- package/build/types/fixers.d.ts +0 -34
- package/build/types/fixers.js +0 -1
- package/build/types/index.d.ts +0 -3
- package/build/types/index.js +0 -3
- package/build/types/status.d.ts +0 -42
- package/build/types/status.js +0 -1
- package/build/types/threats.d.ts +0 -50
- package/build/types/threats.js +0 -1
- package/build/utils/index.d.ts +0 -15
- package/build/utils/index.js +0 -125
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Badge } from '@automattic/jetpack-components';
|
|
3
|
-
import { DataViews, filterSortAndPaginate, } from '@wordpress/dataviews';
|
|
4
|
-
import { dateI18n } from '@wordpress/date';
|
|
5
|
-
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { Icon } from '@wordpress/icons';
|
|
7
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
8
|
-
import { ThreatSeverityBadge, getThreatType } from '@automattic/jetpack-scan';
|
|
9
|
-
import ThreatFixerButton from '../threat-fixer-button/index.js';
|
|
10
|
-
import { THREAT_ACTION_FIX, THREAT_ACTION_IGNORE, THREAT_ACTION_UNIGNORE, THREAT_FIELD_AUTO_FIX, THREAT_FIELD_DESCRIPTION, THREAT_FIELD_EXTENSION, THREAT_FIELD_FIRST_DETECTED, THREAT_FIELD_FIXED_ON, THREAT_FIELD_ICON, THREAT_FIELD_PLUGIN, THREAT_FIELD_SEVERITY, THREAT_FIELD_SIGNATURE, THREAT_FIELD_STATUS, THREAT_FIELD_THEME, THREAT_FIELD_TITLE, THREAT_FIELD_TYPE, THREAT_ICONS, THREAT_STATUSES, THREAT_TYPES, } from './constants.js';
|
|
11
|
-
import styles from './styles.module.scss';
|
|
12
|
-
import ThreatsStatusToggleGroupControl from './threats-status-toggle-group-control.js';
|
|
13
|
-
/**
|
|
14
|
-
* DataViews component for displaying security threats.
|
|
15
|
-
*
|
|
16
|
-
* @param {object} props - Component props.
|
|
17
|
-
* @param {Array} props.data - Threats data.
|
|
18
|
-
* @param {Array} props.filters - Initial DataView filters.
|
|
19
|
-
* @param {Function} props.onChangeSelection - Callback function run when an item is selected.
|
|
20
|
-
* @param {Function} props.onFixThreats - Threat fix action callback.
|
|
21
|
-
* @param {Function} props.onIgnoreThreats - Threat ignore action callback.
|
|
22
|
-
* @param {Function} props.onUnignoreThreats - Threat unignore action callback.
|
|
23
|
-
* @param {Function} props.isThreatEligibleForFix - Function to determine if a threat is eligible for fixing.
|
|
24
|
-
* @param {Function} props.isThreatEligibleForIgnore - Function to determine if a threat is eligible for ignoring.
|
|
25
|
-
* @param {Function} props.isThreatEligibleForUnignore - Function to determine if a threat is eligible for unignoring.
|
|
26
|
-
*
|
|
27
|
-
* @return {JSX.Element} The ThreatsDataViews component.
|
|
28
|
-
*/
|
|
29
|
-
export default function ThreatsDataViews({ data, filters, onChangeSelection, isThreatEligibleForFix, isThreatEligibleForIgnore, isThreatEligibleForUnignore, onFixThreats, onIgnoreThreats, onUnignoreThreats, }) {
|
|
30
|
-
const baseView = {
|
|
31
|
-
sort: {
|
|
32
|
-
field: 'severity',
|
|
33
|
-
direction: 'desc',
|
|
34
|
-
},
|
|
35
|
-
search: '',
|
|
36
|
-
filters: filters || [],
|
|
37
|
-
page: 1,
|
|
38
|
-
perPage: 20,
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* DataView default layouts.
|
|
42
|
-
*
|
|
43
|
-
* This property provides layout information about the view types that are active. If empty, enables all layout types (see “Layout Types”) with empty layout data.
|
|
44
|
-
*
|
|
45
|
-
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#defaultlayouts-record-string-view
|
|
46
|
-
*/
|
|
47
|
-
const defaultLayouts = {
|
|
48
|
-
table: {
|
|
49
|
-
...baseView,
|
|
50
|
-
fields: [THREAT_FIELD_SEVERITY, THREAT_FIELD_TYPE, THREAT_FIELD_AUTO_FIX],
|
|
51
|
-
titleField: THREAT_FIELD_TITLE,
|
|
52
|
-
descriptionField: THREAT_FIELD_DESCRIPTION,
|
|
53
|
-
showMedia: false,
|
|
54
|
-
},
|
|
55
|
-
list: {
|
|
56
|
-
...baseView,
|
|
57
|
-
fields: [
|
|
58
|
-
THREAT_FIELD_SEVERITY,
|
|
59
|
-
THREAT_FIELD_TYPE,
|
|
60
|
-
THREAT_FIELD_EXTENSION,
|
|
61
|
-
THREAT_FIELD_SIGNATURE,
|
|
62
|
-
],
|
|
63
|
-
titleField: THREAT_FIELD_TITLE,
|
|
64
|
-
mediaField: THREAT_FIELD_ICON,
|
|
65
|
-
showMedia: true,
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* DataView view object - configures how the dataset is visible to the user.
|
|
70
|
-
*
|
|
71
|
-
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#view-object
|
|
72
|
-
*/
|
|
73
|
-
const [view, setView] = useState({
|
|
74
|
-
type: 'table',
|
|
75
|
-
...defaultLayouts.table,
|
|
76
|
-
});
|
|
77
|
-
/**
|
|
78
|
-
* Compute values from the provided threats data.
|
|
79
|
-
*
|
|
80
|
-
* @member {object[]} themes - List of unique themes included in the threats data.
|
|
81
|
-
* @member {object[]} plugins - plugins included in the threats data.
|
|
82
|
-
* @member {object[]} signatures - List of unique threat signatures.
|
|
83
|
-
* @member {string[]} dataFields - List of unique fields.
|
|
84
|
-
*/
|
|
85
|
-
const { themes, plugins, signatures, dataFields, } = useMemo(() => {
|
|
86
|
-
return data.reduce((acc, threat) => {
|
|
87
|
-
// Extensions (Themes and Plugins)
|
|
88
|
-
if (threat.extension) {
|
|
89
|
-
switch (threat.extension.type) {
|
|
90
|
-
case 'themes':
|
|
91
|
-
if (!acc.themes.find(({ value }) => value === threat.extension.slug)) {
|
|
92
|
-
acc.themes.push({ value: threat.extension.slug, label: threat.extension.name });
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
case 'plugins':
|
|
96
|
-
if (!acc.plugins.find(({ value }) => value === threat.extension.slug)) {
|
|
97
|
-
acc.plugins.push({ value: threat.extension.slug, label: threat.extension.name });
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
default:
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// Signatures
|
|
105
|
-
if (threat.signature) {
|
|
106
|
-
if (!acc.signatures.find(({ value }) => value === threat.signature)) {
|
|
107
|
-
acc.signatures.push({ value: threat.signature, label: threat.signature });
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Fields
|
|
111
|
-
const fields = Object.keys(threat);
|
|
112
|
-
fields.forEach(field => {
|
|
113
|
-
if (!acc.dataFields.includes(field) &&
|
|
114
|
-
threat[field] !== null &&
|
|
115
|
-
threat[field] !== undefined) {
|
|
116
|
-
acc.dataFields.push(field);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
return acc;
|
|
120
|
-
}, {
|
|
121
|
-
themes: [],
|
|
122
|
-
plugins: [],
|
|
123
|
-
signatures: [],
|
|
124
|
-
dataFields: [],
|
|
125
|
-
});
|
|
126
|
-
}, [data]);
|
|
127
|
-
/**
|
|
128
|
-
* DataView fields - describes the visible items for each record in the dataset.
|
|
129
|
-
*
|
|
130
|
-
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#fields-object
|
|
131
|
-
*/
|
|
132
|
-
const fields = useMemo(() => {
|
|
133
|
-
const result = [
|
|
134
|
-
{
|
|
135
|
-
id: THREAT_FIELD_TITLE,
|
|
136
|
-
label: __('Threat', 'jetpack-scan'),
|
|
137
|
-
enableGlobalSearch: true,
|
|
138
|
-
enableHiding: false,
|
|
139
|
-
render: ({ item }) => (_jsx("div", { className: styles.threat__title, children: item.title })),
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: THREAT_FIELD_DESCRIPTION,
|
|
143
|
-
label: __('Description', 'jetpack-scan'),
|
|
144
|
-
enableGlobalSearch: true,
|
|
145
|
-
enableHiding: false,
|
|
146
|
-
render: ({ item }) => (_jsx("div", { className: styles.threat__description, children: item.description })),
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
id: THREAT_FIELD_ICON,
|
|
150
|
-
label: __('Icon', 'jetpack-scan'),
|
|
151
|
-
enableHiding: false,
|
|
152
|
-
getValue({ item }) {
|
|
153
|
-
return getThreatType(item);
|
|
154
|
-
},
|
|
155
|
-
render({ item }) {
|
|
156
|
-
return (_jsx("div", { className: styles.threat__media, children: _jsx(Icon, { icon: THREAT_ICONS[getThreatType(item)], size: 20 }) }));
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
id: THREAT_FIELD_STATUS,
|
|
161
|
-
label: __('Status', 'jetpack-scan'),
|
|
162
|
-
elements: THREAT_STATUSES,
|
|
163
|
-
getValue({ item }) {
|
|
164
|
-
if (!item.status) {
|
|
165
|
-
return 'current';
|
|
166
|
-
}
|
|
167
|
-
return (THREAT_STATUSES.find(({ value }) => value === item.status)?.value ?? item.status);
|
|
168
|
-
},
|
|
169
|
-
render({ item }) {
|
|
170
|
-
if (item.status) {
|
|
171
|
-
const status = THREAT_STATUSES.find(({ value }) => value === item.status);
|
|
172
|
-
if (status) {
|
|
173
|
-
return _jsx(Badge, { variant: status?.variant, children: status.label });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return _jsx(Badge, { variant: "warning", children: __('Active', 'jetpack-scan') });
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
id: THREAT_FIELD_TYPE,
|
|
181
|
-
label: __('Type', 'jetpack-scan'),
|
|
182
|
-
elements: THREAT_TYPES,
|
|
183
|
-
getValue({ item }) {
|
|
184
|
-
switch (getThreatType(item)) {
|
|
185
|
-
case 'core':
|
|
186
|
-
return __('WordPress', 'jetpack-scan');
|
|
187
|
-
case 'plugins':
|
|
188
|
-
return __('Plugin', 'jetpack-scan');
|
|
189
|
-
case 'themes':
|
|
190
|
-
return __('Theme', 'jetpack-scan');
|
|
191
|
-
case 'file':
|
|
192
|
-
return __('File', 'jetpack-scan');
|
|
193
|
-
default:
|
|
194
|
-
return __('Unknown', 'jetpack-scan');
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
id: THREAT_FIELD_EXTENSION,
|
|
200
|
-
label: __('Extension', 'jetpack-scan'),
|
|
201
|
-
enableGlobalSearch: true,
|
|
202
|
-
enableHiding: true,
|
|
203
|
-
getValue({ item }) {
|
|
204
|
-
return item.extension ? item.extension.slug : '';
|
|
205
|
-
},
|
|
206
|
-
render({ item }) {
|
|
207
|
-
return item.extension ? item.extension.name : '';
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
id: THREAT_FIELD_PLUGIN,
|
|
212
|
-
label: __('Plugin', 'jetpack-scan'),
|
|
213
|
-
enableGlobalSearch: true,
|
|
214
|
-
enableHiding: false,
|
|
215
|
-
elements: plugins,
|
|
216
|
-
getValue({ item }) {
|
|
217
|
-
return item.extension ? item.extension.slug : '';
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
id: THREAT_FIELD_THEME,
|
|
222
|
-
label: __('Theme', 'jetpack-scan'),
|
|
223
|
-
enableGlobalSearch: true,
|
|
224
|
-
enableHiding: false,
|
|
225
|
-
elements: themes,
|
|
226
|
-
getValue({ item }) {
|
|
227
|
-
return item.extension ? item.extension.slug : '';
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
...(dataFields.includes('severity')
|
|
231
|
-
? [
|
|
232
|
-
{
|
|
233
|
-
id: THREAT_FIELD_SEVERITY,
|
|
234
|
-
label: __('Severity', 'jetpack-scan'),
|
|
235
|
-
type: 'integer',
|
|
236
|
-
getValue({ item }) {
|
|
237
|
-
return item.severity ?? 0;
|
|
238
|
-
},
|
|
239
|
-
render({ item }) {
|
|
240
|
-
return _jsx(ThreatSeverityBadge, { severity: item.severity });
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
]
|
|
244
|
-
: []),
|
|
245
|
-
...(dataFields.includes('signature')
|
|
246
|
-
? [
|
|
247
|
-
{
|
|
248
|
-
id: THREAT_FIELD_SIGNATURE,
|
|
249
|
-
label: __('Signature', 'jetpack-scan'),
|
|
250
|
-
elements: signatures,
|
|
251
|
-
enableGlobalSearch: true,
|
|
252
|
-
getValue({ item }) {
|
|
253
|
-
return item.signature || '';
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
]
|
|
257
|
-
: []),
|
|
258
|
-
...(dataFields.includes('firstDetected')
|
|
259
|
-
? [
|
|
260
|
-
{
|
|
261
|
-
id: THREAT_FIELD_FIRST_DETECTED,
|
|
262
|
-
label: __('First Detected', 'jetpack-scan'),
|
|
263
|
-
type: 'datetime',
|
|
264
|
-
getValue({ item }) {
|
|
265
|
-
return item.firstDetected ? new Date(item.firstDetected) : null;
|
|
266
|
-
},
|
|
267
|
-
render({ item }) {
|
|
268
|
-
return item.firstDetected ? (_jsx("span", { className: styles.threat__firstDetected, children: dateI18n('F j Y', item.firstDetected, false) })) : null;
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
]
|
|
272
|
-
: []),
|
|
273
|
-
...(dataFields.includes('fixedOn')
|
|
274
|
-
? [
|
|
275
|
-
{
|
|
276
|
-
id: THREAT_FIELD_FIXED_ON,
|
|
277
|
-
label: __('Fixed On', 'jetpack-scan'),
|
|
278
|
-
type: 'datetime',
|
|
279
|
-
getValue({ item }) {
|
|
280
|
-
return item.fixedOn ? new Date(item.fixedOn) : null;
|
|
281
|
-
},
|
|
282
|
-
render({ item }) {
|
|
283
|
-
return item.fixedOn ? (_jsx("span", { className: styles.threat__fixedOn, children: dateI18n('F j Y', item.fixedOn, false) })) : null;
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
]
|
|
287
|
-
: []),
|
|
288
|
-
...(dataFields.includes('fixable')
|
|
289
|
-
? [
|
|
290
|
-
{
|
|
291
|
-
id: THREAT_FIELD_AUTO_FIX,
|
|
292
|
-
label: __('Auto-fix', 'jetpack-scan'),
|
|
293
|
-
enableHiding: false,
|
|
294
|
-
elements: [
|
|
295
|
-
{
|
|
296
|
-
value: 'yes',
|
|
297
|
-
label: __('Yes', 'jetpack-scan'),
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
value: 'no',
|
|
301
|
-
label: __('No', 'jetpack-scan'),
|
|
302
|
-
},
|
|
303
|
-
],
|
|
304
|
-
getValue({ item }) {
|
|
305
|
-
return item.fixable ? 'yes' : 'no';
|
|
306
|
-
},
|
|
307
|
-
render({ item }) {
|
|
308
|
-
if (!item.fixable) {
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
return _jsx(ThreatFixerButton, { threat: item, onClick: onFixThreats });
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
]
|
|
315
|
-
: []),
|
|
316
|
-
];
|
|
317
|
-
return result;
|
|
318
|
-
}, [dataFields, plugins, themes, signatures, onFixThreats]);
|
|
319
|
-
/**
|
|
320
|
-
* DataView actions - collection of operations that can be performed upon each record.
|
|
321
|
-
*
|
|
322
|
-
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#actions-object
|
|
323
|
-
*/
|
|
324
|
-
const actions = useMemo(() => {
|
|
325
|
-
const result = [];
|
|
326
|
-
if (dataFields.includes('fixable')) {
|
|
327
|
-
result.push({
|
|
328
|
-
id: THREAT_ACTION_FIX,
|
|
329
|
-
label: __('Auto-fix', 'jetpack-scan'),
|
|
330
|
-
isPrimary: true,
|
|
331
|
-
callback: onFixThreats,
|
|
332
|
-
isEligible(item) {
|
|
333
|
-
if (!onFixThreats) {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
if (isThreatEligibleForFix) {
|
|
337
|
-
return isThreatEligibleForFix(item);
|
|
338
|
-
}
|
|
339
|
-
return !!item.fixable;
|
|
340
|
-
},
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
if (dataFields.includes('status')) {
|
|
344
|
-
result.push({
|
|
345
|
-
id: THREAT_ACTION_IGNORE,
|
|
346
|
-
label: __('Ignore', 'jetpack-scan'),
|
|
347
|
-
isPrimary: true,
|
|
348
|
-
callback: onIgnoreThreats,
|
|
349
|
-
isEligible(item) {
|
|
350
|
-
if (!onIgnoreThreats) {
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
if (isThreatEligibleForIgnore) {
|
|
354
|
-
return isThreatEligibleForIgnore(item);
|
|
355
|
-
}
|
|
356
|
-
return item.status === 'current';
|
|
357
|
-
},
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
if (dataFields.includes('status')) {
|
|
361
|
-
result.push({
|
|
362
|
-
id: THREAT_ACTION_UNIGNORE,
|
|
363
|
-
label: __('Unignore', 'jetpack-scan'),
|
|
364
|
-
isPrimary: true,
|
|
365
|
-
callback: onUnignoreThreats,
|
|
366
|
-
isEligible(item) {
|
|
367
|
-
if (!onUnignoreThreats) {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
if (isThreatEligibleForUnignore) {
|
|
371
|
-
return isThreatEligibleForUnignore(item);
|
|
372
|
-
}
|
|
373
|
-
return item.status === 'ignored';
|
|
374
|
-
},
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
return result;
|
|
378
|
-
}, [
|
|
379
|
-
dataFields,
|
|
380
|
-
onFixThreats,
|
|
381
|
-
onIgnoreThreats,
|
|
382
|
-
onUnignoreThreats,
|
|
383
|
-
isThreatEligibleForFix,
|
|
384
|
-
isThreatEligibleForIgnore,
|
|
385
|
-
isThreatEligibleForUnignore,
|
|
386
|
-
]);
|
|
387
|
-
/**
|
|
388
|
-
* Apply the view settings (i.e. filters, sorting, pagination) to the dataset.
|
|
389
|
-
*
|
|
390
|
-
* @see https://github.com/WordPress/gutenberg/blob/trunk/packages/dataviews/src/filter-and-sort-data-view.ts
|
|
391
|
-
*/
|
|
392
|
-
const { data: processedData, paginationInfo } = useMemo(() => {
|
|
393
|
-
return filterSortAndPaginate(data, view, fields);
|
|
394
|
-
}, [data, view, fields]);
|
|
395
|
-
/**
|
|
396
|
-
* Callback function to update the view state.
|
|
397
|
-
*
|
|
398
|
-
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#onchangeview-function
|
|
399
|
-
*/
|
|
400
|
-
const onChangeView = useCallback((newView) => {
|
|
401
|
-
setView(newView);
|
|
402
|
-
}, []);
|
|
403
|
-
/**
|
|
404
|
-
* DataView getItemId function - returns the unique ID for each record in the dataset.
|
|
405
|
-
*
|
|
406
|
-
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#getitemid-function
|
|
407
|
-
*/
|
|
408
|
-
const getItemId = useCallback((item) => item.id.toString(), []);
|
|
409
|
-
return (_jsx(DataViews, { actions: actions, data: processedData, defaultLayouts: defaultLayouts, fields: fields, getItemId: getItemId, onChangeSelection: onChangeSelection, onChangeView: onChangeView, paginationInfo: paginationInfo, view: view, header: _jsx(ThreatsStatusToggleGroupControl, { data: data, view: view, onChangeView: onChangeView }) }));
|
|
410
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import ThreatsDataViews from '../index.js';
|
|
4
|
-
const data = [
|
|
5
|
-
// Scan API Data
|
|
6
|
-
{
|
|
7
|
-
id: 185869885,
|
|
8
|
-
signature: 'EICAR_AV_Test',
|
|
9
|
-
title: 'Malicious code found in file: index.php',
|
|
10
|
-
description: "This is the standard EICAR antivirus test code, and not a real infection. If your site contains this code when you don't expect it to, contact Jetpack support for some help.",
|
|
11
|
-
firstDetected: '2024-10-07T20:45:06.000Z',
|
|
12
|
-
fixedIn: null,
|
|
13
|
-
fixedOn: '2024-10-07T20:45:06.000Z',
|
|
14
|
-
fixable: { fixer: 'rollback', target: 'January 26, 2024, 6:49 am', extensionStatus: '' },
|
|
15
|
-
fixer: {
|
|
16
|
-
status: 'in_progress',
|
|
17
|
-
startedAt: '2024-10-07T20:45:06.000Z',
|
|
18
|
-
lastUpdated: '2024-10-07T20:45:06.000Z',
|
|
19
|
-
},
|
|
20
|
-
severity: 8,
|
|
21
|
-
status: 'current',
|
|
22
|
-
filename: '/var/www/html/wp-content/index.php',
|
|
23
|
-
context: {
|
|
24
|
-
1: 'echo <<<HTML',
|
|
25
|
-
2: 'X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*',
|
|
26
|
-
3: 'HTML;',
|
|
27
|
-
marks: {},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
// Protect Report Data
|
|
31
|
-
{
|
|
32
|
-
id: '1d0470df-4671-47ac-8d87-a165e8f7d502',
|
|
33
|
-
title: 'WooCommerce <= 3.2.3 - Authenticated PHP Object Injection',
|
|
34
|
-
description: 'Versions 3.2.3 and earlier are affected by an issue where cached queries within shortcodes could lead to object injection. This is related to the recent WordPress 4.8.3 security release.This issue can only be exploited by users who can edit content and add shortcodes, but we still recommend all users running WooCommerce 3.x upgrade to 3.2 to mitigate this issue.',
|
|
35
|
-
source: 'https://wpscan.com/vulnerability/1d0470df-4671-47ac-8d87-a165e8f7d502',
|
|
36
|
-
extension: {
|
|
37
|
-
name: 'WooCommerce',
|
|
38
|
-
slug: 'woocommerce',
|
|
39
|
-
version: '3.2.3',
|
|
40
|
-
type: 'plugins',
|
|
41
|
-
},
|
|
42
|
-
fixedIn: '3.2.4',
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
describe('ThreatsDataViews', () => {
|
|
46
|
-
it('renders threat data', () => {
|
|
47
|
-
render(_jsx(ThreatsDataViews, { data: data }));
|
|
48
|
-
expect(screen.getByText('Malicious code found in file: index.php')).toBeInTheDocument();
|
|
49
|
-
expect(screen.getByText('WooCommerce <= 3.2.3 - Authenticated PHP Object Injection')).toBeInTheDocument();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type View } from '@wordpress/dataviews';
|
|
2
|
-
import { type Threat } from '@automattic/jetpack-scan';
|
|
3
|
-
/**
|
|
4
|
-
* ToggleGroupControl component for filtering threats by status.
|
|
5
|
-
* @param {object} props - Component props.
|
|
6
|
-
* @param { Threat[]} props.data - Threats data.
|
|
7
|
-
* @param { View } props.view - The current view.
|
|
8
|
-
* @param { Function } props.onChangeView - Callback function to handle view changes.
|
|
9
|
-
* @return {JSX.Element|null} The component or null.
|
|
10
|
-
*/
|
|
11
|
-
export default function ThreatsStatusToggleGroupControl({ data, view, onChangeView }: {
|
|
12
|
-
data: Threat[];
|
|
13
|
-
view: View;
|
|
14
|
-
onChangeView: (newView: View) => void;
|
|
15
|
-
}): JSX.Element;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { __experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
3
|
-
__experimentalToggleGroupControlOption as ToggleGroupControlOption, // eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
4
|
-
} from '@wordpress/components';
|
|
5
|
-
import { useMemo, useCallback } from '@wordpress/element';
|
|
6
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
-
import styles from './styles.module.scss';
|
|
8
|
-
/**
|
|
9
|
-
* ToggleGroupControl component for filtering threats by status.
|
|
10
|
-
* @param {object} props - Component props.
|
|
11
|
-
* @param { Threat[]} props.data - Threats data.
|
|
12
|
-
* @param { View } props.view - The current view.
|
|
13
|
-
* @param { Function } props.onChangeView - Callback function to handle view changes.
|
|
14
|
-
* @return {JSX.Element|null} The component or null.
|
|
15
|
-
*/
|
|
16
|
-
export default function ThreatsStatusToggleGroupControl({ data, view, onChangeView, }) {
|
|
17
|
-
/**
|
|
18
|
-
* Compute values from the provided threats data.
|
|
19
|
-
*
|
|
20
|
-
* @member {number} activeThreatsCount - Count of active threats.
|
|
21
|
-
* @member {number} historicThreatsCount - Count of historic threats.
|
|
22
|
-
*/
|
|
23
|
-
const { activeThreatsCount, historicThreatsCount, } = useMemo(() => {
|
|
24
|
-
return data.reduce((acc, threat) => {
|
|
25
|
-
if (threat.status) {
|
|
26
|
-
if (threat.status === 'current') {
|
|
27
|
-
acc.activeThreatsCount++;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
acc.historicThreatsCount++;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return acc;
|
|
34
|
-
}, {
|
|
35
|
-
activeThreatsCount: 0,
|
|
36
|
-
historicThreatsCount: 0,
|
|
37
|
-
});
|
|
38
|
-
}, [data]);
|
|
39
|
-
/**
|
|
40
|
-
* Callback function to handle the status change filter.
|
|
41
|
-
*
|
|
42
|
-
* @param {string} newStatus - The new status filter value.
|
|
43
|
-
*/
|
|
44
|
-
const onStatusFilterChange = useCallback((newStatus) => {
|
|
45
|
-
const updatedFilters = view.filters.filter(filter => filter.field !== 'status');
|
|
46
|
-
if (newStatus === 'active') {
|
|
47
|
-
updatedFilters.push({
|
|
48
|
-
field: 'status',
|
|
49
|
-
operator: 'isAny',
|
|
50
|
-
value: ['current'],
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else if (newStatus === 'historic') {
|
|
54
|
-
updatedFilters.push({
|
|
55
|
-
field: 'status',
|
|
56
|
-
operator: 'isAny',
|
|
57
|
-
value: ['fixed', 'ignored'],
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
onChangeView({
|
|
61
|
-
...view,
|
|
62
|
-
filters: updatedFilters,
|
|
63
|
-
});
|
|
64
|
-
}, [view, onChangeView]);
|
|
65
|
-
/**
|
|
66
|
-
* Memoized function to determine if a status filter is selected.
|
|
67
|
-
*
|
|
68
|
-
* @param {Array} threatStatuses - List of threat statuses.
|
|
69
|
-
*/
|
|
70
|
-
const isStatusFilterSelected = useMemo(() => (threatStatuses) => view.filters.some(filter => filter.field === 'status' &&
|
|
71
|
-
Array.isArray(filter.value) &&
|
|
72
|
-
filter.value.length === threatStatuses.length &&
|
|
73
|
-
threatStatuses.every(threatStatus => filter.value.includes(threatStatus))), [view.filters]);
|
|
74
|
-
const selectedValue = useMemo(() => {
|
|
75
|
-
if (isStatusFilterSelected(['current'])) {
|
|
76
|
-
return 'active';
|
|
77
|
-
}
|
|
78
|
-
if (isStatusFilterSelected(['fixed', 'ignored'])) {
|
|
79
|
-
return 'historic';
|
|
80
|
-
}
|
|
81
|
-
return '';
|
|
82
|
-
}, [isStatusFilterSelected]);
|
|
83
|
-
if (!(activeThreatsCount + historicThreatsCount)) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
return (_jsx("div", { children: _jsx("div", { className: styles['toggle-group-control'], children: _jsxs(ToggleGroupControl, { label: __('Filter threats by status', 'jetpack-scan'), value: selectedValue, onChange: onStatusFilterChange, isBlock: true, hideLabelFromVision: true, __nextHasNoMarginBottom: true, __next40pxDefaultSize: true, children: [
|
|
88
|
-
_jsx(ToggleGroupControlOption, { value: "active", label: sprintf(
|
|
89
|
-
/* translators: %d: number of active threats */ __('Active threats (%d)', 'jetpack-scan'), activeThreatsCount) }), _jsx(ToggleGroupControlOption, { value: "historic", label: sprintf(
|
|
90
|
-
/* translators: %d: number of historic threats */
|
|
91
|
-
__('History (%d)', 'jetpack-scan'), historicThreatsCount) })
|
|
92
|
-
] }) }) }));
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
package/build/constants/index.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export const CONTACT_SUPPORT_URL = 'https://jetpack.com/contact-support/?rel=support';
|
|
2
|
-
/** Once a fixer has been running for this specified amount of time (in ms), it should be considered "stale". */
|
|
3
|
-
export const FIXER_IS_STALE_THRESHOLD = 1000 * 60 * 60 * 24; // 24 hours
|
package/build/index.d.ts
DELETED
package/build/index.js
DELETED
package/build/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/index.test.js
DELETED
package/build/types/fixers.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type FixerStatus = 'not_started' | 'in_progress' | 'fixed' | 'not_fixed';
|
|
2
|
-
/**
|
|
3
|
-
* Threat Fix Status
|
|
4
|
-
*
|
|
5
|
-
* Individual fixer status for a threat.
|
|
6
|
-
*/
|
|
7
|
-
export type ThreatFixStatusError = {
|
|
8
|
-
error: string;
|
|
9
|
-
};
|
|
10
|
-
export type ThreatFixStatusSuccess = {
|
|
11
|
-
status: FixerStatus;
|
|
12
|
-
lastUpdated: string;
|
|
13
|
-
};
|
|
14
|
-
export type ThreatFixStatus = ThreatFixStatusError | ThreatFixStatusSuccess;
|
|
15
|
-
/**
|
|
16
|
-
* Fixers Status
|
|
17
|
-
*
|
|
18
|
-
* Overall status of all fixers.
|
|
19
|
-
*/
|
|
20
|
-
type FixersStatusBase = {
|
|
21
|
-
ok: boolean;
|
|
22
|
-
};
|
|
23
|
-
export type FixersStatusError = FixersStatusBase & {
|
|
24
|
-
ok: false;
|
|
25
|
-
error: string;
|
|
26
|
-
};
|
|
27
|
-
export type FixersStatusSuccess = FixersStatusBase & {
|
|
28
|
-
ok: true;
|
|
29
|
-
threats: {
|
|
30
|
-
[key: number]: ThreatFixStatus;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
export type FixersStatus = FixersStatusSuccess | FixersStatusError;
|
|
34
|
-
export {};
|
package/build/types/fixers.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/types/index.d.ts
DELETED
package/build/types/index.js
DELETED