Shortcode Block Securityのロゴ

Shortcode Block Security

組織
wpultimatesecurity
shortcode-block-security

add_shortcodeでショートコードを登録するとき、render_callbackで動的ブロックを登録するとき、またはショートコードやブロックの属性を処理するときに使います。shortcode_attsで属性を正規化し、許可リストに照らして検証したうえで、esc_html、esc_attr、esc_url、wp_kses_postを使い、出力先に応じてすべてのレンダリング結果をエスケープします。レンダリングされるコンテンツでの保存型XSSと反射型XSSを防ぎます。

Add to TypingMind

概要

公開者wpultimatesecurity
リポジトリWordPress-Security-Skills
スキル名shortcode-block-security
スター
54
フォーク
3
同梱ファイル
2
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 2個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    wpultimatesecurityがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Shortcode Block Security」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/shortcode-block-security
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wpultimatesecurity/WordPress-Security-Skills.git /tmp/WordPress-Security-Skills
mkdir -p .claude/skills
cp -r /tmp/WordPress-Security-Skills/skills/shortcode-block-security .claude/skills/shortcode-block-security
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでShortcode Block Securityを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にShortcode Block Securityを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Shortcode Block Securityは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Shortcode & dynamic block security

When to use this skill

Use this skill whenever code renders content from shortcodes or dynamic blocks:

  • Registering a shortcode with add_shortcode().
  • Reading or outputting shortcode attributes ($atts) or enclosed content ($content).
  • Registering a dynamic block with a render_callback.
  • Reading block attributes in a server-side render.
  • Building HTML, URLs, or classes from shortcode/block input.

Shortcodes and dynamic blocks are stored XSS sinks: a contributor enters [my_card title="<script>..."] and the render callback echoes it unescaped. Every attribute must be sanitized and every output escaped.

Related: see the output-escaping skill for context-correct escaping and the gutenberg-block-editor-security skill for broader block-editor surfaces.

Core principles (and why they matter)

  1. shortcode_atts() sets defaults; it does NOT sanitize. The returned array still holds raw user input. Sanitize each value before use.
  2. Block attributes are user input too. Declaring type: 'string' in block.json does not escape HTML or JavaScript for you; sanitize on render.
  3. Escape at render for the exact context. HTML body → esc_html(). HTML attribute → esc_attr(). URL → esc_url(). Rich HTML → wp_kses_post() with an allowlist.
  4. Do not store unescaped attribute values. If you persist them, sanitize on save and escape on read.
  5. Never pass shortcode/block input to do_shortcode() or eval() uncontrolled. Both can execute arbitrary shortcodes or code.
  6. Return, don't echo. Shortcode and block render callbacks must return strings; echoing produces unexpected output placement.

Step-by-step implementation

  1. In the shortcode callback, call shortcode_atts() with a complete default map.
  2. Sanitize each attribute to its expected type (absint, sanitize_text_field, esc_url_raw, sanitize_key).
  3. In a block render_callback, read attributes from the $attributes array and sanitize them the same way.
  4. Build the markup by concatenating escaped values.
  5. Return the complete markup string.
  6. For rich content, use wp_kses_post() or a tightly scoped wp_kses() allowlist.

Supporting references

ReferenceLoad when
Shortcode & dynamic block security checklistBefore final verification of the shortcode & dynamic block security controls.
Secure shortcode and dynamic blockImplementing shortcode and dynamic-block render callbacks with validated attributes and escaped markup.

Common AI mistakes / anti-patterns

Mistake 1 — Echoing $atts directly

php
// ❌ Insecure: stored XSS through the title attribute.
function my_plugin_card_shortcode( $atts ) {
    return '<div class="card"><h3>' . $atts['title'] . '</h3></div>';
}
php
// ✅ Secure: default, then sanitize, then escape.
function my_plugin_card_shortcode( $atts ) {
    $atts = shortcode_atts(
        array(
            'title' => '',
            'link'  => '',
        ),
        $atts,
        'my_plugin_card'
    );

    $title = sanitize_text_field( $atts['title'] );
    $link  = esc_url_raw( $atts['link'] );

    $output = '<div class="card">';
    if ( $link ) {
        $output .= '<h3><a href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a></h3>';
    } else {
        $output .= '<h3>' . esc_html( $title ) . '</h3>';
    }
    $output .= '</div>';

    return $output;
}

Mistake 2 — Trusting shortcode_atts() to sanitize

php
// ❌ Insecure: shortcode_atts only supplies defaults and filters unknown keys.
$atts = shortcode_atts( array( 'class' => '' ), $atts );
echo '<div class="' . $atts['class'] . '">...</div>';
php
// ✅ Secure: sanitize the value after normalizing it.
$atts  = shortcode_atts( array( 'class' => '' ), $atts, 'my_plugin_box' );
$class = sanitize_html_class( $atts['class'] );
echo '<div class="' . esc_attr( $class ) . '">...</div>';

Mistake 3 — Dynamic block render callback echoing attributes

php
// ❌ Insecure: block attributes echoed raw.
function my_plugin_render_banner( $attributes ) {
    ?>
    <div class="banner" style="background: <?php echo $attributes['bgColor']; ?>">
        <?php echo $attributes['heading']; ?>
    </div>
    <?php
}
php
// ✅ Secure: sanitize attributes and escape for the output context.
function my_plugin_render_banner( $attributes ) {
    $bg_color = isset( $attributes['bgColor'] ) ? sanitize_hex_color( $attributes['bgColor'] ) : '#ffffff';
    $heading  = isset( $attributes['heading'] ) ? sanitize_text_field( $attributes['heading'] ) : '';

    return sprintf(
        '<div class="banner" style="background: %s"><h2>%s</h2></div>',
        esc_attr( $bg_color ),
        esc_html( $heading )
    );
}

Mistake 4 — Allowing arbitrary HTML through attributes

php
// ❌ Insecure: an attacker can inject script/event handlers.
function my_plugin_render_note( $attributes ) {
    return '<div>' . $attributes['content'] . '</div>';
}
php
// ✅ Secure: constrain rich markup with wp_kses_post.
function my_plugin_render_note( $attributes ) {
    $content = isset( $attributes['content'] ) ? $attributes['content'] : '';
    return '<div>' . wp_kses_post( $content ) . '</div>';
}

Mistake 5 — Running do_shortcode() on untrusted input

php
// ❌ Insecure: executes arbitrary shortcodes supplied by a visitor.
echo do_shortcode( $_POST['content'] );
php
// ✅ Secure: do not run do_shortcode on user input; if required, sanitize first.
$content = wp_kses_post( wp_unslash( $_POST['content'] ?? '' ) );

Correct code examples

A complete secure shortcode and dynamic-block render callback is in references/secure-shortcode-block.php.

Checklist

  • shortcode_atts() provides defaults for every supported attribute.
  • Each shortcode attribute is sanitized to its expected type after normalization.
  • Block attributes are sanitized inside render_callback, not trusted from block.json types.
  • All rendered output is escaped for its context (esc_html, esc_attr, esc_url, wp_kses_post).
  • CSS classes use sanitize_html_class() (or esc_attr() with an allowlist).
  • Colors use sanitize_hex_color() where appropriate.
  • The callback returns a string; it does not echo directly.
  • do_shortcode() is never run on untrusted input.

Official references

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Shortcode Block Security」では何ができますか?

add_shortcodeでショートコードを登録するとき、render_callbackで動的ブロックを登録するとき、またはショートコードやブロックの属性を処理するときに使います。shortcode_attsで属性を正規化し、許可リストに照らして検証したうえで、esc_html、esc_attr、esc_url、wp_kses_postを使い、出力先に応じてすべてのレンダリング結果をエスケープします。レンダリングされるコンテンツでの保存型XSSと反射型XSSを防ぎます。

TypingMindでShortcode Block Securityを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Shortcode Block Securityはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにShortcode Block Securityをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/shortcode-block-securityを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Shortcode Block Securityを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Shortcode Block Securityで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもShortcode Block Securityを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Shortcode Block Security」は無料ですか?

はい。wpultimatesecurityがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇