Free WordPress WAF
Protect your site at the edge
Atomic Edge blocks exploit traffic, bots, and bad requests before they reach WordPress. Create a free account, then point DNS when you are ready.
Get Protected FreeAtomic Edge analysis of CVE-2026-137045: BetterLinks versions up to and including 3.1.7 are vulnerable to authenticated stored cross-site scripting via the ‘short_url’ parameter. The flaw impacts the FluentBoards integration handlers in betterlinks/includes/Admin/Ajax.php, which saved attacker-controlled short_url values to the database without applying the standard link validation and escaping. The CVSS score is 6.4 with a Subscriber+ privilege requirement, contingent on the attacker’s account being a member of a FluentBoards board.
The root cause is the absence of sanitization and validation in the FluentBoards link save path. The update_fbs_link() and create paths around includes/Admin/Ajax.php read $_POST[‘short_url’] and write it to the links table, but they skipped the validation the main link handlers perform (validate_link_payload in Link.php). The patched version adds a new private method validate_fbs_short_url() in Ajax.php that wraps validate_link_payload() and calls it before the short URL is persisted in both update_fbs_link() and the create handler. Additionally, LinkChecker.php previously built the anchor replacement with string concatenation (‘${1}’ . $href . ‘${3}’), letting the short URL content flow unescaped into the final HTML output. The patch wraps $href in esc_url() and swaps preg_replace() for preg_replace_callback(), so backreferences in the short URL are treated as literal text.
Exploitation requires a Subscriber-level account that has been added to a FluentBoards board, which exposes the board admin screen and its betterlinks_admin_nonce. From that screen the attacker submits a request to /wp-admin/admin-ajax.php with action=update_fbs_link (or the create action), a valid security nonce, and a short_url payload such as “>alert(document.cookie) or an onmouseover attribute fragment. The malicious value is stored, and any frontend page where BetterLinks renders a cloaked or transformed anchor executes the injected script in the victim’s browser. Because the payload is stored, an administrator visiting the affected page triggers execution with admin session privileges.
The patch closes the vulnerability in two layers. First, validate_fbs_short_url() enforces the same rules as the primary link handlers: empty check, rejection of quotes, angle brackets and whitespace, reserved WordPress path checks, and duplicate detection via validate_link_payload(), invoked before any write in both the update and create flows. Second, LinkChecker.php now escapes the final href with esc_url() and uses preg_replace_callback() so short URL characters such as $1 or 1 cannot act as regex backreferences. Helper.php also adds get_uploads_relative_path() to keep existing uploads from being shadowed, and Link.php refuses to run short links that point at files that still exist. These changes ensure stored values cannot break out of the anchor attribute during rendering.
Successful exploitation allows an authenticated low-privileged user to inject arbitrary JavaScript that runs in administrative sessions. This can lead to session hijacking, creation of rogue administrator accounts, plugin and theme modification, and full site takeover. Because BetterLinks renders cloaked links across public pages, the stored XSS also fires for unauthenticated visitors, enabling defacement, credential harvesting via injected forms, and drive-by redirects. The patched behavior forces attackers to submit short URLs that survive validate_link_payload(), eliminating the attribute breakout and regex backreference vectors that made stored payloads execute.
Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/betterlinks/betterlinks.php
+++ b/betterlinks/betterlinks.php
@@ -3,7 +3,7 @@
* Plugin Name: BetterLinks
* Plugin URI: https://betterlinks.io/
* Description: Create, shorten, cloak, track and manage any URL. Gather click analytics, run marketing campaigns, and connect AI assistants over MCP.
- * Version: 3.1.7
+ * Version: 3.1.8
* Author: WPDeveloper
* Author URI: https://wpdeveloper.com
* License: GPL-3.0-or-later
@@ -110,7 +110,7 @@
/**
* Defines CONSTANTS for Whole plugins.
*/
- define('BETTERLINKS_VERSION', '3.1.7');
+ define('BETTERLINKS_VERSION', '3.1.8');
define('BETTERLINKS_DB_VERSION', '1.6.11');
define('BETTERLINKS_MENU_NOTICE', '11');
define('BETTERLINKS_SETTINGS_NAME', 'betterlinks_settings');
--- a/betterlinks/includes/Admin/Ajax.php
+++ b/betterlinks/includes/Admin/Ajax.php
@@ -247,6 +247,46 @@
);
}
+ /**
+ * Apply the regular short URL validation to a FluentBoards link and stop
+ * with its error when it fails.
+ *
+ * These handlers write `short_url` themselves instead of going through the
+ * main link handlers, so they need the same checks: no quotes, angle
+ * brackets or whitespace, no reserved WordPress paths, no duplicates.
+ *
+ * @param string|null $short_url Proposed short URL.
+ * @param int $link_id Link being updated, or 0 when creating.
+ * @return void
+ */
+ private function validate_fbs_short_url( $short_url, $link_id = 0 ) {
+ $short_url = (string) $short_url;
+ if ( '' === trim( $short_url ) ) {
+ wp_send_json_error(
+ array(
+ 'result' => false,
+ 'code' => 'betterlinks_invalid_short_url',
+ 'message' => __( 'The short URL cannot be empty.', 'betterlinks' ),
+ )
+ );
+ }
+
+ $args = array( 'short_url' => $short_url );
+ if ( $link_id > 0 ) {
+ $args['ID'] = absint( $link_id );
+ }
+ $invalid = $this->validate_link_payload( $args, $link_id > 0 );
+ if ( is_wp_error( $invalid ) ) {
+ wp_send_json_error(
+ array(
+ 'result' => false,
+ 'code' => $invalid->get_error_code(),
+ 'message' => $invalid->get_error_message(),
+ )
+ );
+ }
+ }
+
public function update_fbs_link() {
check_ajax_referer( 'betterlinks_admin_nonce', 'security' );
if ( ! defined( 'FLUENT_BOARDS' ) ) {
@@ -267,6 +307,9 @@
$this->send_fbs_permission_error();
}
+ // Same short URL rules as every other place a link is saved.
+ $this->validate_fbs_short_url( $short_url, $id );
+
if ( $helper::is_exists_short_url( $short_url ) ) {
wp_send_json_error(
array(
@@ -351,6 +394,8 @@
$short_url = isset( $_POST['short_url'] ) ? sanitize_text_field( wp_unslash( $_POST['short_url'] ) ) : null;
$prefix = isset( $settings['prefix'] ) ? $settings['prefix'] . '/' : '';
$short_url = ! empty( $short_url ) ? $short_url : $prefix . $slug;
+ // Validate before anything is written (the category and settings below).
+ $this->validate_fbs_short_url( $short_url );
$nofollow = ! empty( $settings['nofollow'] ) ? $settings['nofollow'] : null;
$sponsored = ! empty( $settings['sponsored'] ) ? $settings['sponsored'] : null;
$track_me = ! empty( $settings['track_me'] ) ? $settings['track_me'] : null;
--- a/betterlinks/includes/Frontend/LinkChecker.php
+++ b/betterlinks/includes/Frontend/LinkChecker.php
@@ -36,11 +36,23 @@
if( empty( $href ) ) {
continue;
}
- $href = $this->check_hrefs($href);
+ // Escape the final href (after the filter), so a short URL saved
+ // before slugs were validated cannot break out of the attribute.
+ $href = esc_url( $this->check_hrefs( $href ) );
+ if ( '' === $href ) {
+ continue;
+ }
+ // A callback, so `$1` or `1` in a short URL is kept as text and
+ // not read as a back-reference.
$pattern = '/(<as+[^>]*hrefs*=s*["'])([^"']*)(["'][^>]*>)/i';
- $replacement = '${1}' . $href . '${3}';
- $replace = preg_replace($pattern, $replacement, $match[0]);
+ $replace = preg_replace_callback(
+ $pattern,
+ static function ( $parts ) use ( $href ) {
+ return $parts[1] . $href . $parts[3];
+ },
+ $match[0]
+ );
// if( empty( $this->link['uncloaked'] ) ){
// $pattern = '/s*data-link-id=["'][^"']*["']/i';
--- a/betterlinks/includes/Helper.php
+++ b/betterlinks/includes/Helper.php
@@ -826,6 +826,14 @@
if ( '' === $path ) {
return false;
}
+ // Redirecting a retired upload (an old PDF, image…) to its replacement is
+ // a core use case and worked before system paths were reserved, so files
+ // inside the uploads directory stay available even though wp-content is
+ // reserved. The web server serves files that still exist before
+ // WordPress loads, and run_redirect() never shadows one either.
+ if ( null !== self::get_uploads_relative_path( $path ) ) {
+ return false;
+ }
$first = (string) strtok( $path, '/?#' );
$reserved = array(
'wp-admin',
@@ -854,6 +862,47 @@
}
/**
+ * The part of `$path` inside the uploads directory, when `$path` points at
+ * something under it (`wp-content/uploads/2025/04/file.pdf` →
+ * `2025/04/file.pdf`). Null for any other path, for the uploads directory
+ * itself, and for paths with `..` segments that could climb out of it.
+ *
+ * @param string $path Path relative to the site root.
+ * @return string|null
+ */
+ public static function get_uploads_relative_path( $path ) {
+ if ( ! function_exists( 'wp_get_upload_dir' ) ) {
+ return null;
+ }
+ // wp_get_upload_dir() is cached per site by core, so this stays correct
+ // after switch_to_blog() on multisite.
+ $uploads = wp_get_upload_dir();
+ $base_path = isset( $uploads['baseurl'] ) ? (string) wp_parse_url( $uploads['baseurl'], PHP_URL_PATH ) : '';
+ $site_path = (string) wp_parse_url( site_url( '/' ), PHP_URL_PATH );
+ if ( '' !== $site_path && 0 === strpos( $base_path, $site_path ) ) {
+ $base_path = substr( $base_path, strlen( $site_path ) );
+ }
+ $uploads_base = strtolower( trim( $base_path, '/' ) );
+
+ $path = (string) $path;
+ // A null byte is never part of a real file name, and file_exists()
+ // throws on it in PHP 8+, so leave such paths to the normal 404.
+ if ( false !== strpos( $path, "