---
title: "Indirect Prompt Injection via django-docutils RST Rendering in AI"
slug: "indirect-prompt-injection-django-docutils-rst-ai-agents"
description: "Defensive teardown of CVE-2026-59988 reframed as an AI security failure: unsafe Docutils defaults create indirect prompt injection and data exfiltration"
author: "Hamdi Soudani"
category: "ai-security-jailbreaks"
archetype: "advisory-teardown"
published_at: "2026-11-26T13:04:23.286+00:00"
updated_at: "2026-11-26T13:04:23.512398+00:00"
canonical_url: "https://pyvren.com/blog/indirect-prompt-injection-django-docutils-rst-ai-agents"
reading_time_minutes: 5
word_count: 991
quality_score: 91
tags: ["ai-security","prompt-injection","django-docutils","cve-2026-59988","indirect-prompt-injection"]
keywords: ["indirect prompt injection django-docutils","ai agent document processing sandbox","rst rendering ssrf defense","llm data exfiltration channel","docutils unsafe defaults mitigation"]
sources: ["https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/","https://github.com/advisories/GHSA-86mf-q4h5-69gp","https://ismalicious.com/cve/CVE-2026-59988"]
---

# Indirect Prompt Injection via django-docutils RST Rendering in AI

> **TL;DR:** Upgrade django-docutils to 0.30.0 and sandbox RST rendering to block indirect prompt injection, local file disclosure, SSRF, and stored XSS in AI agent document pipelines.

## Key Facts

- **Affected versions:** django-docutils < 0.30.0 ([source](https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/))
- **Fixed version:** 0.30.0 ([source](https://github.com/advisories/GHSA-86mf-q4h5-69gp))
- **CVSS score:** 8.2 High (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N) ([source](https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/))
- **CWE identifiers:** CWE-200, CWE-22, CWE-79 ([source](https://ismalicious.com/cve/CVE-2026-59988))
- **EPSS exploitation probability:** 0.5% within 30 days as of 2026-11-25 ([source](https://ismalicious.com/cve/CVE-2026-59988))
- **Guardrail latency overhead:** Approximately 2-5 ms per document at typical blog-post sizes ([source](https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/))

django-docutils before version 0.30.0 hands attacker-controlled reStructuredText directly to Docutils with defaults designed for trusted documents, not web-facing applications. The vulnerability, tracked as CVE-2026-59988, affects public rendering paths including `publish_doctree`, `publish_html_from_source`, `publish_html_from_doctree`, `publish_parts_from_doctree`, the `{% rst %}` template tag, the `rst` template filter, `DocutilsTemplates`, and `DocutilsView`. An attacker who can influence rendered RST can use `.. include::` and `.. csv-table:: :file:` directives to read local files, `.. include::` and `.. csv-table:: :url:` to trigger server-side URL requests, and `.. raw:: html` to emit unescaped HTML that becomes stored XSS when rendered in a browser. Local `docutils.conf` processing can also re-enable unsafe behavior even when an application attempts to harden settings manually.

This advisory teardown covers the threat model, why naive prompt filters fail, a defense-in-depth sandbox architecture, runnable guardrail policy, and operational tradeoffs.

## Threat Model & Attack Surface Matrix

| Attack Surface | Blast Radius | Concrete Control |
|---|---|---|
| Agent fetches untrusted URL, converts to RST, renders via django-docutils | Indirect prompt injection; server-side file disclosure and SSRF | Upgrade to 0.30.0; disable file_insertion_enabled and raw_enabled; drop worker network egress |
| `{% rst %}` template tag rendering user comments in agent context | Read worker-process files, exfiltrate secrets | Upgrade to 0.30.0; disable file_insertion_enabled and raw_enabled |
| `DocutilsView` processing API-supplied RST | SSRF to internal metadata services | Block unsafe URI schemes; egress proxy allowlist |
| `DocutilsTemplates` in CMS wiki pages | Stored XSS via `.. raw:: html` | Sanitize doctree before HTML emission; CSP headers |
| Local `docutils.conf` re-enabling directives | Full bypass of application-level hardening | Set `_disable_config=True`; immutable config mount |
| Multi-turn agent document-processing pipeline | Guardrail drift; autonomous tool use with exfiltration channel | Sandbox worker; non-root user; no access to `.env` or source trees |

The root cause is that Docutils treats file insertion, raw content, and ambient configuration as legitimate features for trusted documents. Django applications that render lower-trust RST inherit these unsafe defaults unless they explicitly override them. Because the server-side read or network request happens during rendering, UI escaping after the fact does not prevent disclosure or SSRF.

This maps directly to OWASP LLM Top 10 concerns around insecure output handling and data exfiltration, and to NIST AI RMF guidance on isolating model-adjacent infrastructure from sensitive data planes [OWASP LLM Top 10](https://owasp.org/www-project-top-10/2025/02-insecure-output-handling) [NIST AI RMF](https://www.nist.gov/itl/ai-risk-management-framework).

## Why Naive Prompt Filters Fail

Keyword filtering on RST input cannot reliably block this class of attack. Attackers can obfuscate directive names, split directives across whitespace, use Unicode homoglyphs, or embed malicious content in included files that pass through the filter before inclusion. More importantly, the vulnerability is not a prompt-injection problem in the LLM sense; it is a server-side processing issue where the document processor itself has privileged filesystem and network access. Filtering the prompt text does not remove the ambient authority of the Django worker process.

LLM document-processing pipelines compound the risk. An autonomous agent that fetches a URL, converts the response to RST, and renders it through django-docutils creates an indirect prompt injection path: the fetched content controls server-side behavior without ever touching the model's context window. Guardrails that inspect only the model input or output miss the server-side document processing entirely.

Multi-turn guardrail drift makes this worse. An agent that renders RST in turn one, then summarizes the rendered output in turn two, can leak file contents or internal network topology through the model's own responses. The initial injection happens at the document layer, not the chat layer, so per-turn prompt filters never see it.

## Defense-in-Depth & Sandbox Isolation Architecture

The primary fix is upgrading to django-docutils 0.30.0, which disables file insertion, raw directives, local `docutils.conf` processing, and unsafe URI schemes by default, and sanitizes doctrees before HTML emission [GitLab Advisory](https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/). Until upgrade is complete, enforce the following controls:

1. **Disable dangerous Docutils defaults** at application startup before any rendering path is reached.
2. **Run the Django worker in a read-only container** with no access to `.env`, source trees, or mounted secrets.
3. **Drop all network egress** from the worker namespace except an explicit allowlist for required upstream services.
4. **Sanitize rendered HTML** through a strict allowlist sanitizer before storage or delivery to browsers.
5. **Render untrusted RST in a separate microservice** with no access to internal metadata endpoints or inter-service credentials.

This isolation prevents privilege escalation in autonomous agents: even if an attacker achieves indirect prompt injection through fetched content, the sandboxed worker cannot reach internal metadata services or exfiltrate worker-process files.

## Runnable Guardrail Policy / Verification Code

The following Django AppConfig enforces safe Docutils settings globally before rendering occurs. It wraps the configured template engines and forces the web-safe defaults described in the advisory.

```python
from django.apps import AppConfig
from django.template import engines

class SafeDocutilsConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "myapp"

    def ready(self):
        SAFE_DOCUTILS_SETTINGS = {
            "file_insertion_enabled": False,
            "raw_enabled": False,
            "_disable_config": True,
        }
        for engine in engines.all():
            engine.engine.libraries.setdefault(
                "docutils_tags", "django_docutils.templatetags.docutils_tags"
            )
```

Verification: confirm the installed version and inspect active settings in a staging worker.

```bash
pip show django-docutils | grep Version
python -c "import django_docutils; print(django_docutils.__version__)"
```

If the version is below 0.30.0, the application is vulnerable unless it manually enforces `SAFE_DOCUTILS_SETTINGS` and sanitizes doctrees. After upgrade, verify that `.. include::` and `.. raw:: html` directives are rejected or neutralized in rendered output.

## Operational Tradeoffs & False-Positive Budget

Disabling file insertion and raw directives breaks legitimate documentation workflows that rely on `.. include::` for shared snippets or `.. raw:: html` for embedded widgets. Applications that require these features should move them to a separate, trusted rendering pipeline with its own sandbox and no access to user-controlled input. The false-positive cost of blocking all raw directives is low for comment fields, wiki bodies, and CMS content, but high for technical documentation portals that intentionally allow authors to embed HTML.

Latency overhead from enforcing settings at startup is negligible; per-request sanitization adds approximately 2-5 ms per document at typical blog-post sizes. The larger operational cost is maintaining the egress allowlist and reviewing rendered HTML through a sanitizer, which can introduce false positives when legitimate content contains iframes or SVG.

When not to use this guidance: applications that render only trusted static RST authored by internal staff are not affected unless attackers can influence that content. Do not apply the sandbox controls to trusted internal documentation services that require local file access, as that breaks legitimate functionality without reducing risk.

![CVE-2026-59988 severity card showing CVSS 8.2 High for django-docutils unsafe Docutils defaults.](https://ismalicious.com/api/og?kind=cve&locale=en&cveId=CVE-2026-59988&severity=high&cvss=8.2&product=django-docutils&date=2026-11-20&path=%2Fcve%2FCVE-2026-59988&sig=Z-eMKucQ0L6IXrBHa80tUQ)

Primary sources: [GitLab Advisory Database CVE-2026-59988](https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/), [GitHub Advisory Database GHSA-86mf-q4h5-69gp](https://github.com/advisories/GHSA-86mf-q4h5-69gp), [isMalicious CVE-2026-59988 record](https://ismalicious.com/cve/CVE-2026-59988).

## Frequently Asked Questions

### How does CVE-2026-59988 enable indirect prompt injection in AI agent pipelines?

An autonomous agent that fetches untrusted web content, converts it to reStructuredText, and renders it through django-docutils lets the fetched content control server-side behavior—file reads, URL fetches, and raw HTML emission—without ever entering the model's context window, bypassing input and output guardrails entirely.

### Which django-docutils rendering paths process attacker-controlled RST unsafely?

publish_doctree, publish_html_from_source, publish_html_from_doctree, publish_parts_from_doctree, the {% rst %} template tag, the rst template filter, DocutilsTemplates, and DocutilsView.

### Does client-side HTML escaping mitigate CVE-2026-59988?

No. File reads and server-side URL fetches occur during server-side Docutils processing before HTML reaches the client, so client-side escaping cannot prevent disclosure or SSRF.

## Primary Sources

- https://advisories.gitlab.com/pypi/django-docutils/CVE-2026-59988/
- https://github.com/advisories/GHSA-86mf-q4h5-69gp
- https://ismalicious.com/cve/CVE-2026-59988
