Skip to content

Commit ea7e56c

Browse files
committed
Enhance file upload handling by sanitizing accepted file types in admin settings and custom fields. Additionally, sanitize Content-Type in post endpoints to prevent HTTP header injection, ensuring improved security and data integrity.
1 parent b2bc0a2 commit ea7e56c

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

dt-core/admin/admin-settings-endpoints.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ public static function edit_field( WP_REST_Request $request ) {
12991299
if ( isset( $post_fields[$field_key]['type'] ) && $post_fields[$field_key]['type'] === 'file_upload' ) {
13001300
// Accepted file types
13011301
if ( isset( $post_submission['visibility']['accepted_file_types'] ) && !empty( $post_submission['visibility']['accepted_file_types'] ) ) {
1302-
$types = array_map( 'trim', explode( ',', $post_submission['visibility']['accepted_file_types'] ) );
1302+
$types = array_map( 'sanitize_text_field', array_map( 'trim', explode( ',', $post_submission['visibility']['accepted_file_types'] ) ) );
13031303
$custom_field['accepted_file_types'] = $types;
13041304
}
13051305

dt-core/admin/menu/tabs/tab-custom-fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ private function process_edit_field( $post_submission ){
10701070
if ( $field['type'] === 'file_upload' ) {
10711071
// Accepted file types
10721072
if ( isset( $post_submission['accepted_file_types'] ) && !empty( $post_submission['accepted_file_types'] ) ) {
1073-
$types = array_map( 'trim', explode( ',', $post_submission['accepted_file_types'] ) );
1073+
$types = array_map( 'sanitize_text_field', array_map( 'trim', explode( ',', $post_submission['accepted_file_types'] ) ) );
10741074
$custom_field['accepted_file_types'] = $types;
10751075
}
10761076

dt-posts/dt-posts-endpoints.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,12 @@ public function storage_download( WP_REST_Request $request ) {
15041504
}
15051505
}
15061506

1507+
// Sanitize Content-Type to prevent HTTP header injection (e.g. newlines from S3 or meta).
1508+
$content_type = sanitize_mime_type( $content_type );
1509+
if ( $content_type === '' ) {
1510+
$content_type = 'application/octet-stream';
1511+
}
1512+
15071513
// Set headers for file download
15081514
header( 'Content-Type: ' . $content_type );
15091515
header( 'Content-Disposition: attachment; filename="' . esc_attr( $file_name ) . '"' );

0 commit comments

Comments
 (0)