Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix uploading xss contained file with multiple svg file where first f… #502

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Comment/Controllers/Comment_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public function store( WP_REST_Request $request ) {

$files = array_key_exists( 'files', $media_data ) ? $media_data['files'] : null;

$file_type = $files['type'][0];

if( HelperFile::check_file_for_xss_code( $file_type, $files ) ){
if( HelperFile::check_file_for_xss_code( $files ) ){
return wp_send_json(
[
'error_type' => 'svg_xss',
Expand Down Expand Up @@ -129,9 +127,7 @@ public function update( WP_REST_Request $request ) {
// An array of files
$files = array_key_exists( 'files', $media_data ) ? $media_data['files'] : null;

$file_type = $files['type'][0];

if( HelperFile::check_file_for_xss_code( $file_type, $files ) ){
if( HelperFile::check_file_for_xss_code( $files ) ){
return wp_send_json(
[
'error_type' => 'svg_xss',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public function store( WP_REST_Request $request ) {
$milestone_id = $request->get_param( 'milestone' );
$files = array_key_exists( 'files', $media_data ) ? $media_data['files'] : null;

$file_type = $files['type'][0];

if( HelperFile::check_file_for_xss_code( $file_type, $files ) ){
if( HelperFile::check_file_for_xss_code( $files ) ){
return wp_send_json(
[
'error_type' => 'svg_xss',
Expand Down Expand Up @@ -121,9 +119,7 @@ public function update( WP_REST_Request $request ) {
$files = array_key_exists( 'files', $media_data ) ? $media_data['files'] : null;
$files_to_delete = $request->get_param( 'files_to_delete' );

$file_type = $files['type'][0];

if( HelperFile::check_file_for_xss_code( $file_type, $files ) ){
if( HelperFile::check_file_for_xss_code( $files ) ){
return wp_send_json(
[
'error_type' => 'svg_xss',
Expand Down
25 changes: 15 additions & 10 deletions src/File/Helper/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ public static function get_results( $params = [] ) {
return $response;
}

public static function check_file_for_xss_code( $file_type, $files ) {
if ( $file_type === 'image/svg+xml' ) {
$svg_tmp_name = $files['tmp_name'][0];

$svg_content = file_get_contents($svg_tmp_name);

if ( self::contains_xss_code($svg_content) ) {
return true;
}
}
public static function check_file_for_xss_code( $files ) {
if (isset($files['type']) && is_array($files['type'])) {

foreach ($files['type'] as $index => $file_type) {

if ($file_type === 'image/svg+xml') {
$svg_tmp_name = $files['tmp_name'][$index];
$svg_content = file_get_contents($svg_tmp_name);

if (self::contains_xss_code($svg_content)) {
return true;
}
}
}
}

return false;
}
Expand Down