Output Escapingのロゴ

Output Escaping

組織
wpultimatesecurity
output-escaping

WordPressのPHPコードやテンプレートで、HTML、属性、URL、インラインJavaScript、textareaに動的な値を出力するときに使用します。出力時にesc_html、esc_attr、esc_url、esc_js、esc_textarea、wp_kses_postや、i18n版のesc_html__、esc_attr_eを使ってエスケープします。保存型および反射型XSSを防ぎます。データベース由来のデータも含め、出力するすべての変数にあらかじめ適用してください。

Add to TypingMind

概要

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

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

  • どのLLMでも利用可能

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

  • 2個の同梱ファイル

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

  • オープンソース

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

インストール

AIスキル「Output Escaping」を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/output-escaping
  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/output-escaping .claude/skills/output-escaping
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

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

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

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

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

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

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

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

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

スキルの指示

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

Output escaping (XSS prevention)

When to use this skill

Use this skill whenever a dynamic value is sent to the browser:

  • echo / print of any variable into HTML.
  • Values placed into HTML attributes (value, href, src, class, data-*).
  • URLs in href / src / redirects.
  • Data injected into inline <script> or JS via wp_localize_script.
  • Content rendered in templates, shortcodes, blocks, widgets, REST responses that return HTML.

Escape as late as possible, at the point of output, choosing the function that matches the context the value lands in. This is separate from input sanitization — do both.

Core principles (and why they matter)

  1. Escape on output, every time. XSS happens when untrusted data is interpreted as markup or script. Escaping at output neutralizes it regardless of how it got stored.
  2. Escape even "trusted" data. Database values, option values, and your own earlier output can still contain markup. Escape at render anyway — it's cheap and consistent.
  3. Context determines the function. HTML body → esc_html; attribute → esc_attr; URL → esc_url; inline JS → esc_js (or wp_json_encode); rich HTML → wp_kses_post. Using the wrong one (e.g. esc_html inside an attribute) can still be exploitable.
  4. Escape the whole value, late. Don't concatenate escaped + unescaped fragments; escape the final value as it is echoed.
  5. Translations are output too. Use esc_html__(), esc_attr_e(), etc. — never echo a raw __() result into a sensitive context.
  6. wp_kses_post() is for intentional HTML. When a value must contain markup, allow a safe subset rather than escaping it all away.

Step-by-step implementation

  1. Identify the context at the echo site (HTML text, attribute, URL, JS, textarea).
  2. Pick the matching escaping function.
  3. Wrap the value at the moment of output.
  4. For translatable strings, use the esc_*__ / esc_*_e variant.
  5. For values that legitimately contain HTML, use wp_kses_post() / wp_kses().

Supporting references

ReferenceLoad when
Output escaping checklistBefore final verification of the output escaping controls.
Output escaping cheatsheetChoosing the applicable WordPress API or control for context-specific output escaping.

Common AI mistakes / anti-patterns

Mistake 1 — Echoing a value with no escaping

php
// ❌ Insecure: stored XSS if $name ever contains markup.
echo '<h2>' . $name . '</h2>';
php
// ✅ Secure: escape for HTML context.
echo '<h2>' . esc_html( $name ) . '</h2>';

Mistake 2 — Wrong context (HTML escaper inside an attribute)

php
// ❌ Insecure: esc_html doesn't encode quotes the way attributes need.
echo '<input value="' . esc_html( $value ) . '">';
php
// ✅ Secure: esc_attr for attribute context.
echo '<input value="' . esc_attr( $value ) . '">';

Mistake 3 — Unescaped URLs (allows javascript: and injection)

php
// ❌ Insecure: attacker controls the scheme/markup.
echo '<a href="' . $url . '">link</a>';
php
// ✅ Secure: esc_url strips dangerous schemes and encodes the URL.
echo '<a href="' . esc_url( $url ) . '">link</a>';

Mistake 4 — Injecting PHP into inline JS without esc_js/JSON

php
// ❌ Insecure: breaks out of the string and into script.
echo '<script>var label = "' . $label . '";</script>';
php
// ✅ Secure: esc_js for a single quoted string...
echo '<script>var label = "' . esc_js( $label ) . '";</script>';
// ...or, better, pass structured data as JSON:
echo '<script>var data = ' . wp_json_encode( $data ) . ';</script>';

Mistake 5 — Using wp_kses_post() where escaping is required (and vice versa)

php
// ❌ Wrong tool: kses lets markup through where you wanted plain text.
echo '<td>' . wp_kses_post( $plain_title ) . '</td>';
php
// ✅ Plain text → esc_html; intentional rich HTML → wp_kses_post.
echo '<td>' . esc_html( $plain_title ) . '</td>';
echo '<div class="bio">' . wp_kses_post( $rich_bio ) . '</div>';

Mistake 6 — Translated strings echoed unescaped

php
// ❌ Insecure: translation files can contain markup; raw echo into a tag.
echo '<p>' . __( 'Welcome, %s', 'my-plugin' ) . '</p>';
php
// ✅ Secure: escape the translated output.
printf( '<p>%s</p>', esc_html__( 'Welcome back', 'my-plugin' ) );

Mistake 7 — Redirect target not validated

php
// ❌ Insecure: open redirect to an attacker-controlled site.
$redirect = $_GET['redirect_to'];
wp_redirect( $redirect );
exit;
php
// ✅ Secure: the "escape" for a Location target is validation + wp_safe_redirect.
$redirect = isset( $_GET['redirect_to'] ) ? esc_url_raw( wp_unslash( $_GET['redirect_to'] ) ) : '';
$redirect = wp_validate_redirect( $redirect, admin_url() );
wp_safe_redirect( $redirect );
exit;

Mistake 8 — Using wp_kses_post where a tighter allowlist is needed

php
// ❌ Risky: wp_kses_post allows many tags you may not want in a caption.
echo wp_kses_post( $caption );
php
// ✅ Secure: define a custom allowlist when the context is narrower.
$allowed = array(
    'a'      => array( 'href' => array() ),
    'em'     => array(),
    'strong' => array(),
);
echo wp_kses( $caption, $allowed );

Related: see the input-sanitization-validation skill for validating redirect URLs on input and the filesystem-security skill for path escaping.

Mistake 9 — Escaping in PHP, then re-injecting in JavaScript

js
// ❌ Insecure: PHP passed the value safely through wp_localize_script or
// wp_json_encode, but the script decodes it into markup.
const name = myPluginData.displayName;
document.querySelector( '#greeting' ).innerHTML = 'Hello ' + name;
jQuery( '#title' ).html( myPluginData.title );
js
// ✅ Secure: insert untrusted values as text in the DOM.
document.querySelector( '#greeting' ).textContent = 'Hello ' + myPluginData.displayName;
jQuery( '#title' ).text( myPluginData.title );

Server-side escaping protects the transfer into the page, not what client code does next. Review DOM sinks (innerHTML, outerHTML, insertAdjacentHTML, document.write, jQuery .html()/.append() with strings, location assignments) in plugin scripts.

Correct code examples

A complete context → function reference (with esc_url vs esc_url_raw, the i18n variants, and wp_kses allowlist usage) is in references/escaping-cheatsheet.md.

php
// A small template snippet that escapes every dynamic value in context.
?>
<article id="post-<?php echo esc_attr( $post_id ); ?>" class="<?php echo esc_attr( $css ); ?>">
    <h2><a href="<?php echo esc_url( $permalink ); ?>"><?php echo esc_html( $title ); ?></a></h2>
    <div class="content"><?php echo wp_kses_post( $content ); ?></div>
    <a class="more" href="<?php echo esc_url( $permalink ); ?>">
        <?php echo esc_html__( 'Read more', 'my-plugin' ); ?>
    </a>
</article>
<?php

Checklist

  • Every echoed variable is escaped at the point of output.
  • HTML text uses esc_html / esc_html__ / esc_html_e.
  • Attribute values use esc_attr / esc_attr__ / esc_attr_e.
  • URLs in markup use esc_url (esc_url_raw only for storage/redirects).
  • Inline JS uses esc_js or, preferably, wp_json_encode.
  • Textarea contents use esc_textarea.
  • Intentional HTML uses wp_kses_post / wp_kses with an allowlist.
  • Translatable strings use the esc_* i18n variants.
  • No escaped/unescaped string concatenation that defeats escaping.
  • Client-side code inserts localized or fetched values with textContent / .text(), not innerHTML / .html(); URLs assigned to location or href are validated.

Official references

同梱ファイル

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

よくある質問

AIスキル「Output Escaping」では何ができますか?

WordPressのPHPコードやテンプレートで、HTML、属性、URL、インラインJavaScript、textareaに動的な値を出力するときに使用します。出力時にesc_html、esc_attr、esc_url、esc_js、esc_textarea、wp_kses_postや、i18n版のesc_html__、esc_attr_eを使ってエスケープします。保存型および反射型XSSを防ぎます。データベース由来のデータも含め、出力するすべての変数にあらかじめ適用してください。

TypingMindでOutput Escapingを使うメリットは何ですか?

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

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

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

Output Escapingを使えるAIモデルはどれですか?

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

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

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

AIスキル「Output Escaping」は無料ですか?

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

AIスキルとは何ですか?

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

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

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

すべて見る

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

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