شعار Rendering Untrusted Content

Rendering Untrusted Content

المجتمع
wdm0006
rendering-untrusted-content

يعرض المحتوى المخزّن أو المكتوب أو المستورَد بصيغة HTML من دون التسبب في ثغرات XSS، وذلك عبر تدقيق كل مواضع تجاوز الهروب التلقائي (|safe وMarkup وinnerHTML)، وتنقية مخرجات Markdown باستخدام قائمة سماح، وتهريب المحتوى على الخادم وفي DOM، وكتابة اختبارات للتنقية تتحقق من النسخة الصحيحة من السلسلة النصية. استخدمه عند إضافة مُرشّح لـ Markdown أو النص المنسّق، أو عرض محتوى كتبه مستخدم أو مسؤول، أو مراجعة قالب يعلّم HTML على أنه موثوق، أو بناء عميل يحقن قيماً في innerHTML، أو معالجة بلاغ عن ثغرة XSS.

Add to TypingMind

نظرة عامة

الناشرwdm0006
المستودعpython-skills
اسم المهارةrendering-untrusted-content
النجوم
111
التفريعات
17
الملفات المرفقة
تعليمات فقط
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • مكتفية بذاتها

    كل ما يحتاجه النموذج موجود في التعليمات — لا ملفات إضافية لمزامنتها.

  • مفتوحة المصدر

    نشرها wdm0006 على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Rendering Untrusted Content في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/wdm0006/python-skills/tree/main/skills/common/rendering-untrusted-content
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wdm0006/python-skills.git /tmp/python-skills
mkdir -p .claude/skills
cp -r /tmp/python-skills/skills/common/rendering-untrusted-content .claude/skills/rendering-untrusted-content
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Rendering Untrusted Content في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Rendering Untrusted Content تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Rendering Untrusted Content بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Rendering Untrusted Content

Template engines autoescape by default, so the vulnerable surface is small and enumerable: it is exactly the places where something says this value is already safe HTML. Find those first; everything else is already handled.

Step 1 — Enumerate the trust bypasses

bash
# Server-side (Jinja/Django templates + the Python that feeds them)
grep -rnE '\|\s*safe|Markup\(|autoescape false|mark_safe' templates/ src/

# Client-side
grep -rnE 'innerHTML|outerHTML|insertAdjacentHTML|document\.write' web/ static/

Every hit is a claim that needs justification. A |safe on a value that came from a database column is a claim about everything that has ever been written to that column, including via an import path nobody remembers.

Step 2 — Markdown output is not sanitized HTML

Markdown renderers pass raw HTML through by design — that is a documented feature, not a bug. So a shared template filter shaped like this is an XSS sink:

python
# BAD — the filter marks arbitrary stored markup trusted.
def _markdown(text: str) -> Markup:
    return Markup(markdown.markdown(text, extensions=["extra", "tables"]))

"Only admins author content" is not a boundary. As soon as there is an import path, a seed script, or a second author, the content store is untrusted input.

Render, then sanitize with an allowlist, and only then mark trusted:

python
import markdown, nh3
from markupsafe import Markup

ALLOWED_TAGS = {
    "p", "br", "hr", "em", "strong", "code", "pre", "blockquote",
    "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "li",
    "a", "img", "table", "thead", "tbody", "tr", "th", "td",
}
ALLOWED_ATTRS = {
    "a": {"href", "title", "rel"},
    "img": {"src", "alt", "title"},
    "th": {"style", "align"},
    "td": {"style", "align"},
}

def _markdown(text: str) -> Markup:
    html = markdown.markdown(text, extensions=["extra", "tables"])
    return Markup(nh3.clean(
        html,
        tags=ALLOWED_TAGS,
        attributes=ALLOWED_ATTRS,
        filter_style_properties={"text-align"},   # see below
    ))

Do not hand-roll the allowlist logic. Use a maintained HTML sanitizer (nh3, the Rust/ammonia-backed successor to bleach). Regex-stripping <script> is not sanitization.

The table-alignment trap

Markdown's tables extension encodes column alignment as an inline style — <th style="text-align: left;">. An allowlist that drops style is "secure" and silently removes alignment from every table in the corpus. Allow style on table cells and constrain which properties survive (filter_style_properties).

Then note that the sanitizer normalizes what it keeps: text-align: left; comes back as text-align:left — no space, no trailing semicolon. An exact-output test must expect the normalized form, not the string Markdown emitted, or it fails on a correct fix.

Step 3 — A shared filter has the whole corpus as its blast radius

One filter feeds every post body, every FAQ answer, every description. Changing it re-renders all of them at once, and the failure mode is not a crash — it is content quietly losing a construct.

Render every piece of authored content before and after the change and diff it character by character, then keep that as a regression test:

python
@pytest.mark.parametrize("path", sorted(CONTENT_DIR.glob("*.md")))
def test_authored_content_is_unchanged_by_sanitization(path):
    raw = markdown.markdown(path.read_text(), extensions=EXTENSIONS)
    assert _markdown(path.read_text()) == raw

If no authored file contains raw HTML, that equality holds and any future diff is a genuine regression. If some file does need raw HTML, you have found the one case worth an explicit decision instead of discovering it in production.

Step 4 — Test the copy of the string that actually matters

The same value is often rendered several times on one page: in prose, in <meta> tags, and inside a JSON-LD <script> block. A whole-document assertion therefore reports a vulnerability that isn't one:

python
# BAD — fails even when the prose is correctly sanitized.
assert "<script>alert(1)</script>" not in html

Template tojson filters emit HTML-safe JSON — angle brackets become \u003c / \u003e, so the JSON-LD copy cannot break out of its <script> element and is not a vulnerability. But the payload's text still appears there, so a document-wide assertion goes red while the prose is perfectly sanitized. Scope the assertion to the rendered prose:

python
article = extract_article_html(html)
assert "<script>" not in article
assert "&lt;script&gt;" in article        # proves it was escaped, not dropped

Assert the escaped form is present, not just that the dangerous form is absent — otherwise a filter that silently deletes the whole field passes.

Also scope the audit: a feed or export built from separately-escaped title/description fields that never includes the body is not part of this surface. Don't "fix" it.

Step 5 — Escape at both ends

Server-side escaping does nothing for a client that re-injects the same value through innerHTML. A card grid rendered safely by the server and a detail modal built with a template literal are two independent sinks, and the second one is usually the one that got missed.

js
// Prefer the API that cannot execute markup.
el.textContent = item.description;

// When you must build markup, escape into a local first.
const description = escapeHtml(item.description);
const tags = item.tags.map(escapeHtml).join(", ");
modal.innerHTML = `<p>${description}</p><footer>${tags}</footer>`;

Escaping into a const before the template literal is not just style: wrapping the expression inline pushes the line past the linter's length limit, and reflowing the HTML string to fit introduces leading whitespace that is visible inside white-space: pre-wrap blocks. Escape first, interpolate second.

Step 6 — "No event handlers" is a test that fails on clean code

Asserting that no on* attribute appears in rendered output looks like a strong XSS regression test, and it goes red immediately: application templates legitimately emit handlers (onclick="showDetail(3)"). A test that fails on correct code gets deleted within a week.

Allowlist the handlers your own templates emit and assert on the remainder:

python
handlers = re.findall(r'\son(\w+)="([^"]*)"', card_html)
assert handlers == [("click", "showDetail(3)")]

Pinning the full list (rather than not any(...)) also catches a second, injected handler alongside the legitimate one — presence assertions can't.

Checklist

- [ ] Every |safe / Markup() / mark_safe / innerHTML site enumerated and justified
- [ ] Markdown (and any rich-text) output passes through an allowlist sanitizer
      before being marked trusted — a maintained library, not a regex
- [ ] Allowlist keeps constructs the renderer depends on (table-cell style),
      and tests expect the sanitizer's normalized output
- [ ] Authored content diffed before/after the filter change, pinned by a test
- [ ] Sanitization tests assert on the rendered prose, and assert the escaped
      form is present — not just that the raw payload is absent
- [ ] Client-side injection points escape too (or use textContent)
- [ ] Handler/attribute assertions allowlist what the app's own templates emit

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Rendering Untrusted Content؟

يعرض المحتوى المخزّن أو المكتوب أو المستورَد بصيغة HTML من دون التسبب في ثغرات XSS، وذلك عبر تدقيق كل مواضع تجاوز الهروب التلقائي (|safe وMarkup وinnerHTML)، وتنقية مخرجات Markdown باستخدام قائمة سماح، وتهريب المحتوى على الخادم وفي DOM، وكتابة اختبارات للتنقية تتحقق من النسخة الصحيحة من السلسلة النصية. استخدمه عند إضافة مُرشّح لـ Markdown أو النص المنسّق، أو عرض محتوى كتبه مستخدم أو مسؤول، أو مراجعة قالب يعلّم HTML على أنه موثوق، أو بناء عميل يحقن قيماً في innerHTML، أو معالجة بلاغ عن ثغرة XSS.

لماذا تستخدم Rendering Untrusted Content على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Rendering Untrusted Content عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Rendering Untrusted Content في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/wdm0006/python-skills/tree/main/skills/common/rendering-untrusted-content. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Rendering Untrusted Content؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Rendering Untrusted Content؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Rendering Untrusted Content معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Rendering Untrusted Content مجانية؟

نعم. نشرها wdm0006 على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇