<?xml version="1.0" encoding="UTF-8"?>
<xao-docs>
  <site name="XaoDocs" product="Xao" version="1.0.0-dev" homepage="https://xao.ndx.au" repo="https://github.com/ndx-au/Xao" examples-repo="https://github.com/ndx-au/xao-example-apps"/>
  <request slug="security" theme="atlas" path="/xml/security" xml-url="/xml/security"/>
  <themes>
    <theme id="atlas" name="Atlas" tagline="Three-column reference desk with persistent sidebar and sticky page outline" audience="API and framework developers browsing across sections" structure="3-column grid: left navigation sidebar, center article, right on-this-page outline" css="/assets/atlas.css" active="true"/>
    <theme id="folio" name="Folio" tagline="Editorial journal spread with XPath-grouped numbered chapters and collapsible library" audience="Architects and evaluators reading long-form conceptual chapters" structure="Editorial cover header, collapsible library drawer, and sibling-grouped numbered chapter sections" css="/assets/folio.css" active="false"/>
    <theme id="console" name="Console" tagline="Operations dashboard with telemetry strip and collapsible H2 module accordions" audience="SREs, operators, and runtime engineers scanning sections quickly" structure="Command header, telemetry bar, compact nav rail, and expandable &lt;details&gt; module accordions" css="/assets/console.css" active="false"/>
    <theme id="reader" name="Reader (A11y)" tagline="WCAG AAA single-column linear reader with upfront summary, numbered TOC, and zero JS" audience="Screen reader users, keyboard-only navigation, and low-vision / cognitive accessibility" structure="Multi-landmark skip links, upfront document summary, inline numbered TOC, figure-wrapped code blocks, directory after article, zero JS" css="/assets/reader.css" active="false"/>
    <theme id="handbook" name="Handbook" tagline="Single-column print-ready technical specification sheet with metadata ledger" audience="Technical reviewers, auditors, and print/PDF export workflows" structure="Single-column specification document with &lt;dl&gt; metadata ledger, numbered outline, and print stylesheet" css="/assets/handbook.css" active="false"/>
  </themes>
  <navigation>
    <section name="Start Here">
      <item slug="index" title="Xao Documentation" description="XML Application Objects for PHP 8 and PHC — zero-dependency XML content aggregation and XSLT 3.0 presentation." order="1" active="false"/>
      <item slug="getting-started" title="Getting Started" description="Set up PHC, autoload Xao with zero Composer packages, transform your first DomDoc with XSLT 3.0, and run phc serve." order="2" active="false"/>
    </section>
    <section name="Core Concepts">
      <item slug="architecture" title="Architecture &amp; XML Aggregation" description="How Xao builds a unified XML conglomeration document from databases, Markdown, and domain objects before delegating presentation to XSLT 3.0." order="3" active="false"/>
      <item slug="xslt-themes" title="XSLT 3.0 Themes vs CSS Skins" description="Why XSLT themes are structurally and semantically richer than CSS-only themes — including accessibility-first DOM transformations." order="4" active="false"/>
    </section>
    <section name="Framework Reference">
      <item slug="core-api" title="Core API Reference" description="Reference for Xao\\Runtime, Xao\\XaoRoot, Xao\\DomDoc, Xao\\DomFactory, Xao\\AppDoc, Xao\\Http\\Response, and Xao\\Exceptions." order="5" active="false"/>
      <item slug="database-aggregation" title="Database Aggregation (DbToXml)" description="Convert PDO queries, PDOStatement results, and PHP iterables directly into structured DomDoc XML fragments under PHC." order="6" active="false"/>
      <item slug="markdown-aggregation" title="Markdown Aggregation" description="Convert CommonMark and GFM into CommonMark XML 1.0 natively in PHC via comrak and graft it into Xao DomDoc trees." order="7" active="false"/>
      <item slug="xslt-drivers" title="XSLT 3.0 Drivers" description="Pluggable XsltDriverInterface strategies: PhcNativeXsltDriver (default in-process), SaxonHttpDriver (HTTP/distributed), and ClientSideXslDriver." order="8" active="false"/>
    </section>
    <section name="Operations &amp; Runtime">
      <item slug="phc-runtime" title="PHC Runtime &amp; Compatibility" description="Running Xao on PHC in isolate and worker modes, sandbox defaults, worker-safe autoloading, and P00–P05 compatibility findings." order="9" active="false"/>
      <item slug="security" title="Security Model" description="XXE rejection, realpath containment, strict slug allowlists, CSRF guards, gated debug output, and PHC sandbox enforcement." order="10" active="true"/>
    </section>
    <section name="Examples &amp; Design">
      <item slug="reference-apps" title="Reference Applications" description="Comparing Xao's built-in SQLite PDO catalog reference app with XaoDocs, the flat-file Markdown multi-theme CMS." order="11" active="false"/>
      <item slug="adr-0001-phc-xee-xslt" title="ADR 0001 &amp; Roadmap" description="Architecture Decision Record for pure-Rust xee-xslt in PHC plus the Xao v1.0.0 milestone and phase roadmap (M0–M3, P00–P06)." order="12" active="false"/>
    </section>
  </navigation>
  <page slug="security" title="Security Model" description="XXE rejection, realpath containment, strict slug allowlists, CSRF guards, gated debug output, and PHC sandbox enforcement." section="Operations &amp; Runtime" audience="Security reviewers and application developers" status="stable" words="266" reading-minutes="2" source-file="content/security.md">
    <tags>
      <tag>security</tag>
      <tag>xxe</tag>
      <tag>sandbox</tag>
      <tag>csrf</tag>
      <tag>containment</tag>
    </tags>
    <neighbors>
      <prev slug="phc-runtime" title="PHC Runtime &amp; Compatibility"/>
      <next slug="reference-apps" title="Reference Applications"/>
    </neighbors>
    <body>
      <document xmlns="http://commonmark.org/xml/1.0">
        <heading level="1">
          <text xml:space="preserve">Security Model</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">Xao is designed to </text>
          <strong>
            <text xml:space="preserve">fail closed</text>
          </strong>
          <text xml:space="preserve"> at every trust boundary, pairing framework-level guards in PHP with PHC's Rust sandbox.</text>
        </paragraph>
        <heading level="2">
          <text xml:space="preserve">Defense-in-Depth Controls</text>
        </heading>
        <list type="ordered" start="1" delim="period" tight="true">
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">XXE &amp; DOCTYPE rejection:</text>
              </strong>
              <text xml:space="preserve"> Both </text>
              <code xml:space="preserve">DomDoc::parseXmlToDomDocument()</code>
              <text xml:space="preserve"> and </text>
              <code xml:space="preserve">PhcNativeXsltDriver::transform()</code>
              <text xml:space="preserve"> reject </text>
              <code xml:space="preserve">&lt;!DOCTYPE</code>
              <text xml:space="preserve"> and </text>
              <code xml:space="preserve">&lt;!ENTITY</code>
              <text xml:space="preserve"> declarations upfront (</text>
              <code xml:space="preserve">XmlParseException</code>
              <text xml:space="preserve"> / </text>
              <code xml:space="preserve">XsltTransformException</code>
              <text xml:space="preserve">), and PHC disables external DTD and entity loading natively.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Strict </text>
                <code xml:space="preserve">realpath()</code>
                <text xml:space="preserve"> containment:</text>
              </strong>
            </paragraph>
            <list type="bullet" tight="true">
              <item>
                <paragraph>
                  <code xml:space="preserve">DomDoc::resolveSafeFilePath($filePath, $baseDir)</code>
                  <text xml:space="preserve"> verifies canonical paths remain strictly under </text>
                  <code xml:space="preserve">$baseDir</code>
                  <text xml:space="preserve">.</text>
                </paragraph>
              </item>
              <item>
                <paragraph>
                  <code xml:space="preserve">Transformer::resolveStylesheet()</code>
                  <text xml:space="preserve"> and </text>
                  <code xml:space="preserve">PhcNativeXsltDriver::resolveStylesheet()</code>
                  <text xml:space="preserve"> reject NUL bytes, backslashes, </text>
                  <code xml:space="preserve">..</code>
                  <text xml:space="preserve"> traversal segments, absolute paths, and symlink escapes outside </text>
                  <code xml:space="preserve">$stylesheetRoot</code>
                  <text xml:space="preserve"> (HTTP </text>
                  <code xml:space="preserve">403</code>
                  <text xml:space="preserve">).</text>
                </paragraph>
              </item>
              <item>
                <paragraph>
                  <text xml:space="preserve">PHC independently sandboxes </text>
                  <code xml:space="preserve">xsl:include</code>
                  <text xml:space="preserve">, </text>
                  <code xml:space="preserve">xsl:import</code>
                  <text xml:space="preserve">, and </text>
                  <code xml:space="preserve">document()</code>
                  <text xml:space="preserve"> URIs against </text>
                  <code xml:space="preserve">sandbox.allowed_roots</code>
                  <text xml:space="preserve">.</text>
                </paragraph>
              </item>
            </list>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Slug allowlists (</text>
                <code xml:space="preserve">Xao\App\SlugValidator</code>
                <text xml:space="preserve">):</text>
              </strong>
              <text xml:space="preserve"> Slugs must match </text>
              <code xml:space="preserve">^[a-z0-9]+(?:-[a-z0-9]+)*$</code>
              <text xml:space="preserve"> (max 64 chars). Traversal sequences (</text>
              <code xml:space="preserve">..</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">/</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">\</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">\0</code>
              <text xml:space="preserve">) fail closed with HTTP </text>
              <code xml:space="preserve">403</code>
              <text xml:space="preserve">, and malformed characters fail with HTTP </text>
              <code xml:space="preserve">400</code>
              <text xml:space="preserve">.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Gated debug output:</text>
              </strong>
              <text xml:space="preserve"> Legacy 2003 Xao allowed </text>
              <code xml:space="preserve">?xao:XML</code>
              <text xml:space="preserve"> and </text>
              <code xml:space="preserve">?xao:Text</code>
              <text xml:space="preserve"> unconditionally from query parameters. Modern </text>
              <code xml:space="preserve">AppDoc</code>
              <text xml:space="preserve"> blocks debug XML/text output with HTTP </text>
              <code xml:space="preserve">403</code>
              <text xml:space="preserve"> unless </text>
              <code xml:space="preserve">$debug === true</code>
              <text xml:space="preserve"> is explicitly configured (</text>
              <code xml:space="preserve">XAO_DEBUG=1</code>
              <text xml:space="preserve">).</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Safe Markdown defaults:</text>
              </strong>
              <text xml:space="preserve"> </text>
              <code xml:space="preserve">phc_markdown_to_dom()</code>
              <text xml:space="preserve"> and </text>
              <code xml:space="preserve">phc_markdown_to_xml()</code>
              <text xml:space="preserve"> run with </text>
              <code xml:space="preserve">unsafe_html = false</code>
              <text xml:space="preserve"> by default, stripping raw HTML blocks and inline </text>
              <code xml:space="preserve">&lt;script&gt;</code>
              <text xml:space="preserve"> tags before XSLT transformation.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">CSRF protection &amp; sessions (</text>
                <code xml:space="preserve">ReferenceApp</code>
                <text xml:space="preserve">):</text>
              </strong>
              <text xml:space="preserve"> State-mutating POST routes validate per-session tokens via </text>
              <code xml:space="preserve">Xao\App\CsrfGuard::verify()</code>
              <text xml:space="preserve"> using </text>
              <code xml:space="preserve">hash_equals()</code>
              <text xml:space="preserve"> and fail closed with HTTP </text>
              <code xml:space="preserve">403</code>
              <text xml:space="preserve">.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Error suppression in HTTP responses:</text>
              </strong>
              <text xml:space="preserve"> </text>
              <code xml:space="preserve">phc.toml</code>
              <text xml:space="preserve"> sets </text>
              <code xml:space="preserve">display_errors = "0"</code>
              <text xml:space="preserve"> so host paths and stack traces never leak to clients.</text>
            </paragraph>
          </item>
        </list>
      </document>
    </body>
  </page>
</xao-docs>
