Xao / Technical Fieldnotes

Operations & Runtime · Issue 1.0.0-dev · 2 min read

Security Model

XXE rejection, realpath containment, strict slug allowlists, CSRF guards, gated debug output, and PHC sandbox enforcement.

Audience: Security reviewers and application developersWords: 266Source: content/security.md
Open library index (12 documents)

Xao is designed to fail closed at every trust boundary, pairing framework-level guards in PHP with PHC's Rust sandbox.

Defense-in-Depth Controls

  1. XXE & DOCTYPE rejection: Both DomDoc::parseXmlToDomDocument() and PhcNativeXsltDriver::transform() reject <!DOCTYPE and <!ENTITY declarations upfront (XmlParseException / XsltTransformException), and PHC disables external DTD and entity loading natively.

  2. Strict realpath() containment:

    • DomDoc::resolveSafeFilePath($filePath, $baseDir) verifies canonical paths remain strictly under $baseDir.

    • Transformer::resolveStylesheet() and PhcNativeXsltDriver::resolveStylesheet() reject NUL bytes, backslashes, .. traversal segments, absolute paths, and symlink escapes outside $stylesheetRoot (HTTP 403).

    • PHC independently sandboxes xsl:include, xsl:import, and document() URIs against sandbox.allowed_roots.

  3. Slug allowlists (Xao\App\SlugValidator): Slugs must match ^[a-z0-9]+(?:-[a-z0-9]+)*$ (max 64 chars). Traversal sequences (.., /, \, \0) fail closed with HTTP 403, and malformed characters fail with HTTP 400.

  4. Gated debug output: Legacy 2003 Xao allowed ?xao:XML and ?xao:Text unconditionally from query parameters. Modern AppDoc blocks debug XML/text output with HTTP 403 unless $debug === true is explicitly configured (XAO_DEBUG=1).

  5. Safe Markdown defaults: phc_markdown_to_dom() and phc_markdown_to_xml() run with unsafe_html = false by default, stripping raw HTML blocks and inline <script> tags before XSLT transformation.

  6. CSRF protection & sessions (ReferenceApp): State-mutating POST routes validate per-session tokens via Xao\App\CsrfGuard::verify() using hash_equals() and fail closed with HTTP 403.

  7. Error suppression in HTTP responses: phc.toml sets display_errors = "0" so host paths and stack traces never leak to clients.