Skip to content

Commit

Permalink
Ensure global is set before accessing. Add PHPCS ignore flags for uns…
Browse files Browse the repository at this point in the history
…lashed and unsanitized input.
  • Loading branch information
TylerB24890 committed Aug 28, 2024
1 parent 5aeb863 commit 138f856
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions includes/optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ public function optimize() {
$svg_id = filter_input( INPUT_GET, 'svg_id', FILTER_SANITIZE_NUMBER_INT );
$attachment_id = ! empty( $svg_id ) ? $svg_id : attachment_url_to_postid( $svg_url );

if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
if (
empty( $_GET['optimized_svg'] ) ||
empty( $attachment_id ) ||
! current_user_can( 'edit_post', $attachment_id )
) {
return;
}

Expand All @@ -166,10 +170,10 @@ public function optimize() {
return;
}

$maybe_dirty = $_GET['optimized_svg'];
$maybe_dirty = stripcslashes( $_GET['optimized_svg'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$sanitizer = new Sanitizer();
$sanitizer->minify( true );
$sanitized = $sanitizer->sanitize( stripcslashes( $maybe_dirty ) );
$sanitized = $sanitizer->sanitize( $maybe_dirty );

if ( empty( $sanitized ) ) {
return;
Expand Down

0 comments on commit 138f856

Please sign in to comment.