shortcode-injection

Untrusted input run as WordPress shortcodes.

Group
Code
Runs
Runs under ur scan: ur scan --rule shortcode-injection
Level
warning
Reads
Every file
Fix
None: the safe form depends on what the value is meant to be

Why

A value from a request is given to do_shortcode, which runs every shortcode its text names, so whoever sends the request can run any shortcode the site registers, with any attributes, as only a post's author should. Pass the value to do_shortcode only after removing its shortcodes, as strip_shortcodes does, or run the one shortcode meant with fixed attributes.

The fix, as Ur suggests it: strip the shortcodes from the value first.

For agents

Never give do_shortcode text a request chose; strip its shortcodes first or run a fixed shortcode.

Example

preview.php
<?php
add_action('wp_ajax_nopriv_preview_form', 'preview_form');
function preview_form() {
    echo do_shortcode($_POST['content']);
    wp_die();
}
What Ur prints
$ ur scan --rule shortcode-injection
warning[shortcode-injection]: `$_POST`, a form field, reaches `do_shortcode`
  --> ./preview.php:4:10 function `preview_form`
  = step 1: ./preview.php:4:23 `$_POST`, a form field,
  = hint: strip the shortcodes from the value first
  = see: do_shortcode(), WordPress Developer Resources (2025-04-15), https://developer.wordpress.org/reference/functions/do_shortcode/
scanned 1 file (no framework recognized)
  shortcode-injection: 1 high, 0 medium
1 finding and 0 of medium confidence

Try it in the playground →

Source

do_shortcode(), WordPress Developer Resources (2025-04-15).