Skip to content

Commit 4a1a328

Browse files
authored
Publicize: Mitigate obscure PHP fatals when REST receives malformed data (#45418)
* Mitigate fatals * Add changelog * Return WP_Error instead of empty array * Simplify wording
1 parent 855c432 commit 4a1a328

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Sharing: Prevent PHP fatals when passed malformed data.

projects/packages/publicize/src/class-rest-controller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ public function register_rest_routes() {
106106
return is_array( $param );
107107
},
108108
'sanitize_callback' => function ( $param ) {
109+
if ( ! is_array( $param ) ) {
110+
return new WP_Error(
111+
'rest_invalid_param',
112+
esc_html__( 'The skipped_connections argument must be an array of connection IDs.', 'jetpack-publicize-pkg' ),
113+
array( 'status' => 400 )
114+
);
115+
}
109116
return array_map( 'absint', $param );
110117
},
111118
),

projects/packages/publicize/src/rest-api/class-share-post-controller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public function register_routes() {
6969
return is_array( $param );
7070
},
7171
'sanitize_callback' => function ( $param ) {
72+
if ( ! is_array( $param ) ) {
73+
return new WP_Error(
74+
'rest_invalid_param',
75+
esc_html__( 'The skipped_connections argument must be an array of connection IDs.', 'jetpack-publicize-pkg' ),
76+
array( 'status' => 400 )
77+
);
78+
}
7279
return array_map( 'absint', $param );
7380
},
7481
),

0 commit comments

Comments
 (0)