Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/alt-manager/alt-manager.php
+++ b/alt-manager/alt-manager.php
@@ -10,7 +10,7 @@
* Plugin Name: Image Alt Text Manager
* plugin URI: https://wpsaad.com/alt-manager-wordpress-image-alt-text-plugin/
* Description:Automatically bulk change images alt text to dynamic alt tags values related to content or media and also generate empty values for both alt and title tags.
- * Version: 1.8.2
+ * Version: 1.8.3
* Author: WPSAAD
* Author URI: https://wpsaad.com
* License: GPLv2 or later
--- a/alt-manager/inc/alm-empty-generator.php
+++ b/alt-manager/inc/alm-empty-generator.php
@@ -133,7 +133,7 @@
if ( 'wpml-ls-flag' === $img->getAttribute( 'class' ) ) {
$next_sibling = $img->next_sibling();
if ( !empty( $next_sibling->innertext() ) ) {
- $img->setAttribute( 'alt', $next_sibling->innertext() );
+ $img->setAttribute( 'alt', esc_attr( $next_sibling->innertext() ) );
}
}
// Check if image already has alt/title set by alm-functions.php - skip if already set
@@ -144,11 +144,11 @@
if ( !$is_featured && $img->getAttribute( 'class' ) !== 'wpml-ls-flag' && !($has_alt && $has_title) ) {
// options
$options = [
- 'Site Name' => get_bloginfo( 'name' ),
- 'Site Description' => get_bloginfo( 'description' ),
- 'Page Title' => get_the_title( $ID ),
- 'Post Title' => get_post_field( 'post_title', $ID ),
- 'Product Title' => get_post_field( 'post_title', $ID ),
+ 'Site Name' => sanitize_text_field( get_bloginfo( 'name' ) ),
+ 'Site Description' => sanitize_text_field( get_bloginfo( 'description' ) ),
+ 'Page Title' => sanitize_text_field( get_the_title( $ID ) ),
+ 'Post Title' => sanitize_text_field( get_post_field( 'post_title', $ID ) ),
+ 'Product Title' => sanitize_text_field( get_post_field( 'post_title', $ID ) ),
];
//wp image attachment data
if ( wp_attachment_is_image( $attachment_id ) ) {
@@ -169,8 +169,8 @@
if ( $logo_checker ) {
$alt = $options['Site Name'];
$title = $options['Site Name'];
- $img->setAttribute( 'alt', $alt );
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
+ $img->setAttribute( 'title', esc_attr( $title ) );
}
if ( !$logo_checker ) {
//check page type
@@ -191,11 +191,11 @@
}
//Empty alt option
if ( 'enabled' === $generate_empty_alt && empty( $img->getAttribute( 'alt' ) ) ) {
- $img->setAttribute( 'alt', $alt );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
} elseif ( 'enabled' === $generate_empty_alt && !empty( $img->getAttribute( 'alt' ) ) ) {
- $img->setAttribute( 'alt', $img->getAttribute( 'alt' ) );
+ $img->setAttribute( 'alt', esc_attr( $img->getAttribute( 'alt' ) ) );
} else {
- $img->setAttribute( 'alt', $alt );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
}
//page images title
if ( !empty( alm_get_option( 'pages_images_title' ) ) && is_array( alm_get_option( 'pages_images_title' ) ) ) {
@@ -211,11 +211,11 @@
}
//Empty title option
if ( 'enabled' === $generate_empty_title && empty( $img->getAttribute( 'title' ) ) ) {
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'title', esc_attr( $title ) );
} elseif ( 'enabled' === $generate_empty_title && !empty( $img->getAttribute( 'title' ) ) ) {
- $img->setAttribute( 'title', $img->getAttribute( 'title' ) );
+ $img->setAttribute( 'title', esc_attr( $img->getAttribute( 'title' ) ) );
} else {
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'title', esc_attr( $title ) );
}
}
//check homepage - use original page ID, not extracted product ID
@@ -225,8 +225,8 @@
$alt = '';
$title = '';
if ( 'page' !== alm_get_option( 'show_on_front' ) && !empty( alm_get_option( 'show_on_front' ) ) ) {
- $img->setAttribute( 'alt', $options['Site Name'] );
- $img->setAttribute( 'title', $options['Site Name'] );
+ $img->setAttribute( 'alt', esc_attr( $options['Site Name'] ) );
+ $img->setAttribute( 'title', esc_attr( $options['Site Name'] ) );
} else {
//Homepage images alt
if ( !empty( alm_get_option( 'home_images_alt' ) ) && is_array( alm_get_option( 'home_images_alt' ) ) ) {
@@ -242,11 +242,11 @@
}
//Empty alt option
if ( 'enabled' === $generate_empty_alt && empty( $img->getAttribute( 'alt' ) ) ) {
- $img->setAttribute( 'alt', $alt );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
} elseif ( 'enabled' === $generate_empty_alt && !empty( $img->getAttribute( 'alt' ) ) ) {
- $img->setAttribute( 'alt', $img->getAttribute( 'alt' ) );
+ $img->setAttribute( 'alt', esc_attr( $img->getAttribute( 'alt' ) ) );
} else {
- $img->setAttribute( 'alt', $alt );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
}
//Homepage images title
if ( !empty( alm_get_option( 'home_images_title' ) ) && is_array( alm_get_option( 'home_images_title' ) ) ) {
@@ -262,11 +262,11 @@
}
//Empty title option
if ( 'enabled' === $generate_empty_title && empty( $img->getAttribute( 'title' ) ) ) {
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'title', esc_attr( $title ) );
} elseif ( 'enabled' === $generate_empty_title && !empty( $img->getAttribute( 'title' ) ) ) {
- $img->setAttribute( 'title', $img->getAttribute( 'title' ) );
+ $img->setAttribute( 'title', esc_attr( $img->getAttribute( 'title' ) ) );
} else {
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'title', esc_attr( $title ) );
}
}
}
@@ -288,11 +288,11 @@
}
//Empty alt option
if ( 'enabled' === $generate_empty_alt && empty( $img->getAttribute( 'alt' ) ) ) {
- $img->setAttribute( 'alt', $alt );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
} elseif ( 'enabled' === $generate_empty_alt && !empty( $img->getAttribute( 'alt' ) ) ) {
- $img->setAttribute( 'alt', $img->getAttribute( 'alt' ) );
+ $img->setAttribute( 'alt', esc_attr( $img->getAttribute( 'alt' ) ) );
} else {
- $img->setAttribute( 'alt', $alt );
+ $img->setAttribute( 'alt', esc_attr( $alt ) );
}
//post images title
if ( !empty( alm_get_option( 'post_images_title' ) ) && is_array( alm_get_option( 'post_images_title' ) ) ) {
@@ -308,11 +308,11 @@
}
//Empty title option
if ( 'enabled' === $generate_empty_title && empty( $img->getAttribute( 'title' ) ) ) {
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'title', esc_attr( $title ) );
} elseif ( 'enabled' === $generate_empty_title && !empty( $img->getAttribute( 'title' ) ) ) {
- $img->setAttribute( 'title', $img->getAttribute( 'title' ) );
+ $img->setAttribute( 'title', esc_attr( $img->getAttribute( 'title' ) ) );
} else {
- $img->setAttribute( 'title', $title );
+ $img->setAttribute( 'title', esc_attr( $title ) );
}
}
}
@@ -351,11 +351,11 @@
return;
}
$replacements = [
- 'Site Name' => get_bloginfo( 'name' ),
- 'Site Description' => get_bloginfo( 'description' ),
- 'Page Title' => get_the_title( $ID ),
- 'Post Title' => get_post_field( 'post_title', $ID ),
- 'Product Title' => get_post_field( 'post_title', $ID ),
+ 'Site Name' => sanitize_text_field( get_bloginfo( 'name' ) ),
+ 'Site Description' => sanitize_text_field( get_bloginfo( 'description' ) ),
+ 'Page Title' => sanitize_text_field( get_the_title( $ID ) ),
+ 'Post Title' => sanitize_text_field( get_post_field( 'post_title', $ID ) ),
+ 'Product Title' => sanitize_text_field( get_post_field( 'post_title', $ID ) ),
];
$alt_keys = alm_get_option( "{$context}_images_alt" );
$title_keys = alm_get_option( "{$context}_images_title" );
@@ -374,8 +374,8 @@
return;
}
// Decode for raw readable characters
- $alt_output = htmlspecialchars_decode( $alt_final, ENT_QUOTES );
- $title_output = htmlspecialchars_decode( $title_final, ENT_QUOTES );
+ $alt_output = esc_attr( $alt_final );
+ $title_output = esc_attr( $title_final );
// Enqueue script properly
wp_enqueue_script(
'alm-frontend',
--- a/alt-manager/inc/alm-functions.php
+++ b/alt-manager/inc/alm-functions.php
@@ -31,11 +31,11 @@
$ID = get_the_ID();
// options
$options = [
- 'Site Name' => get_bloginfo( 'name' ),
- 'Site Description' => get_bloginfo( 'description' ),
- 'Page Title' => get_the_title( $ID ),
- 'Post Title' => get_post_field( 'post_title', $ID ),
- 'Product Title' => get_post_field( 'post_title', $ID ),
+ 'Site Name' => sanitize_text_field( get_bloginfo( 'name' ) ),
+ 'Site Description' => sanitize_text_field( get_bloginfo( 'description' ) ),
+ 'Page Title' => sanitize_text_field( get_the_title( $ID ) ),
+ 'Post Title' => sanitize_text_field( get_post_field( 'post_title', $ID ) ),
+ 'Product Title' => sanitize_text_field( get_post_field( 'post_title', $ID ) ),
];
//wp image attachment data
if ( wp_attachment_is_image( $attachment->ID ) ) {
@@ -64,11 +64,11 @@
}
//Empty alt option
if ( 'enabled' === $generate_empty_alt && empty( $attr['alt'] ) ) {
- $attr['alt'] = $alt;
+ $attr['alt'] = esc_attr( $alt );
} elseif ( 'enabled' === $generate_empty_alt && !empty( $attr['alt'] ) ) {
- $attr['alt'] = $attr['alt'];
+ $attr['alt'] = esc_attr( $attr['alt'] );
} else {
- $attr['alt'] = $alt;
+ $attr['alt'] = esc_attr( $alt );
}
//Page images title
if ( !empty( alm_get_option( 'pages_images_title' ) ) && is_array( alm_get_option( 'pages_images_title' ) ) ) {
@@ -84,11 +84,11 @@
}
//Empty title option
if ( 'enabled' === $generate_empty_title && empty( get_the_title( $attachment->ID ) ) ) {
- $attr['title'] = $title;
+ $attr['title'] = esc_attr( $title );
} elseif ( 'enabled' === $generate_empty_title && !empty( get_the_title( $attachment->ID ) ) ) {
- $attr['title'] = get_the_title( $attachment->ID );
+ $attr['title'] = esc_attr( get_the_title( $attachment->ID ) );
} else {
- $attr['title'] = $title;
+ $attr['title'] = esc_attr( $title );
}
}
//check homepage
@@ -108,11 +108,11 @@
$alt = $options[alm_get_option( 'home_images_alt' )];
}
if ( 'enabled' === $generate_empty_alt && empty( $attr['alt'] ) ) {
- $attr['alt'] = $alt;
+ $attr['alt'] = esc_attr( $alt );
} elseif ( 'enabled' === $generate_empty_alt && !empty( $attr['alt'] ) ) {
- $attr['alt'] = $attr['alt'];
+ $attr['alt'] = esc_attr( $attr['alt'] );
} else {
- $attr['alt'] = $alt;
+ $attr['alt'] = esc_attr( $alt );
}
//Homepage images title
if ( !empty( alm_get_option( 'home_images_title' ) ) && is_array( alm_get_option( 'home_images_title' ) ) ) {
@@ -128,11 +128,11 @@
}
//Empty title option
if ( 'enabled' === $generate_empty_title && empty( get_the_title( $attachment->ID ) ) ) {
- $attr['title'] = $title;
+ $attr['title'] = esc_attr( $title );
} elseif ( 'enabled' === $generate_empty_title && !empty( get_the_title( $attachment->ID ) ) ) {
- $attr['title'] = get_the_title( $attachment->ID );
+ $attr['title'] = esc_attr( get_the_title( $attachment->ID ) );
} else {
- $attr['title'] = $title;
+ $attr['title'] = esc_attr( $title );
}
}
//check post type
@@ -153,11 +153,11 @@
}
//Empty alt option
if ( 'enabled' === $generate_empty_alt && empty( $attr['alt'] ) ) {
- $attr['alt'] = $alt;
+ $attr['alt'] = esc_attr( $alt );
} elseif ( 'enabled' === $generate_empty_alt && !empty( $attr['alt'] ) ) {
- $attr['alt'] = $attr['alt'];
+ $attr['alt'] = esc_attr( $attr['alt'] );
} else {
- $attr['alt'] = $alt;
+ $attr['alt'] = esc_attr( $alt );
}
//Posts images title
if ( !empty( alm_get_option( 'post_images_title' ) ) && is_array( alm_get_option( 'post_images_title' ) ) ) {
@@ -173,11 +173,11 @@
}
//Empty title option
if ( 'enabled' === $generate_empty_title && empty( get_the_title( $attachment->ID ) ) ) {
- $attr['title'] = $title;
+ $attr['title'] = esc_attr( $title );
} elseif ( 'enabled' === $generate_empty_title && !empty( get_the_title( $attachment->ID ) ) ) {
- $attr['title'] = get_the_title( $attachment->ID );
+ $attr['title'] = esc_attr( get_the_title( $attachment->ID ) );
} else {
- $attr['title'] = $title;
+ $attr['title'] = esc_attr( $title );
}
}
return $attr;