Skip to content

Commit 4993848

Browse files
authored
Scan: ensure that a database threat looks correct (#103748)
* Scan: ensure that a database threat looks correct * threat-item/utils.ts: properly detect the new shape of database threat metadata * Database threat: match with what we say in the emails
1 parent f805210 commit 4993848

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

client/components/jetpack/threat-description/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ export interface Props {
1818
diff?: string;
1919
rows?: Record< string, unknown >;
2020
table?: string;
21+
primaryKeyColumn?: string;
22+
value?: string;
2123
filename?: string;
2224
isFixable: boolean;
25+
details?: Record< string, unknown >;
2326
}
2427

2528
class ThreatDescription extends PureComponent< Props > {
@@ -67,12 +70,18 @@ class ThreatDescription extends PureComponent< Props > {
6770
}
6871

6972
renderDatabaseRows(): ReactNode | null {
70-
const { rows, table } = this.props;
71-
if ( ! rows || ! table ) {
73+
const { table, details, primaryKeyColumn, value } = this.props;
74+
if ( ! table || ! details ) {
7275
return null;
7376
}
7477

75-
const content = Object.values( rows ).map( ( row ) => JSON.stringify( row ) + '\n' );
78+
const row = {
79+
table,
80+
primary_key_column: primaryKeyColumn,
81+
primary_key_value: value,
82+
details,
83+
};
84+
const content = JSON.stringify( row, null, ' \t' ) + '\n';
7685

7786
return (
7887
<>

client/components/jetpack/threat-item-header/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ const getThreatMessage = ( threat: Threat ) => {
6565

6666
case 'database':
6767
if ( ! threat.rows ) {
68+
if ( threat.table !== undefined ) {
69+
return translate( 'The database table %(table)s contains malicious code', {
70+
args: {
71+
table: threat.table,
72+
},
73+
} );
74+
}
75+
6876
return translate( 'Database threat' );
6977
}
7078
return translate(

client/components/jetpack/threat-item/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ const ThreatItem: React.FC< Props > = ( {
180180
diff={ threat.diff }
181181
rows={ threat.rows }
182182
table={ threat.table }
183+
primaryKeyColumn={ threat.primaryKeyColumn }
184+
value={ threat.value }
183185
filename={ threat.filename }
184186
isFixable={ isFixable }
187+
details={ threat.details }
185188
/>
186189

187190
<div className="threat-item__buttons">

client/components/jetpack/threat-item/types.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ export interface BaseThreat {
3232
extension?: Extension;
3333
rows?: Record< string, unknown >;
3434
table?: string;
35+
primaryKeyColumn?: string;
36+
value?: string;
3537
diff?: string;
3638
context?: Record< string, unknown >;
3739
severity: number;
3840
source?: string;
3941
version?: string;
42+
details?: Record< string, unknown >;
4043
}
4144

4245
export interface FixableThreat extends BaseThreat {

client/components/jetpack/threat-item/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export function getThreatType( threat: Threat ): ThreatType {
105105
return 'database';
106106
}
107107

108+
if ( threat.table !== undefined ) {
109+
return 'database';
110+
}
111+
108112
if ( 'Suspicious.Links' === threat.signature ) {
109113
return 'database';
110114
}
@@ -136,6 +140,20 @@ export const getThreatVulnerability = ( threat: Threat ): string | TranslateResu
136140
return translate( 'Vulnerability found in a theme' );
137141

138142
case 'database':
143+
if ( threat.signature !== undefined ) {
144+
return translate( 'Thread found: %(signature)s', {
145+
args: {
146+
signature: threat.signature,
147+
},
148+
} );
149+
}
150+
if ( threat.table !== undefined ) {
151+
return translate( 'The database table %(table)s contains malicious code', {
152+
args: {
153+
table: threat.table,
154+
},
155+
} );
156+
}
139157
return 'Vulnerability found in a database table';
140158

141159
case 'none':

client/state/data-layer/wpcom/sites/scan/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const formatScanThreat = ( threat ) => ( {
2929
rows: threat.rows,
3030
diff: threat.diff,
3131
table: threat.table,
32+
primaryKeyColumn: threat.pk_column,
33+
value: threat.value,
34+
details: threat.details,
3235
context: threat.context,
3336
severity: threat.severity,
3437
source: threat.source,

0 commit comments

Comments
 (0)