Plugin Updates
This commit is contained in:
@@ -98,7 +98,6 @@ function wpcf7dtx_validation_filter($result, $tag)
|
||||
return wpcf7dtx_validate_value($result, $user_value, $tag, $type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate Single Value
|
||||
*
|
||||
@@ -171,137 +170,132 @@ function wpcf7dtx_validate_value($result, $value, $tag, $type = '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Validator Requires Contact Form 7 Minimum Version
|
||||
* Backend Mail Configuration Validation
|
||||
*
|
||||
* Validate dynamic form tags used in mail configuration.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param WPCF7_ConfigValidator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
if (wpcf7dtx_dependencies()) {
|
||||
/**
|
||||
* Backend Mail Configuration Validation
|
||||
*
|
||||
* Validate dynamic form tags used in mail configuration.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param WPCF7_ConfigValidator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_validate($validator)
|
||||
{
|
||||
// Check for sensitive form tags
|
||||
$manager = WPCF7_FormTagsManager::get_instance();
|
||||
$contact_form = $validator->contact_form();
|
||||
$form = $contact_form->prop('form');
|
||||
if (wpcf7_autop_or_not()) {
|
||||
$form = $manager->replace_with_placeholders($form);
|
||||
$form = wpcf7_autop($form);
|
||||
$form = $manager->restore_from_placeholders($form);
|
||||
}
|
||||
$form = $manager->replace_all($form);
|
||||
$tags = $manager->get_scanned_tags();
|
||||
foreach ($tags as $tag) {
|
||||
/** @var WPCF7_FormTag $tag */
|
||||
function wpcf7dtx_validate($validator)
|
||||
{
|
||||
// Check for sensitive form tags
|
||||
$manager = WPCF7_FormTagsManager::get_instance();
|
||||
$contact_form = $validator->contact_form();
|
||||
$form = $contact_form->prop('form');
|
||||
if (wpcf7_autop_or_not()) {
|
||||
$form = $manager->replace_with_placeholders($form);
|
||||
$form = wpcf7_autop($form);
|
||||
$form = $manager->restore_from_placeholders($form);
|
||||
}
|
||||
$form = $manager->replace_all($form);
|
||||
$tags = $manager->get_scanned_tags();
|
||||
foreach ($tags as $tag) {
|
||||
/** @var WPCF7_FormTag $tag */
|
||||
|
||||
// Only validate DTX formtags
|
||||
if (in_array($tag->basetype, array_merge(
|
||||
array('dynamictext', 'dynamichidden'), // Deprecated DTX form tags
|
||||
array_keys(wpcf7dtx_config()) // DTX form tags
|
||||
))) {
|
||||
// Check value for sensitive data
|
||||
$default = $tag->get_option('defaultvalue', '', true);
|
||||
if (!$default) {
|
||||
$default = $tag->get_default_option(strval(reset($tag->values)));
|
||||
}
|
||||
if (
|
||||
!empty($value = trim(wpcf7_get_hangover($tag->name, $default))) && // Has value
|
||||
($result = wpcf7dtx_validate_sensitive_value($value))['status'] // Has sensitive data
|
||||
) {
|
||||
$validator->add_error('form.body', 'dtx_disallowed', array(
|
||||
'message' => sprintf(
|
||||
__('[%1$s %2$s]: Access to key "%3$s" in shortcode "%4$s" is disallowed by default. To allow access, add "%3$s" to the %5$s Allow List.', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html($tag->basetype),
|
||||
esc_html($tag->name),
|
||||
esc_html($result['key']),
|
||||
esc_html($result['shortcode']),
|
||||
esc_html($result['shortcode'] == 'CF7_get_current_user' ? __('User Data Key', 'contact-form-7-dynamic-text-extension') : __('Meta Key', 'contact-form-7-dynamic-text-extension'))
|
||||
),
|
||||
'link' => wpcf7dtx_get_admin_settings_screen_url()
|
||||
));
|
||||
}
|
||||
// Only validate DTX formtags
|
||||
if (in_array($tag->basetype, array_merge(
|
||||
array('dynamictext', 'dynamichidden'), // Deprecated DTX form tags
|
||||
array_keys(wpcf7dtx_config()) // DTX form tags
|
||||
))) {
|
||||
// Check value for sensitive data
|
||||
$default = $tag->get_option('defaultvalue', '', true);
|
||||
if (!$default) {
|
||||
$default = $tag->get_default_option(strval(reset($tag->values)));
|
||||
}
|
||||
if (
|
||||
!empty($value = trim(wpcf7_get_hangover($tag->name, $default))) && // Has value
|
||||
($result = wpcf7dtx_validate_sensitive_value($value))['status'] // Has sensitive data
|
||||
) {
|
||||
$validator->add_error('form.body', 'dtx_disallowed', array(
|
||||
'message' => sprintf(
|
||||
__('[%1$s %2$s]: Access to key "%3$s" in shortcode "%4$s" is disallowed by default. To allow access, add "%3$s" to the %5$s Allow List.', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html($tag->basetype),
|
||||
esc_html($tag->name),
|
||||
esc_html($result['key']),
|
||||
esc_html($result['shortcode']),
|
||||
esc_html($result['shortcode'] == 'CF7_get_current_user' ? __('User Data Key', 'contact-form-7-dynamic-text-extension') : __('Meta Key', 'contact-form-7-dynamic-text-extension'))
|
||||
),
|
||||
'link' => wpcf7dtx_get_admin_settings_screen_url()
|
||||
));
|
||||
}
|
||||
|
||||
// Check placeholder for sensitive data
|
||||
if (
|
||||
($tag->has_option('placeholder') || $tag->has_option('watermark')) && // Using placeholder
|
||||
!empty($placeholder = trim(html_entity_decode(urldecode($tag->get_option('placeholder', '', true)), ENT_QUOTES))) && // Has value
|
||||
($result = wpcf7dtx_validate_sensitive_value($placeholder))['status'] // Has sensitive data
|
||||
) {
|
||||
$validator->add_error('form.body', 'dtx_disallowed', array(
|
||||
'message' => sprintf(
|
||||
__('[%1$s %2$s]: Access to key "%3$s" in shortcode "%4$s" is disallowed by default. To allow access, add "%3$s" to the %5$s Allow List.', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html($tag->basetype),
|
||||
esc_html($tag->name),
|
||||
esc_html($result['key']),
|
||||
esc_html($result['shortcode']),
|
||||
esc_html($result['shortcode'] == 'CF7_get_current_user' ? __('User Data Key', 'contact-form-7-dynamic-text-extension') : __('Meta Key', 'contact-form-7-dynamic-text-extension'))
|
||||
),
|
||||
'link' => wpcf7dtx_get_admin_settings_screen_url()
|
||||
));
|
||||
}
|
||||
// Check placeholder for sensitive data
|
||||
if (
|
||||
($tag->has_option('placeholder') || $tag->has_option('watermark')) && // Using placeholder
|
||||
!empty($placeholder = trim(html_entity_decode(urldecode($tag->get_option('placeholder', '', true)), ENT_QUOTES))) && // Has value
|
||||
($result = wpcf7dtx_validate_sensitive_value($placeholder))['status'] // Has sensitive data
|
||||
) {
|
||||
$validator->add_error('form.body', 'dtx_disallowed', array(
|
||||
'message' => sprintf(
|
||||
__('[%1$s %2$s]: Access to key "%3$s" in shortcode "%4$s" is disallowed by default. To allow access, add "%3$s" to the %5$s Allow List.', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html($tag->basetype),
|
||||
esc_html($tag->name),
|
||||
esc_html($result['key']),
|
||||
esc_html($result['shortcode']),
|
||||
esc_html($result['shortcode'] == 'CF7_get_current_user' ? __('User Data Key', 'contact-form-7-dynamic-text-extension') : __('Meta Key', 'contact-form-7-dynamic-text-extension'))
|
||||
),
|
||||
'link' => wpcf7dtx_get_admin_settings_screen_url()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate email address
|
||||
if (!$validator->is_valid()) {
|
||||
$contact_form = null;
|
||||
$form_tags = null;
|
||||
foreach ($validator->collect_error_messages() as $component => $errors) {
|
||||
$components = explode('.', $component);
|
||||
if (count($components) === 2 && strpos($components[0], 'mail') === 0 && in_array($components[1], array('sender', 'recipient', 'additional_headers'))) {
|
||||
foreach ($errors as $error) {
|
||||
// Focus on email fields that flag the invalid mailbox syntax warning, have to test link because code isn't sent and message could be in any language
|
||||
if (strpos(wpcf7dtx_array_has_key('link', $error), 'invalid-mailbox-syntax') !== false) {
|
||||
if (is_null($contact_form)) {
|
||||
$contact_form = $validator->contact_form();
|
||||
}
|
||||
if (is_null($form_tags)) {
|
||||
$form_tags = wpcf7_scan_form_tags();
|
||||
}
|
||||
$raw_value = $contact_form->prop($components[0])[$components[1]];
|
||||
foreach ($form_tags as $tag) {
|
||||
if (!empty($tag->name)) {
|
||||
// Check if this form tag is in the raw value
|
||||
$form_tag = '[' . $tag->name . ']';
|
||||
if (strpos($raw_value, $form_tag) !== false && in_array($tag->basetype, array_keys(wpcf7dtx_config()))) {
|
||||
$validator->remove_error($component, 'invalid_mailbox_syntax'); // Remove error, this is ours to handle now
|
||||
$utm_source = urlencode(home_url());
|
||||
if (!in_array($tag->basetype, array('dynamic_hidden', 'dynamic_email'))) {
|
||||
$validator->add_error($component, 'invalid_mailbox_syntax', array(
|
||||
'message' => __('Only email, dynamic email, hidden, or dynamic hidden form tags can be used for email addresses.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-invalid_mailbox_syntax#valid-form-tags', $utm_source))
|
||||
// Validate email address
|
||||
if (!$validator->is_valid()) {
|
||||
$contact_form = null;
|
||||
$form_tags = null;
|
||||
foreach ($validator->collect_error_messages() as $component => $errors) {
|
||||
$components = explode('.', $component);
|
||||
if (count($components) === 2 && strpos($components[0], 'mail') === 0 && in_array($components[1], array('sender', 'recipient', 'additional_headers'))) {
|
||||
foreach ($errors as $error) {
|
||||
// Focus on email fields that flag the invalid mailbox syntax warning, have to test link because code isn't sent and message could be in any language
|
||||
if (strpos(wpcf7dtx_array_has_key('link', $error), 'invalid-mailbox-syntax') !== false) {
|
||||
if (is_null($contact_form)) {
|
||||
$contact_form = $validator->contact_form();
|
||||
}
|
||||
if (is_null($form_tags)) {
|
||||
$form_tags = wpcf7_scan_form_tags();
|
||||
}
|
||||
$raw_value = $contact_form->prop($components[0])[$components[1]];
|
||||
foreach ($form_tags as $tag) {
|
||||
if (!empty($tag->name)) {
|
||||
// Check if this form tag is in the raw value
|
||||
$form_tag = '[' . $tag->name . ']';
|
||||
if (strpos($raw_value, $form_tag) !== false && in_array($tag->basetype, array_keys(wpcf7dtx_config()))) {
|
||||
$validator->remove_error($component, 'invalid_mailbox_syntax'); // Remove error, this is ours to handle now
|
||||
$utm_source = urlencode(home_url());
|
||||
if (!in_array($tag->basetype, array('dynamic_hidden', 'dynamic_email'))) {
|
||||
$validator->add_error($component, 'invalid_mailbox_syntax', array(
|
||||
'message' => __('Only email, dynamic email, hidden, or dynamic hidden form tags can be used for email addresses.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-invalid_mailbox_syntax#valid-form-tags', $utm_source))
|
||||
));
|
||||
} else {
|
||||
$dynamic_value = wpcf7dtx_get_dynamic(false, $tag); // Get the dynamic value of this tag
|
||||
if (empty($dynamic_value) && $tag->basetype == 'dynamic_hidden') {
|
||||
$validator->add_error($component, 'maybe_empty', array(
|
||||
'message' => __('The dynamic hidden form tag must have a default value.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-maybe_empty#maybe-empty', $utm_source))
|
||||
));
|
||||
} else {
|
||||
$dynamic_value = wpcf7dtx_get_dynamic(false, $tag); // Get the dynamic value of this tag
|
||||
if (empty($dynamic_value) && $tag->basetype == 'dynamic_hidden') {
|
||||
$validator->add_error($component, 'maybe_empty', array(
|
||||
'message' => __('The dynamic hidden form tag must have a default value.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-maybe_empty#maybe-empty', $utm_source))
|
||||
} elseif (empty($dynamic_value) && !$tag->is_required()) {
|
||||
$validator->add_error($component, 'maybe_empty', array(
|
||||
'message' => __('The dynamic form tag must be required or have a default value.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-maybe_empty#maybe-empty', $utm_source))
|
||||
));
|
||||
} elseif (!empty($dynamic_value)) {
|
||||
if (!wpcf7_is_email($dynamic_value)) {
|
||||
$validator->add_error($component, 'invalid_mailbox_syntax', array(
|
||||
'message' => __('The default dynamic value does not result in a valid email address.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-invalid_mailbox_syntax#invalid-email-address', $utm_source))
|
||||
));
|
||||
} elseif (empty($dynamic_value) && !$tag->is_required()) {
|
||||
$validator->add_error($component, 'maybe_empty', array(
|
||||
'message' => __('The dynamic form tag must be required or have a default value.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-maybe_empty#maybe-empty', $utm_source))
|
||||
} elseif ($component[1] == 'sender' && !wpcf7_is_email_in_site_domain($dynamic_value)) {
|
||||
$validator->add_error($component, 'email_not_in_site_domain', array(
|
||||
'message' => __('The dynamic email address for the sender does not belong to the site domain.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-email_not_in_site_domain#invalid-site-domain', $utm_source))
|
||||
));
|
||||
} elseif (!empty($dynamic_value)) {
|
||||
if (!wpcf7_is_email($dynamic_value)) {
|
||||
$validator->add_error($component, 'invalid_mailbox_syntax', array(
|
||||
'message' => __('The default dynamic value does not result in a valid email address.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-invalid_mailbox_syntax#invalid-email-address', $utm_source))
|
||||
));
|
||||
} elseif ($component[1] == 'sender' && !wpcf7_is_email_in_site_domain($dynamic_value)) {
|
||||
$validator->add_error($component, 'email_not_in_site_domain', array(
|
||||
'message' => __('The dynamic email address for the sender does not belong to the site domain.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-email_not_in_site_domain#invalid-site-domain', $utm_source))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,9 +307,23 @@ if (wpcf7dtx_dependencies()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('wpcf7_config_validator_validate', 'wpcf7dtx_validate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Custom Mail Template Validator
|
||||
*
|
||||
* Validator requires a minimum version of Contact Form 7.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_init_validator()
|
||||
{
|
||||
if (wpcf7dtx_dependencies()) {
|
||||
add_action('wpcf7_config_validator_validate', 'wpcf7dtx_validate');
|
||||
}
|
||||
}
|
||||
add_action('plugins_loaded', 'wpcf7dtx_init_validator', 30);
|
||||
|
||||
|
||||
/**
|
||||
* Validate Field Value for Sensitive Data
|
||||
|
||||
Reference in New Issue
Block a user