Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/groundhogg/api/v4/contacts-api.php
+++ b/groundhogg/api/v4/contacts-api.php
@@ -238,21 +238,22 @@
/**
* Unable to edit
*
- * @param $contact Contact
- *
* @return WP_Error
*/
- public static function ERROR_INVALID_PERMISSIONS_CANT_EDIT( $contact ) {
+ public static function ERROR_INVALID_PERMISSIONS_CANT_VIEW() {
+ return self::ERROR_401( 'error', 'You do not have sufficient permissions to view this contact.' );
+ }
- if ( ! is_a_contact( $contact ) || ! $contact->exists() ) {
- return self::ERROR_401( 'error', 'The requested contact does not exist.', [
- 'given' => $contact
- ] );
- }
- return self::ERROR_401( 'error', 'You do not have sufficient permissions to edit this contact.', [
- 'id' => $contact->get_id()
- ] );
+ /**
+ * Unable to edit
+ *
+ * @param $contact Contact
+ *
+ * @return WP_Error
+ */
+ public static function ERROR_INVALID_PERMISSIONS_CANT_EDIT() {
+ return self::ERROR_401( 'error', 'You do not have sufficient permissions to edit this contact.' );
}
/**
@@ -433,6 +434,10 @@
return $this->ERROR_RESOURCE_NOT_FOUND();
}
+ if ( ! current_user_can( 'view_contact', $object ) ){
+ return self::ERROR_INVALID_PERMISSIONS_CANT_VIEW();
+ }
+
return self::SUCCESS_RESPONSE( [ 'item' => $object ] );
}
@@ -448,7 +453,12 @@
// First order stuff
if ( $request->has_param( 'email' ) ) {
$fields = $request->get_json_params();
- $existed = is_email_address_in_use( $request->get_param( 'email' ) );
+ $email_address = $request->get_param( 'email' );
+ $existed = is_email_address_in_use( $email_address );
+
+ if ( $existed && ! current_user_can( 'edit_contact', $email_address ) ) {
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
+ }
try {
$contact = generate_contact_with_map( $fields, [], [
@@ -495,6 +505,11 @@
if ( is_email_address_in_use( $email_address ) ) {
$existed = true;
$contact = new Contact( $email_address );
+
+ if ( ! current_user_can( 'edit_contact', $contact ) ) {
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
+ }
+
$contact->update( $data );
} // Create new contact record
else {
@@ -534,7 +549,7 @@
}
if ( ! current_user_can( 'edit_contact', $contact ) ) {
- return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT( $contact );
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
}
$add_tag_params = [ 'tags', 'add_tags', 'apply_tags' ];
@@ -602,6 +617,10 @@
return $this->ERROR_RESOURCE_NOT_FOUND();
}
+ if ( ! current_user_can( 'delete_contact', $object ) ) {
+ return self::ERROR_401( 'error', 'You do not have sufficient permissions to delete this contact.' );
+ }
+
$object->delete();
$this->do_object_deleted_action( $object );
@@ -684,7 +703,7 @@
}
if ( ! current_user_can( 'edit_contact', $contact ) ) {
- return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT( $contact );
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
}
$tags = $request->get_json_params();
@@ -713,7 +732,7 @@
}
if ( ! current_user_can( 'view_contact', $contact ) ) {
- return self::ERROR_401();
+ return self::ERROR_INVALID_PERMISSIONS_CANT_VIEW();
}
return self::SUCCESS_RESPONSE( [ 'tags' => $contact->get_tags() ] );
@@ -747,7 +766,7 @@
}
if ( ! current_user_can( 'edit_contact', $contact ) ) {
- return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT( $contact );
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
}
$tags = $request->get_json_params();
@@ -774,6 +793,10 @@
return self::ERROR_CONTACT_NOT_FOUND();
}
+ if ( ! current_user_can( 'edit_contact', $contact ) ) {
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
+ }
+
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- API KEY previously validated
if ( empty( $_FILES ) ) {
return self::ERROR_422( 'error', 'No files provided.' );
@@ -811,6 +834,10 @@
return self::ERROR_CONTACT_NOT_FOUND();
}
+ if ( ! current_user_can( 'view_contact', $contact ) ) {
+ return self::ERROR_INVALID_PERMISSIONS_CANT_VIEW();
+ }
+
$data = $contact->get_files();
$limit = absint( $request->get_param( 'limit' ) ) ?: 25;
@@ -873,7 +900,7 @@
}
if ( ! current_user_can( 'edit_contact', $contact ) ) {
- return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT( $contact );
+ return self::ERROR_INVALID_PERMISSIONS_CANT_EDIT();
}
$others = $request->has_param( 'others' )
@@ -902,6 +929,10 @@
return self::ERROR_CONTACT_NOT_FOUND();
}
+ if ( ! current_user_can( 'view_contact', $contact ) ) {
+ return self::ERROR_INVALID_PERMISSIONS_CANT_VIEW();
+ }
+
$msgs = Plugin::instance()->imap_inbox->fetch( $contact );
return self::SUCCESS_RESPONSE( [
@@ -1021,7 +1052,7 @@
$contact = get_contactdata( $request->get_param( 'contact' ) );
if ( ! current_user_can( 'view_contact', $contact ) ) {
- return self::ERROR_401();
+ return self::ERROR_INVALID_PERMISSIONS_CANT_VIEW();
}
$contactTable = new Contacts_Table;
--- a/groundhogg/groundhogg.php
+++ b/groundhogg/groundhogg.php
@@ -3,7 +3,7 @@
* Plugin Name: Groundhogg
* Plugin URI: https://www.groundhogg.io/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
* Description: CRM and marketing automation for WordPress
- * Version: 4.5.2
+ * Version: 4.5.3
* Author: Groundhogg Inc.
* Author URI: https://www.groundhogg.io/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
* Text Domain: groundhogg
@@ -24,7 +24,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-define( 'GROUNDHOGG_VERSION', '4.5.2' );
+define( 'GROUNDHOGG_VERSION', '4.5.3' );
define( 'GROUNDHOGG_PREVIOUS_STABLE_VERSION', '4.5' );
define( 'GROUNDHOGG__FILE__', __FILE__ );
--- a/groundhogg/includes/filters.php
+++ b/groundhogg/includes/filters.php
@@ -583,7 +583,7 @@
*/
function remove_font_family_quotes( $html ) {
return preg_replace_callback(
- '/font-familys*:s*([^;]+)(;?)/i',
+ '/font-familys*:s*([^";]+)(;?)/i', // added `"` because inline style rule might not preserve ending `;`
function ( $matches ) {
$fonts = $matches[1];
@@ -643,7 +643,7 @@
];
return preg_replace_callback(
- '/font-familys*:s*([^;]+)(;?)/i',
+ '/font-familys*:s*([^;"]+)(;?)/i', // added `"` because inline style rule might not preserve ending `;`
function ( $matches ) use ( $generic_fonts, $css_keywords ) {
$value = trim( $matches[1] );