Skip to content

Commit 41c7ec5

Browse files
fix: centralize safe remote imports for SSRF (#1336)
1 parent 6bad282 commit 41c7ec5

11 files changed

Lines changed: 1124 additions & 116 deletions

File tree

‎classes/Visualizer/Module/AIBuilder.php‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function fetchChart(): void {
206206
/**
207207
* Determines whether a remote URL serves an XLSX file.
208208
*
209-
* Uses wp_safe_remote_get() and checks ZIP magic number (PK\x03\x04).
209+
* Uses the shared remote-fetch policy and checks ZIP magic number (PK\x03\x04).
210210
*
211211
* @access private
212212
* @param string $url The remote URL to probe.
@@ -218,14 +218,15 @@ private static function _url_is_xlsx( $url ) {
218218
return false;
219219
}
220220

221-
$response = wp_safe_remote_get(
221+
$response = Visualizer_Remote_Fetch::request(
222222
$url,
223223
array(
224-
'timeout' => 15,
225-
'redirection' => 5,
226-
'stream' => true,
227-
'filename' => $tmpfile,
228-
'headers' => array( 'Range' => 'bytes=0-3' ),
224+
'timeout' => 15,
225+
'redirection' => 5,
226+
'stream' => true,
227+
'filename' => $tmpfile,
228+
'headers' => array( 'Range' => 'bytes=0-3' ),
229+
'limit_response_size' => 4,
229230
)
230231
);
231232

‎classes/Visualizer/Module/Chart.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ public function getJsonData() {
204204

205205
$chart_id = $params['chart'];
206206

207-
if ( empty( $chart_id ) ) {
207+
$chart = $chart_id ? get_post( $chart_id ) : null;
208+
if ( ! $chart || Visualizer_Plugin::CPT_VISUALIZER !== $chart->post_type || ! current_user_can( 'edit_post', $chart_id ) ) {
208209
wp_die();
209210
}
210211

@@ -1037,7 +1038,7 @@ public function renderFlattrScript() {
10371038
* Used as a fallback when the URL path has no recognisable file extension
10381039
* (e.g. SharePoint, signed S3 URLs, or "download?id=…" endpoints).
10391040
*
1040-
* Uses wp_safe_remote_get() to block requests to private/loopback addresses,
1041+
* Uses the shared remote-fetch policy to block non-public destinations,
10411042
* and streams the response to a temp file so no body data is held in memory
10421043
* regardless of whether the server honours the Range header.
10431044
*
@@ -1056,14 +1057,15 @@ private static function _url_is_xlsx( $url ) {
10561057
return false;
10571058
}
10581059

1059-
$response = wp_safe_remote_get(
1060+
$response = Visualizer_Remote_Fetch::request(
10601061
$url,
10611062
array(
1062-
'timeout' => 10,
1063-
'user-agent' => 'WordPress/' . get_bloginfo( 'version' ),
1064-
'headers' => array( 'Range' => 'bytes=0-3' ),
1065-
'stream' => true,
1066-
'filename' => $tmpfile,
1063+
'timeout' => 10,
1064+
'user-agent' => 'WordPress/' . get_bloginfo( 'version' ),
1065+
'headers' => array( 'Range' => 'bytes=0-3' ),
1066+
'stream' => true,
1067+
'filename' => $tmpfile,
1068+
'limit_response_size' => 4,
10671069
)
10681070
);
10691071

0 commit comments

Comments
 (0)