Logo van Output Escaping

Output Escaping

Organisatie
wpultimatesecurity
output-escaping

Gebruik dit bij het weergeven of afdrukken van dynamische waarden in WordPress-PHP of -templates, bijvoorbeeld in HTML, attributen, URL's, inline JavaScript of tekstvakken. Escape waarden op het moment van uitvoer met esc_html, esc_attr, esc_url, esc_js, esc_textarea of wp_kses_post, inclusief de i18n-varianten (esc_html__, esc_attr_e). Voorkomt opgeslagen en gereflecteerde XSS. Pas dit proactief toe op elke variabele die wordt weergegeven, ook op gegevens uit de database.

Add to TypingMind

Overzicht

Uitgeverwpultimatesecurity
RepositoryWordPress-Security-Skills
Skillnaamoutput-escaping
Sterren
54
Forks
3
Meegeleverde bestanden
2
LicentieMIT
Links
  • Instructies in Markdown

    Het model laadt het bestand SKILL.md alleen als dat nodig is. Dat kost dus alleen tokens als een verzoek daadwerkelijk bij de skill past.

  • Werkt met elk LLM

    AI-skills bestaan uit instructies in gewone Markdown, niet uit aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Meegeleverde bestanden: 2

    Scripts, sjablonen en referentiemateriaal die het model tijdens het werken kan lezen. De bestanden kunnen alleen worden gelezen en worden nooit uitgevoerd.

  • Open source

    Gepubliceerd door wpultimatesecurity op GitHub. Bekijk de bronbestanden voordat je de skill installeert.

Installatie

Installeer de AI-skill Output Escaping in TypingMind om deze met elk LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map. De app leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/output-escaping
  4. Schakel de skill in voor elke chat waarin je de skill wilt kunnen gebruiken.
Plug-ins → Skills → Skill toevoegen → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

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
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Output Escaping in voor een chat naar keuze in TypingMind en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek bij de skill past, laadt het model zelf de volledige instructies. Je hoeft de skill nooit handmatig aan te roepen. Pas als het model de skill daadwerkelijk gebruikt, kost dat tokens.

Het model laadt Output Escaping automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Output Escaping niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

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

Meegeleverde bestanden

Zolang de skill geladen is, leest het model deze bestanden als dat nodig is. Het model kan ze alleen lezen; ze worden nooit uitgevoerd.

Veelgestelde vragen

Wat doet de AI-skill Output Escaping?

Gebruik dit bij het weergeven of afdrukken van dynamische waarden in WordPress-PHP of -templates, bijvoorbeeld in HTML, attributen, URL's, inline JavaScript of tekstvakken. Escape waarden op het moment van uitvoer met esc_html, esc_attr, esc_url, esc_js, esc_textarea of wp_kses_post, inclusief de i18n-varianten (esc_html__, esc_attr_e). Voorkomt opgeslagen en gereflecteerde XSS. Pas dit proactief toe op elke variabele die wordt weergegeven, ook op gegevens uit de database.

Waarom Output Escaping gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Output Escaping bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model. Ook als je midden in een chat van model wisselt, blijft de skill werken. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek af te sluiten. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Output Escaping in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/output-escaping. TypingMind leest het bestand SKILL.md, bundelt de bijbehorende bestanden en installeert het geheel als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Output Escaping gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Output Escaping gebruiken?

Zoveel als je wilt. Je kunt Output Escaping gebruiken met elk model dat skills ondersteunt, zoals GPT, Claude, Gemini, Grok, DeepSeek, Mistral of Llama. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Output Escaping gratis?

Ja. Deze skill is door wpultimatesecurity op GitHub gepubliceerd onder de licentie MIT. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. De skill volgt het open Agent Skills-formaat: het bestand SKILL.md bevat de naam en beschrijving van de skill. Daarnaast kan de skill scripts, sjablonen of referentiebestanden bevatten die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Bekijk alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇