Skip to content

Commit ffdc1fa

Browse files
Merge pull request #547 from iftakharul-islam/fix/svg-sanitization
Fix/svg sanitization
2 parents 4165b8c + ce21195 commit ffdc1fa

12 files changed

Lines changed: 103 additions & 64 deletions

File tree

bootstrap/loaders.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use WeDevs\PM\Core\Router\WP_Router;
66
use WeDevs\PM\Core\Database\Migrater;
77
use WeDevs\PM\Core\WP\Frontend;
8+
use enshrined\svgSanitize\Sanitizer;
89

910
function pm_load_configurations() {
1011
$files = glob( __DIR__ . "/../config/*.php" );
@@ -158,3 +159,24 @@ function pm_init_tracker() {
158159

159160
$insights->init_plugin();
160161
}
162+
163+
function pm_clean_svg() {
164+
add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename, $mimes ) {
165+
if ( $data['ext'] === 'svg' ) {
166+
$sanitizer = new Sanitizer();
167+
// Check if file exists and is readable
168+
if ( file_exists( $file ) && is_readable( $file ) ) {
169+
$dirtySVG = file_get_contents( $file );
170+
if ( $dirtySVG !== false ) {
171+
$cleanSVG = $sanitizer->sanitize( $dirtySVG );
172+
// Check if sanitization was successful
173+
if ( $cleanSVG !== false && is_writable( $file ) ) {
174+
file_put_contents( $file, $cleanSVG );
175+
}
176+
}
177+
}
178+
}
179+
180+
return $data;
181+
}, 10, 4 );
182+
}

bootstrap/start.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
pm_view();
2121
pm_load_routes();
2222
pm_register_routes();
23-
23+
pm_clean_svg();
2424
do_action( 'pm_loaded' );
2525

2626
add_action('init', 'pm_init_tracker');

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
== Changelog ==
22

3+
= v2.6.23 - Apr 8, 2025 =
4+
5+
**Added:** SVG file upload sanitization & security improvmenet.
6+
37
= v2.6.22 - Mar 7, 2025 =
48

59
**Improved:** Readme.txt file.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"a5hleyrich/wp-background-processing": "^1.0",
2626
"tareq1988/wp-eloquent": "dev-master",
2727
"appsero/client": "^1.2",
28-
"simshaun/recurr": "^4.0"
28+
"simshaun/recurr": "^4.0",
29+
"enshrined/svg-sanitize": "^0.21.0"
2930
},
3031
"autoload": {
3132
"classmap": [

composer.lock

Lines changed: 47 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
return [
44
'name' => 'Project Manager',
55
'slug' => 'pm',
6-
'version' => '2.6.22',
6+
'version' => '2.6.23',
77
'api' => '2',
88
'db_version' => '2.5',
99
'text_domain' => 'pm',

cpm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: WordPress Project Management plugin. Manage your projects and tasks, get things done.
66
* Author: weDevs
77
* Author URI: https://wedevs.com
8-
* Version: 2.6.22
8+
* Version: 2.6.23
99
* Text Domain: wedevs-project-manager
1010
* Domain Path: /languages
1111
* License: GPL2

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pmapi",
3-
"version": "2.6.22",
3+
"version": "2.6.23",
44
"description": "Front-end package manager for project manager",
55
"main": "index.js",
66
"directories": {

readme.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: project, project manager, project management, project management plugin, p
55
Requires at least: 4.4 or higher
66
Tested up to: 6.7.2
77
Requires PHP: 5.6
8-
Stable tag: 2.6.22
8+
Stable tag: 2.6.23
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -21,7 +21,7 @@ Its user-friendly interface and web-based task management feature enable the use
2121

2222
Why wait, effortlessly manage projects, track time, and generate performance reports with this project management solution.
2323

24-
[youtube https://www.youtube.com/watch?v=GI4u8wXOxHg&list=PLJorZsV2RVv82Xe9ReXngU6Wk1RN0EwHu&ab\_channel=weDevs\]
24+
[youtube https://www.youtube.com/watch?v=GI4u8wXOxHg]
2525

2626
Want to give it a try?
2727
👉 [TRY FREE OFFICIAL DEMO](https://pm.wedevsdemos.com/wp-login.php)
@@ -243,6 +243,10 @@ A. Found any bugs? Please create an [issue](https://github.com/tareq1988/wp-proj
243243

244244
== Changelog ==
245245

246+
= v2.6.23 - Apr 8, 2025 =
247+
248+
**Added:** SVG file upload sanitization & security improvmenet.
249+
246250
= v2.6.22 - Mar 7, 2025 =
247251

248252
**Improved:** Readme.txt file.

src/Comment/Controllers/Comment_Controller.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@ public function store( WP_REST_Request $request ) {
8080
$commentable_id = $request->get_param('commentable_id');
8181

8282
$files = array_key_exists( 'files', $media_data ) ? $media_data['files'] : null;
83-
84-
if( HelperFile::check_file_for_xss_code( $files ) ){
85-
return wp_send_json(
86-
[
87-
'error_type' => 'svg_xss',
88-
'message' => __( 'The SVG file you attempted to upload contains content that may pose security risks. Please ensure your file is safe and try again.', 'pm-pro' )
89-
], 400
90-
);
91-
wp_die();
92-
}
9383

9484
$comment = Comment::create( $data );
9585

@@ -127,16 +117,6 @@ public function update( WP_REST_Request $request ) {
127117
// An array of files
128118
$files = array_key_exists( 'files', $media_data ) ? $media_data['files'] : null;
129119

130-
if( HelperFile::check_file_for_xss_code( $files ) ){
131-
return wp_send_json(
132-
[
133-
'error_type' => 'svg_xss',
134-
'message' => __( 'The SVG file you attempted to upload contains content that may pose security risks. Please ensure your file is safe and try again.', 'pm-pro' )
135-
], 400
136-
);
137-
wp_die();
138-
}
139-
140120
// An array of file ids that needs to be deleted
141121
$files_to_delete = $request->get_param( 'files_to_delete' );
142122

0 commit comments

Comments
 (0)