@automattic/jetpack-scan 0.1.0 → 0.3.0
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 +14 -0
- package/package.json +9 -9
- package/src/utils/index.ts +94 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.3.0] - 2024-11-25
|
|
9
|
+
### Added
|
|
10
|
+
- Adds utilities for retrieving fixer messaging [#40197]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Updated package dependencies. [#40288]
|
|
14
|
+
|
|
15
|
+
## [0.2.0] - 2024-11-14
|
|
16
|
+
### Added
|
|
17
|
+
- Adds fixer utility functions [#40111]
|
|
18
|
+
|
|
8
19
|
## 0.1.0 - 2024-11-11
|
|
9
20
|
### Added
|
|
10
21
|
- Added threat and fixer types. [#39754]
|
|
@@ -52,3 +63,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
52
63
|
|
|
53
64
|
### Removed
|
|
54
65
|
- Updated dependencies. [#39754]
|
|
66
|
+
|
|
67
|
+
[0.3.0]: https://github.com/Automattic/jetpack-scan/compare/v0.2.0...v0.3.0
|
|
68
|
+
[0.2.0]: https://github.com/Automattic/jetpack-scan/compare/v0.1.0...v0.2.0
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@automattic/jetpack-scan",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "A JS client for consuming Jetpack Scan services",
|
|
6
6
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/scan/#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@testing-library/react": "16.0.1",
|
|
35
35
|
"@types/jest": "29.5.12",
|
|
36
36
|
"@types/react": "18.3.12",
|
|
37
|
-
"@wordpress/babel-plugin-import-jsx-pragma": "5.
|
|
37
|
+
"@wordpress/babel-plugin-import-jsx-pragma": "5.12.0",
|
|
38
38
|
"babel-jest": "29.7.0",
|
|
39
39
|
"jest": "^29.7.0",
|
|
40
40
|
"jest-environment-jsdom": "29.7.0",
|
|
@@ -50,18 +50,18 @@
|
|
|
50
50
|
"main": "./build/index.js",
|
|
51
51
|
"types": "./build/index.d.ts",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@automattic/jetpack-api": "^0.17.
|
|
54
|
-
"@automattic/jetpack-base-styles": "^0.6.
|
|
55
|
-
"@wordpress/api-fetch": "7.
|
|
56
|
-
"@wordpress/element": "6.
|
|
57
|
-
"@wordpress/i18n": "5.
|
|
58
|
-
"@wordpress/url": "4.
|
|
53
|
+
"@automattic/jetpack-api": "^0.17.19",
|
|
54
|
+
"@automattic/jetpack-base-styles": "^0.6.37",
|
|
55
|
+
"@wordpress/api-fetch": "7.12.0",
|
|
56
|
+
"@wordpress/element": "6.12.0",
|
|
57
|
+
"@wordpress/i18n": "5.12.0",
|
|
58
|
+
"@wordpress/url": "4.12.0",
|
|
59
59
|
"debug": "4.3.4",
|
|
60
60
|
"react": "^18.2.0",
|
|
61
61
|
"react-dom": "^18.2.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@wordpress/i18n": "5.
|
|
64
|
+
"@wordpress/i18n": "5.12.0",
|
|
65
65
|
"react": "^18.2.0",
|
|
66
66
|
"react-dom": "^18.2.0"
|
|
67
67
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
1
2
|
import { Threat, ThreatFixStatus, FIXER_IS_STALE_THRESHOLD } from '..';
|
|
2
3
|
|
|
3
4
|
export const getThreatType = ( threat: Threat ) => {
|
|
@@ -20,10 +21,99 @@ export const fixerTimestampIsStale = ( lastUpdatedTimestamp: string ) => {
|
|
|
20
21
|
return now.getTime() - lastUpdated.getTime() >= FIXER_IS_STALE_THRESHOLD;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export const
|
|
24
|
+
export const fixerIsInError = ( fixerStatus: ThreatFixStatus ): boolean => {
|
|
25
|
+
return !! ( 'error' in fixerStatus && fixerStatus.error );
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const fixerIsInProgress = ( fixerStatus: ThreatFixStatus ): boolean => {
|
|
29
|
+
return !! ( 'status' in fixerStatus && fixerStatus.status === 'in_progress' );
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const fixerStatusIsStale = ( fixerStatus: ThreatFixStatus ): boolean => {
|
|
24
33
|
return (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
fixerTimestampIsStale( fixerStatus.lastUpdated )
|
|
34
|
+
fixerIsInProgress( fixerStatus ) &&
|
|
35
|
+
'lastUpdated' in fixerStatus &&
|
|
36
|
+
!! fixerTimestampIsStale( fixerStatus.lastUpdated )
|
|
28
37
|
);
|
|
29
38
|
};
|
|
39
|
+
|
|
40
|
+
export const getFixerState = ( fixerStatus: ThreatFixStatus ) => {
|
|
41
|
+
return {
|
|
42
|
+
inProgress: fixerStatus && fixerIsInProgress( fixerStatus ),
|
|
43
|
+
error: fixerStatus && fixerIsInError( fixerStatus ),
|
|
44
|
+
stale: fixerStatus && fixerStatusIsStale( fixerStatus ),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const getFixerAction = ( threat: Threat ) => {
|
|
49
|
+
switch ( threat.fixable && threat.fixable.fixer ) {
|
|
50
|
+
case 'delete':
|
|
51
|
+
return __( 'Delete', 'jetpack-scan' );
|
|
52
|
+
case 'update':
|
|
53
|
+
return __( 'Update', 'jetpack-scan' );
|
|
54
|
+
case 'replace':
|
|
55
|
+
case 'rollback':
|
|
56
|
+
return __( 'Replace', 'jetpack-scan' );
|
|
57
|
+
default:
|
|
58
|
+
return __( 'Fix', 'jetpack-scan' );
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const getFixerMessage = ( threat: Threat ) => {
|
|
63
|
+
switch ( threat.fixable && threat.fixable.fixer ) {
|
|
64
|
+
case 'delete':
|
|
65
|
+
if ( threat.filename ) {
|
|
66
|
+
if ( threat.filename.endsWith( '/' ) ) {
|
|
67
|
+
return __( 'Deletes the directory that the infected file is in.', 'jetpack-scan' );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ( threat.signature === 'Core.File.Modification' ) {
|
|
71
|
+
return __( 'Deletes the unexpected file in a core WordPress directory.', 'jetpack-scan' );
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return __( 'Deletes the infected file.', 'jetpack-scan' );
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ( threat.extension?.type === 'plugin' ) {
|
|
78
|
+
return __( 'Deletes the plugin directory to fix the threat.', 'jetpack-scan' );
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if ( threat.extension?.type === 'theme' ) {
|
|
82
|
+
return __( 'Deletes the theme directory to fix the threat.', 'jetpack-scan' );
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'update':
|
|
86
|
+
if ( threat.fixedIn && threat.extension.name ) {
|
|
87
|
+
return sprintf(
|
|
88
|
+
/* translators: Translates to Updates to version. %1$s: Name. %2$s: Fixed version */
|
|
89
|
+
__( 'Updates %1$s to version %2$s', 'jetpack-scan' ),
|
|
90
|
+
threat.extension.name,
|
|
91
|
+
threat.fixedIn
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return __( 'Upgrades the plugin or theme to a newer version.', 'jetpack-scan' );
|
|
95
|
+
case 'replace':
|
|
96
|
+
case 'rollback':
|
|
97
|
+
if ( threat.filename ) {
|
|
98
|
+
return threat.signature === 'Core.File.Modification'
|
|
99
|
+
? __(
|
|
100
|
+
'Replaces the modified core WordPress file with the original clean version from the WordPress source code.',
|
|
101
|
+
'jetpack-scan'
|
|
102
|
+
)
|
|
103
|
+
: __(
|
|
104
|
+
'Replaces the infected file with a previously backed up version that is clean.',
|
|
105
|
+
'jetpack-scan'
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if ( threat.signature === 'php_hardening_WP_Config_NoSalts_001' ) {
|
|
110
|
+
return __(
|
|
111
|
+
'Replaces the default salt keys in wp-config.php with unique ones.',
|
|
112
|
+
'jetpack-scan'
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
return __( 'Jetpack will auto-fix the threat.', 'jetpack-scan' );
|
|
118
|
+
}
|
|
119
|
+
};
|