Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/tracking-code-manager/includes/admin/editor.php
+++ b/tracking-code-manager/includes/admin/editor.php
@@ -32,7 +32,7 @@
?>
<div style="clear:both; margin-top: 2px;"></div>
<div style="float:left; vertical-align:middle; height:24px; margin-right:5px; margin-top:-5px;">
- <img src="<?php echo TCMP_PLUGIN_IMAGES_URI; ?>tick.png" />
+ <img src="<?php echo esc_url( TCMP_PLUGIN_IMAGES_URI . 'tick.png' ); ?>" />
</div>
<div style="float:left; vertical-align:middle; height:24px;">
<?php $tcmp->lang->P( 'Notice.ProFeature' . $i, $q ); ?>
@@ -48,7 +48,7 @@
$url = TCMP_PAGE_PREMIUM . '?utm_source=free-users&utm_medium=wp-cta&utm_campaign=wp-plugin';
?>
<a href="<?php echo esc_url( $url ); ?>" target="_blank">
- <b><?php esc_html( $tcmp->lang->P( 'Notice.ProCTA' ) ); ?></b>
+ <b><?php $tcmp->lang->P( 'Notice.ProCTA' ); ?></b>
</a>
</div>
<div style="height:10px; clear:both;"></div>
--- a/tracking-code-manager/includes/admin/manager.php
+++ b/tracking-code-manager/includes/admin/manager.php
@@ -37,8 +37,8 @@
if ( count( $snippets ) > 0 ) { ?>
<div style="float:left;">
<form method="get" action="" style="margin:5px; float:left;">
- <input type="hidden" name="page" value="<?php echo TCMP_PLUGIN_SLUG; ?>" />
- <input type="hidden" name="tab" value="<?php echo TCMP_TAB_EDITOR; ?>" />
+ <input type="hidden" name="page" value="<?php echo esc_attr( TCMP_PLUGIN_SLUG ); ?>" />
+ <input type="hidden" name="tab" value="<?php echo esc_attr( TCMP_TAB_EDITOR ); ?>" />
<input type="submit" class="button-primary" value="<?php $tcmp->lang->P( 'Button.Add' ); ?>" />
</form>
</div>
@@ -74,9 +74,10 @@
$text = 'Yes';
$question = 'QuestionActiveOff';
}
- $text = '<span style="font-weight:bold; color:' . $color . '">' . $tcmp->lang->L( $text ) . '</span>';
+ $text = '<span style="font-weight:bold; color:' . $color . '">' . $tcmp->lang->L( $text ) . '</span>';
+ $toggle_url = TCMP_TAB_MANAGER_URI . '&tcmp_nonce=' . wp_create_nonce( 'tcmp_toggle' ) . '&action=toggle&id=' . $snippet['id'];
?>
- <a onclick="return confirm('<?php echo esc_attr( $tcmp->lang->L( $question ) ); ?>');" href="<?php echo TCMP_TAB_MANAGER_URI; ?>&tcmp_nonce=<?php echo esc_attr( wp_create_nonce( 'tcmp_toggle' ) ); ?>&action=toggle&id=<?php echo esc_attr( $snippet['id'] ); ?>">
+ <a onclick="return confirm('<?php echo esc_js( $tcmp->lang->L( $question ) ); ?>');" href="<?php echo esc_url( $toggle_url ); ?>">
<?php echo wp_kses( $text, $tcmp_allowed_html_tags ); ?>
</a>
</td>
@@ -92,14 +93,14 @@
} else {
$text = 'Conversion';
}
- esc_html( $tcmp->lang->P( $text ) );
+ $tcmp->lang->P( $text );
?>
</td>
<td style="text-align:center;">
<input type="text" style="width:110px; text-align:center;" value='[tcm id="<?php echo esc_html( $snippet['id'] ); ?>"]' readonly="readonly" class="tcmp-select-onfocus" />
</td>
<td style="text-align:center;">
- <input type="button" class="button button-secondary" value="<?php $tcmp->lang->P( 'Edit' ); ?>" onclick="location.href='<?php echo TCMP_TAB_EDITOR_URI; ?>&id=<?php echo esc_attr( $snippet['id'] ); ?>';"/>
+ <input type="button" class="button button-secondary" value="<?php $tcmp->lang->P( 'Edit' ); ?>" onclick="location.href='<?php echo esc_url( TCMP_TAB_EDITOR_URI . '&id=' . $snippet['id'] ); ?>';"/>
<input type="button" class="button button-secondary" value="<?php $tcmp->lang->P( 'Delete?' ); ?>" onclick="TCMP_btnDeleteClick(<?php echo esc_attr( $snippet['id'] ); ?>)"/>
</td>
</tr>
--- a/tracking-code-manager/includes/admin/metabox.php
+++ b/tracking-code-manager/includes/admin/metabox.php
@@ -28,7 +28,7 @@
<div>
<?php $tcmp->lang->P( 'Select existing Tracking Code' ); ?>..
</div>
- <input type="hidden" name="tcmp_all_ids" value="<?php echo implode( ',', $all_ids ); ?>" />
+ <input type="hidden" name="tcmp_all_ids" value="<?php echo esc_attr( implode( ',', $all_ids ) ); ?>" />
<div>
<?php
@@ -49,7 +49,7 @@
?>
<input type="checkbox" class="tcmp-checkbox" name="tcmp_ids[]" value="<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( $checked ); ?> <?php echo esc_attr( $disabled ); ?> />
<?php echo esc_attr( $snippet['name'] ); ?>
- <a href="<?php echo TCMP_TAB_EDITOR_URI; ?>&id=<?php echo esc_attr( $id ); ?>" target="_blank"> ››</a>
+ <a href="<?php echo esc_url( TCMP_TAB_EDITOR_URI . '&id=' . $id ); ?>" target="_blank"> ››</a>
<br/>
<?php } ?>
</div>
@@ -135,11 +135,6 @@
return;
}
- //in case of custom post type edit_ does not exist
- //if (!current_user_can('edit_'.$post_type, $post_id)) {
- // return;
- //}
-
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
@@ -148,7 +143,15 @@
return;
}
// Verify that the nonce is valid.
- if ( ! wp_verify_nonce( $_POST['tcmp_meta_box_nonce'], 'tcmp_meta_box' ) ) {
+ if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['tcmp_meta_box_nonce'] ) ), 'tcmp_meta_box' ) ) {
+ return;
+ }
+
+ // Object-level authorization: only proceed if the current user can actually
+ // edit this specific post. The 'edit_post' meta capability is mapped by
+ // WordPress to the correct primitive capability for the post's type, so it
+ // works for custom post types too (see F-03).
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
--- a/tracking-code-manager/includes/admin/settings.php
+++ b/tracking-code-manager/includes/admin/settings.php
@@ -5,6 +5,11 @@
$track = tcmp_sqs( 'track', '' );
if ( '' != $track ) {
+ // This GET toggle changes a setting AND triggers an outbound telemetry
+ // transmission, so it must be protected against CSRF with a nonce (F-02).
+ if ( ! $tcmp->check->nonce( 'tcmp_track' ) ) {
+ wp_die( esc_html( $tcmp->lang->L( 'Invalid nonce' ) ) );
+ }
$track = intval( $track );
$tcmp->options->setTrackingEnable( $track );
$tcmp->tracking->sendTracking( true );
@@ -13,9 +18,11 @@
$uri = TCMP_TAB_SETTINGS_URI . '&track=';
if ( $tcmp->options->isTrackingEnable() ) {
$uri .= '0';
+ $uri = wp_nonce_url( $uri, 'tcmp_track' );
$tcmp->options->pushSuccessMessage( 'EnableAllowTrackingNotice', $uri );
} else {
$uri .= '1';
+ $uri = wp_nonce_url( $uri, 'tcmp_track' );
$tcmp->options->pushErrorMessage( 'DisableAllowTrackingNotice', $uri );
}
$tcmp->options->writeMessages();
--- a/tracking-code-manager/includes/admin/whatsnew.php
+++ b/tracking-code-manager/includes/admin/whatsnew.php
@@ -23,12 +23,12 @@
<p class="tcmp-subheadline">Dynamic Conversion Values</p>
<p>Finally, Dynamic Conversion Values are now available for WooCommerce and Easy Digital Download. Now you can track the values of your conversions on <b>Google Adwords</b> and <b>Facebook Ads</b> (with the <b>New Pixel</b> and relative events like "Purchase" and others), and many other channels.</p>
- <img src="<?php echo TCMP_PLUGIN_ASSETS_URI; ?>landing/tcmp-fb.png" />
+ <img src="<?php echo esc_url( TCMP_PLUGIN_ASSETS_URI . 'landing/tcmp-fb.png' ); ?>" />
<br>
<br>
<div style="float: right;">
- <a class="button button-secondary" href="<?php echo TCMP_TAB_MANAGER_URI; ?>&hwb=1">CONTINUE USING FREE VERSION</a>
- <a class="button button-primary" href="<?php echo TCMP_TAB_DOCS_DCV_URI; ?>?utm_campaign=whatsnew" target="_blank">SEE MORE ››</a>
+ <a class="button button-secondary" href="<?php echo esc_url( TCMP_TAB_MANAGER_URI . '&hwb=1' ); ?>">CONTINUE USING FREE VERSION</a>
+ <a class="button button-primary" href="<?php echo esc_url( TCMP_TAB_DOCS_DCV_URI . '?utm_campaign=whatsnew' ); ?>" target="_blank">SEE MORE ››</a>
</div>
</td>
<td valign="top" width="50%" style="border-left: 1px solid #44444E;">
--- a/tracking-code-manager/includes/classes/core/Manager.php
+++ b/tracking-code-manager/includes/classes/core/Manager.php
@@ -21,7 +21,7 @@
return $result;
}
public function change_order() {
- if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'change_order' ) ) {
+ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'change_order' ) ) {
wp_send_json_error( 'Invalid nonce' );
}
@@ -350,23 +350,88 @@
if ( false != $purchase && intval( $tcmp->options->getLicenseSiteCount() ) > 0 ) {
$text = $this->insert_dynamic_conversion_values( $purchase, $text );
}
+ // The snippet body is the site owner's own tracking markup (script
+ // tags, pixels), so escaping it here would defeat the entire purpose
+ // of the plugin. esc_js_code() is the output sink: it runs the text
+ // through wp_kses() against the whitelist in
+ // tcmp_free_wp_kses_tags_attrs.php unless the admin has explicitly
+ // opted out via the "Skip Code Sanitization" setting. That whitelist
+ // permits <script> and onload, so this filters the markup — it does
+ // not constrain what an editor-capable admin can execute. See the
+ // contract note on esc_js_code().
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Filtered by esc_js_code() via wp_kses(); see the contract note there.
echo $this->esc_js_code( $text );
}
}
- private function esc_js_code( $text ) {
+ // Filter a snippet for output.
+ //
+ // What this sink does and does not guarantee: the snippet body is the site
+ // owner's own tracking markup, and the whitelist in
+ // tcmp_free_wp_kses_tags_attrs.php deliberately permits <script>, <iframe>
+ // and onload on every tag. A snippet author therefore has arbitrary
+ // JavaScript by design — that is the plugin's purpose, and it is governed by
+ // the capability gate on the editor (see F-09), not by this method. wp_kses()
+ // here is a well-formedness and whitelist pass over admin-authored markup; it
+ // is not a privilege boundary and must not be described as one.
+ //
+ // The entity decode below is scoped to <script> and <style> bodies, and that
+ // scope is load-bearing. wp_kses() entity-encodes '&' wherever it appears as
+ // text, so a saved "a && b" or a GTM "?id=x&l=dataLayer" comes back as
+ // "&". Inside <script>/<style> the browser does NOT decode entities, so
+ // leaving them encoded breaks the snippet; in an attribute value or in HTML
+ // text the browser DOES decode them, so kses's encoding is both correct and
+ // necessary there. Decoding everywhere — as this method used to — undid the
+ // neutralization kses had just applied, letting a quote escape its attribute
+ // and letting pre-encoded "<script>" text become a live tag.
+ public function esc_js_code( $text ) {
global $tcmp;
global $tcmp_allowed_html_tags;
if ( ! $tcmp->options->getSkipCodeSanitization() ) {
$text = wp_kses( $text, $tcmp_allowed_html_tags );
}
- $text = str_replace( '<', '<', $text );
- $text = str_replace( '>', '>', $text );
- $text = str_replace( '&', '&', $text );
- $text = str_replace( '"', '"', $text );
- $text = str_replace( ''', "'", $text );
- return $text;
+ return $this->decode_script_entities( $text );
+ }
+
+ // Decode HTML entities inside <script> and <style> element bodies only.
+ //
+ // Runs whether or not wp_kses() was applied above: a snippet saved while
+ // sanitization was enabled is stored already-encoded (Options::recursive_wp_kses()
+ // runs kses over the 'code' field on save), so it still needs decoding when
+ // rendered after "Skip Code Sanitization" is switched on.
+ private function decode_script_entities( $text ) {
+ // Cast before strpos(): passing null is deprecated on PHP 8.1+.
+ $text = (string) $text;
+ if ( false === strpos( $text, '&' ) ) {
+ return $text;
+ }
+ $result = preg_replace_callback(
+ '#(<(script|style)b[^>]*>)(.*?)(</2s*>)#is',
+ array( $this, 'decode_script_entities_callback' ),
+ $text
+ );
+ // preg_replace_callback() returns null on a PCRE limit; fall back to the
+ // still-encoded text rather than dropping the snippet. Failing closed
+ // costs a broken snippet, never a reversed sanitization.
+ return is_null( $result ) ? $text : $result;
+ }
+
+ private function decode_script_entities_callback( $matches ) {
+ // strtr() with a map replaces each source sequence exactly once and does
+ // not rescan its own output, so '<' decodes to '<' and cannot
+ // cascade into '<'.
+ $decoded = strtr(
+ $matches[3],
+ array(
+ '&' => '&',
+ '<' => '<',
+ '>' => '>',
+ '"' => '"',
+ ''' => "'",
+ )
+ );
+ return $matches[1] . $decoded . $matches[4];
}
private function insert_dynamic_conversion_values( $purchase, $text ) {
@@ -447,8 +512,7 @@
}
$v = $a;
}
- $v = str_replace( "'", '', $v );
- $v = str_replace( '"', '', $v );
+ $v = $this->esc_conversion_value( $v );
$buffer .= $v;
$previous = $end + strlen( $sep );
@@ -468,6 +532,68 @@
return $buffer;
}
+ // Context-encode a value substituted into a conversion snippet. Placeholders
+ // such as @@EMAIL@@ / @@FULLNAME@@ / @@PRODUCTS@@ carry customer-derived text
+ // and are almost always dropped into JavaScript string literals inside the
+ // tag, but an admin-authored template may also place them in an HTML
+ // attribute or in HTML text.
+ //
+ // SUPPORTED CONTEXTS — a JavaScript string literal (template literals
+ // included), a *quoted* HTML attribute value, and HTML text. In those three
+ // the encoding below holds:
+ //
+ // - Quotes are emitted as the JS unicode escapes u0022 / u0027 rather
+ // than " / '. Inside a JS string these decode back to " and ' so the
+ // value renders correctly, but NO literal quote ever reaches the HTML
+ // parser, so the value cannot close (break out of) a quoted attribute.
+ // - '<', '>' and '/' become u003C / u003E / / so the value cannot open
+ // a new tag or a </script> break-out (harmless literals in HTML text).
+ // - The backtick becomes u0060 and '$' becomes u0024. A template
+ // literal needs both: escaping the backtick alone stops the value
+ // *terminating* the literal, but '${' opens a substitution without
+ // needing one, so a value of '${payload}' would still be evaluated.
+ // u0024 is not a substitution opener — the lexer recognises '${' in
+ // the raw source, before escape sequences are processed.
+ // - Backslash and CR/LF are escaped so they cannot alter the JS around them.
+ //
+ // '$' is escaped where whitespace and '=' are not, and the difference is
+ // ubiquity rather than principle: every ordinary name and product list
+ // contains spaces, so encoding those would corrupt the common case, whereas
+ // '$' is rare in the values these placeholders carry — the numeric ones are
+ // number_format()'d or intval()'d before they get here. In a JS string it
+ // costs nothing either, since u0024 decodes straight back to '$'; only the
+ // two HTML contexts render it as the literal text u0024, which is the same
+ // fidelity-for-safety trade already made for quotes and '<'.
+ //
+ // NOT SUPPORTED — an *unquoted* HTML attribute value, e.g.
+ // `<img src=p.gif alt=@@FULLNAME@@>`. Whitespace and '=' are deliberately left
+ // intact (encoding them would corrupt ordinary names and product lists in the
+ // two contexts where they are just text), so in an unquoted attribute a value
+ // like `foo onload=alert(1)` introduces a new attribute rather than staying a
+ // value. Quote placeholder attributes in the snippet template. Note this is a
+ // weaker boundary than it looks even so: write_codes() applies wp_kses() after
+ // substitution, and that whitelist permits onload — so kses does not backstop
+ // this. Still PRO-gated (license count > 0) and therefore unreachable in the
+ // free tier.
+ //
+ // Numeric values are unaffected. strtr() maps each source character exactly
+ // once, avoiding cascading double-escaping. (See F-10.)
+ private function esc_conversion_value( $v ) {
+ $replacements = array(
+ '\' => '\\',
+ '"' => '\u0022',
+ "'" => '\u0027',
+ '`' => '\u0060',
+ '$' => '\u0024',
+ '<' => '\u003C',
+ '>' => '\u003E',
+ '/' => '\/',
+ "r" => '\r',
+ "n" => '\n',
+ );
+ return strtr( (string) $v, $replacements );
+ }
+
//return snippets that match with options
public function get_conversion_snippets( $options = null ) {
global $tcmp;
--- a/tracking-code-manager/includes/classes/ui/Check.php
+++ b/tracking-code-manager/includes/classes/ui/Check.php
@@ -31,7 +31,7 @@
}
public function nonce( $action, $nonce = '_wpnonce' ) {
if ( isset( $_REQUEST[ $nonce ] ) ) {
- $nonce = $_REQUEST[ $nonce ];
+ $nonce = sanitize_text_field( wp_unslash( $_REQUEST[ $nonce ] ) );
}
return wp_verify_nonce( $nonce, $action );
}
--- a/tracking-code-manager/includes/classes/ui/Form.php
+++ b/tracking-code-manager/includes/classes/ui/Form.php
@@ -375,7 +375,8 @@
$defaults = array();
$other = $this->get_text_args( $args, $defaults );
?>
- <input type="button" class="button tcmp-button" value="<?php $tcmp->lang->P( 'Delete?' ); ?>" onclick="if (confirm('<?php $tcmp->lang->P( 'Question.DeleteQuestion' ); ?>') ) window.location='<?php echo TCMP_TAB_MANAGER_URI; ?>&action=<?php echo esc_attr( $action ); ?>&id=<?php echo esc_attr( $id ); ?>&tcmp_nonce=<?php echo esc_attr( wp_create_nonce( 'tcmp_delete' ) ); ?>';" <?php echo wp_kses( $other, array() ); ?> />
+ <?php $delete_url = TCMP_TAB_MANAGER_URI . '&action=' . rawurlencode( $action ) . '&id=' . rawurlencode( $id ) . '&tcmp_nonce=' . wp_create_nonce( 'tcmp_delete' ); ?>
+ <input type="button" class="button tcmp-button" value="<?php $tcmp->lang->P( 'Delete?' ); ?>" onclick="if (confirm('<?php $tcmp->lang->P( 'Question.DeleteQuestion' ); ?>') ) window.location='<?php echo esc_url( $delete_url ); ?>';" <?php echo wp_kses( $other, array() ); ?> />
<?php
}
--- a/tracking-code-manager/includes/classes/ui/Tabs.php
+++ b/tracking-code-manager/includes/classes/ui/Tabs.php
@@ -7,7 +7,11 @@
}
public function init() {
global $tcmp;
- if ( $tcmp->utils->isAdminUser() ) {
+ // Only register the admin-menu machinery in the admin context; the menu
+ // callback itself still enforces the manage_options capability (and the
+ // multisite unfiltered_html gate). Replaces the misleading always-true
+ // isAdminUser() stub (see F-13).
+ if ( is_admin() ) {
add_action( 'admin_menu', array( &$this, 'attach_menu' ) );
add_filter( 'plugin_action_links', array( &$this, 'plugin_actions' ), 10, 2 );
if ( $tcmp->utils->isPluginPage() ) {
@@ -183,10 +187,14 @@
if (!current_user_can('unfiltered_html'))
{
// Only the Super-Admin role has unfiltered_html by default
- echo '<div class="tcmp-box-error">';
- echo '<p>For a multisite only, changing plugin settings requires the unfiltered_html capability.</p>';
- echo '</div>';
- die;
+ $refusal = 'For a multisite only, changing plugin settings requires the unfiltered_html capability.';
+ echo '<div class="tcmp-box-error"><p>' . esc_html( $refusal ) . '</p></div>';
+ // wp_die() rather than a bare die(): it ends the request with a
+ // themed, filterable error page instead of truncating the admin
+ // document mid-render, and it matches how change_order() already
+ // refuses. It is also interceptable, which is what makes this
+ // branch reachable from the test suite (see TabPageTest).
+ wp_die( esc_html( $refusal ) );
}
}
switch ( $tab ) {
@@ -318,7 +326,7 @@
<?php
} else {
?>
- <a style="float:left; margin-left:10px; <?php echo esc_attr( $style ); ?>" class="nav-tab <?php echo esc_attr( $active ); ?>" target="<?php echo esc_attr( $target ); ?>" href="?page=<?php echo TCMP_PLUGIN_SLUG; ?>&tab=<?php echo esc_attr( $k ); ?>"><?php echo esc_attr( $v ); ?></a>
+ <a style="float:left; margin-left:10px; <?php echo esc_attr( $style ); ?>" class="nav-tab <?php echo esc_attr( $active ); ?>" target="<?php echo esc_attr( $target ); ?>" href="<?php echo esc_url( '?page=' . TCMP_PLUGIN_SLUG . '&tab=' . $k ); ?>"><?php echo esc_attr( $v ); ?></a>
<?php
}
}
--- a/tracking-code-manager/includes/classes/utils/Logger.php
+++ b/tracking-code-manager/includes/classes/utils/Logger.php
@@ -25,7 +25,9 @@
public function fatal( $message, $v1 = null, $v2 = null, $v3 = null, $v4 = null, $v5 = null, $v6 = null ) {
$what = $this->write( '[FATAL]', $message, $v1, $v2, $v3, $v4, $v5, $v6 );
- die( $what );
+ // The message can interpolate snippet names and other stored values, so
+ // escape before it reaches the browser.
+ die( esc_html( $what ) );
}
public function debug( $message, $v1 = null, $v2 = null, $v3 = null, $v4 = null, $v5 = null, $v6 = null ) {
$this->write( '[DEBUG]', $message, $v1, $v2, $v3, $v4, $v5, $v6 );
@@ -72,7 +74,15 @@
}
$hasErrors = false;
- $filename = TCMP_PLUGIN_DIR . 'logs/' . $this->name . '_' . date( 'Ym' ) . '.txt';
+ $dir = $this->get_log_dir();
+ if ( '' == $dir ) {
+ return $message;
+ }
+ // The filename carries a site-specific, unguessable suffix so the log is
+ // not fetchable by guessing the URL, even on servers where the deny
+ // rules below are not honoured (e.g. nginx ignores .htaccess). See F-07.
+ $name = sanitize_file_name( $this->name );
+ $filename = $dir . $name . '_' . gmdate( 'Ym' ) . '_' . $this->log_token() . '.txt';
if ( ! $handle = fopen( $filename, 'a' ) ) {
$hasErrors = true;
}
@@ -86,4 +96,60 @@
}
return $message;
}
+
+ // Resolve (and lazily create + protect) the directory logs are written to.
+ // Logs live under wp-content/uploads/ rather than inside the plugin folder,
+ // and the directory is hardened with deny rules so it is not web-readable
+ // (see F-07).
+ private function get_log_dir() {
+ if ( ! function_exists( 'wp_upload_dir' ) ) {
+ return '';
+ }
+ $upload = wp_upload_dir();
+ if ( ! is_array( $upload ) || empty( $upload['basedir'] ) ) {
+ return '';
+ }
+ $dir = trailingslashit( $upload['basedir'] ) . 'tcm-logs/';
+ if ( ! is_dir( $dir ) && function_exists( 'wp_mkdir_p' ) ) {
+ wp_mkdir_p( $dir );
+ }
+ if ( ! is_dir( $dir ) ) {
+ return '';
+ }
+ $this->protect_dir( $dir );
+ return $dir;
+ }
+
+ // Drop the standard "deny all" guard files into the log directory so the
+ // logs cannot be downloaded over HTTP on either Apache or IIS, plus a blank
+ // index.php to prevent directory listing.
+ private function protect_dir( $dir ) {
+ $guards = array(
+ 'index.php' => "<?phpn// Silence is golden.n",
+ '.htaccess' => "Order Allow,DenynDeny from alln",
+ 'web.config' => "<?xml version="1.0" encoding="UTF-8"?>n<configuration>nt<system.webServer>ntt<authorization>nttt<deny users="*" />ntt</authorization>nt</system.webServer>n</configuration>n",
+ );
+ foreach ( $guards as $file => $contents ) {
+ $path = $dir . $file;
+ if ( ! file_exists( $path ) ) {
+ @file_put_contents( $path, $contents );
+ }
+ }
+ }
+
+ // Short, deterministic, site-specific token used only to obfuscate the log
+ // filename. Derived from WordPress salts when available; this is filename
+ // obfuscation, not a security-sensitive digest.
+ private function log_token() {
+ $seed = 'tcm-log';
+ if ( defined( 'AUTH_SALT' ) && '' != AUTH_SALT ) {
+ $seed .= AUTH_SALT;
+ } elseif ( defined( 'ABSPATH' ) ) {
+ $seed .= ABSPATH;
+ }
+ if ( function_exists( 'wp_hash' ) ) {
+ return substr( wp_hash( $seed ), 0, 12 );
+ }
+ return substr( md5( $seed ), 0, 12 );
+ }
}
--- a/tracking-code-manager/includes/classes/utils/MobileDetect.php
+++ b/tracking-code-manager/includes/classes/utils/MobileDetect.php
@@ -1020,7 +1020,10 @@
public function __call( $name, $arguments ) {
// make sure the name starts with 'is', otherwise
if ( substr( $name, 0, 2 ) !== 'is' ) {
- throw new BadMethodCallException( "No such method exists: $name" );
+ // Deviation from upstream Mobile_Detect: the message interpolates the
+ // called method name, so it is escaped in case the exception text is
+ // ever surfaced to a browser.
+ throw new BadMethodCallException( esc_html( "No such method exists: $name" ) );
}
$this->setDetectionType( self::DETECTION_TYPE_MOBILE );
--- a/tracking-code-manager/includes/classes/utils/Options.php
+++ b/tracking-code-manager/includes/classes/utils/Options.php
@@ -363,12 +363,17 @@
$type = sanitize_text_field( $type );
$result = false;
$array = $this->getRequest( $type . 'Messages', array() );
- // These messages are built by the plugin and have been already sanitized.
- // Trying to sanitize them again will break plugin functionality since some of the messages contain html.
if ( is_array( $array ) && count( $array ) > 0 ) {
$result = true;
+ // Escape at the sink so safety no longer depends on every caller
+ // pre-escaping its message arguments (see F-04). wp_kses_post keeps
+ // the intentional markup (links, styled spans) some notices embed
+ // while neutralising anything dangerous. It now wraps the wpautop()
+ // result rather than each message, so the escaping is applied to
+ // everything that is actually echoed.
+ $html = wpautop( implode( "n", $array ) );
?>
- <div class="tcmp-box-<?php echo strtolower( $type ); ?>"><?php echo wpautop( implode( "n", $array ) ); ?></div>
+ <div class="tcmp-box-<?php echo esc_attr( strtolower( $type ) ); ?>"><?php echo wp_kses_post( $html ); ?></div>
<?php
}
if ( $clean ) {
--- a/tracking-code-manager/includes/classes/utils/Plugin.php
+++ b/tracking-code-manager/includes/classes/utils/Plugin.php
@@ -211,7 +211,10 @@
}
function getActivePlugins( $ids ) {
- return $this->getActivePlugins( $ids, true );
+ // Delegates to getPlugins() with $onlyActive = true. This used to call
+ // itself, which recursed until the process ran out of stack; it had no
+ // callers, so the fault stayed latent.
+ return $this->getPlugins( $ids, true );
}
function getPlugins( $ids, $onlyActive = true ) {
$array = array();
--- a/tracking-code-manager/includes/classes/utils/Tracking.php
+++ b/tracking-code-manager/includes/classes/utils/Tracking.php
@@ -80,11 +80,13 @@
global $tcmp;
//retrieve blog info
- $result['wp_url'] = home_url();
- $result['wp_version'] = get_bloginfo( 'version' );
- $result['wp_language'] = get_bloginfo( 'language' );
- $result['wp_wpurl'] = get_bloginfo( 'wpurl' );
- $result['wp_admin_email'] = get_bloginfo( 'admin_email' );
+ $result['wp_url'] = home_url();
+ $result['wp_version'] = get_bloginfo( 'version' );
+ $result['wp_language'] = get_bloginfo( 'language' );
+ $result['wp_wpurl'] = get_bloginfo( 'wpurl' );
+ // The administrator email address is intentionally NOT transmitted: it is
+ // personal data that is not needed for the usage statistics this payload
+ // collects. (See F-08 — data minimisation.)
$result['plugins'] = $this->getPluginData();
$result['theme'] = $this->getThemeData();
--- a/tracking-code-manager/includes/classes/utils/Utils.php
+++ b/tracking-code-manager/includes/classes/utils/Utils.php
@@ -161,8 +161,17 @@
}
public function twitter( $name ) {
+ // Self-contained X (formerly Twitter) follow link. The old markup relied on
+ // Twitter's platform.twitter.com/widgets.js to turn a `.twitter-follow-button`
+ // anchor into a logo button; that widget was retired after the X rebrand, so it
+ // rendered as bare text with no logo. Inline the X mark as SVG instead — no
+ // external script, works offline, and shows the correct current brand.
+ // Styling lives in the .tcmp-x-follow rules in assets/css/style.css.
?>
- <a href="https://twitter.com/<?php echo esc_attr( $name ); ?>" class="twitter-follow-button" data-show-count="false" data-dnt="true">Follow @<?php echo esc_attr( $name ); ?></a>
+ <a href="https://x.com/<?php echo esc_attr( $name ); ?>" target="_blank" rel="noopener noreferrer" class="tcmp-x-follow">
+ <svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true" focusable="false"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
+ <span>Follow @<?php echo esc_html( $name ); ?></span>
+ </a>
<?php
}
@@ -372,9 +381,9 @@
global $tcmp_allowed_html_tags;
$result = $default;
if ( isset( $_POST[ $name ] ) ) {
- $result = $this->sanitize_post_or_get( $_POST[ $name ] );
+ $result = $this->sanitize_post_or_get( $_POST[ $name ], $name );
} elseif ( isset( $_GET[ $name ] ) ) {
- $result = $this->sanitize_post_or_get( $_GET[ $name ] );
+ $result = $this->sanitize_post_or_get( $_GET[ $name ], $name );
}
if ( is_string( $result ) ) {
@@ -387,8 +396,12 @@
return $result;
}
- private function sanitize_post_or_get( $array ) {
+ private function sanitize_post_or_get( $array, $name = '' ) {
global $tcmp_allowed_html_tags;
+ // The snippet "code" fields hold raw tracking markup on purpose; they are
+ // sanitized on output via TCMP_Manager::esc_js_code(). Everything else is
+ // treated as plain text so that qs() is safe by default (see F-06).
+ $is_code = ( 'code' === $name || 'tcmp_code' === $name );
if ( is_array( $array ) ) {
foreach ( $array as $k => &$v ) {
if ( 'code' == $k ) {
@@ -397,6 +410,9 @@
$v = sanitize_text_field( $v );
}
}
+ unset( $v );
+ } elseif ( is_string( $array ) && ! $is_code ) {
+ $array = sanitize_text_field( $array );
}
return $array;
}
@@ -404,7 +420,7 @@
var $_taxonomyType;
function query( $query, $options = null ) {
- global $tcmp, $wpdb;
+ global $tcmp;
$parent = '';
$defaults = array(
@@ -441,10 +457,27 @@
$function = '';
switch ( $query ) {
case TCMP_QUERY_POSTS_OF_TYPE:
- //$options=array('posts_per_page'=>-1, 'post_type'=>$args['post_type']);
- //$q=get_posts($options);
- $sql = 'SELECT ID, post_title FROM ' . $wpdb->prefix . "posts WHERE post_status='publish' AND post_type='" . $options['type'] . "' ORDER BY post_title";
- $q = $wpdb->get_results( $sql );
+ // get_posts() instead of a direct $wpdb query: it goes
+ // through WordPress's object cache and avoids the
+ // DirectDatabaseQuery / NoCaching warnings. The WP_Post
+ // objects it returns expose the same ID and post_title
+ // fields the loop below reads, and get_posts() already
+ // sets no_found_rows, so this is no heavier than the
+ // two-column SELECT it replaces. The empty-type check keeps
+ // the old semantics: the previous `post_type = ''` SELECT
+ // matched nothing, whereas get_posts() would silently fall
+ // back to listing ordinary posts.
+ if ( '' !== (string) $options['type'] ) {
+ $q = get_posts(
+ array(
+ 'post_type' => $options['type'],
+ 'post_status' => 'publish',
+ 'posts_per_page' => -1,
+ 'orderby' => 'title',
+ 'order' => 'ASC',
+ )
+ );
+ }
$function = 'get_permalink';
break;
case TCMP_QUERY_CATEGORIES:
@@ -1614,11 +1647,6 @@
return $data;
}
- function isAdminUser() {
- //https://wordpress.org/support/topic/how-to-check-admin-right-without-include-pluggablephp
- return true;
- }
-
function isPluginPage() {
global $tcmp;
$page = tcmp_sqs( 'page' );
@@ -1971,17 +1999,15 @@
}
public function getVisitorIpAddress() {
+ // Only REMOTE_ADDR is set by the web server and cannot be spoofed by the
+ // client. HTTP_CLIENT_IP / HTTP_X_FORWARDED_FOR are attacker-controllable
+ // request headers and must never be trusted for a security decision, so
+ // they are intentionally NOT consulted here. Also calls the real instance
+ // method $this->validate_ip() (the previous global validate_ip() call
+ // would have fatal-errored). (See F-12.)
$ip = '';
- if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
- $ip = validate_ip( $_SERVER['HTTP_CLIENT_IP'] );
- }
-
- if ( '' == $ip && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
- $ip = validate_ip( $_SERVER['HTTP_X_FORWARDED_FOR'] );
- }
-
- if ( '' == $ip ) {
- $ip = validate_ip( $_SERVER['REMOTE_ADDR'] );
+ if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
+ $ip = $this->validate_ip( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) );
}
return $ip;
}
--- a/tracking-code-manager/includes/core.php
+++ b/tracking-code-manager/includes/core.php
@@ -52,14 +52,25 @@
add_shortcode( 'tcm', 'tcmp_shortcode' );
function tcmp_shortcode( $atts, $content = '' ) {
global $tcmp;
- extract( shortcode_atts( array( 'id' => false ), $atts ) );
+ // Assign explicitly instead of extract() on external input (see F-13).
+ $atts = shortcode_atts( array( 'id' => false ), $atts );
+ $id = $atts['id'];
- if ( ! isset( $id ) || ! $id ) {
+ if ( ! $id ) {
return '';
}
$snippet = $tcmp->manager->get( $id, true );
- return $snippet['code'];
+ if ( ! is_array( $snippet ) || ! isset( $snippet['code'] ) ) {
+ return '';
+ }
+
+ // Run the snippet through the same output path as write_codes() instead of
+ // returning it raw, so the shortcode and the normal injection path cannot
+ // diverge (F-05). Note that this equalises the two paths; it does not make
+ // the shortcode safe to expose to lower-privileged authors, because the
+ // whitelist esc_js_code() applies permits <script> by design.
+ return $tcmp->manager->esc_js_code( $snippet['code'] );
}
function tcmp_ui_first_time() {
--- a/tracking-code-manager/index.php
+++ b/tracking-code-manager/index.php
@@ -6,7 +6,7 @@
Author: Data443
Author URI: https://data443.com/
Email: support@data443.com
-Version: 2.6.0
+Version: 2.7.0
Requires at least: 3.6.0
Requires PHP: 5.6
*/
@@ -25,7 +25,7 @@
define( 'TCMP_PLUGIN_FILE', __FILE__ );
define( 'TCMP_PLUGIN_SLUG', 'tracking-code-manager' );
define( 'TCMP_PLUGIN_NAME', 'Tracking Code Manager' );
-define( 'TCMP_PLUGIN_VERSION', '2.6.0' );
+define( 'TCMP_PLUGIN_VERSION', '2.7.0' );
define( 'TCMP_PLUGIN_AUTHOR', 'IntellyWP' );
define( 'TCMP_PLUGIN_DIR', dirname( __FILE__ ) . '/' );
@@ -44,7 +44,7 @@
define( 'TCMP_QUERY_TAXONOMY_TYPES', 6 );
define( 'TCMP_QUERY_TAXONOMIES_OF_TYPE', 7 );
-define( 'TCMP_INTELLYWP_ENDPOINT', 'http://www.intellywp.com/wp-content/plugins/intellywp-manager/data.php' );
+define( 'TCMP_INTELLYWP_ENDPOINT', 'https://www.intellywp.com/wp-content/plugins/intellywp-manager/data.php' );
define( 'TCMP_PAGE_FAQ', 'http://www.intellywp.com/tracking-code-manager' );
define( 'TCMP_PAGE_PREMIUM', 'http://www.intellywp.com/tracking-code-manager' );
define( 'TCMP_PAGE_MANAGER', admin_url() . 'options-general.php?page=' . TCMP_PLUGIN_SLUG );