Document Text

DocumentText is the platform's one answer to "what does this file say?" — the words inside a PDF, a spreadsheet, a contract, a forwarded email, without opening the file as a document. It is also the one door through which any outside bytes reach a C parser: a deliverability report, the HTML of a received message, a page the AI fetched, a captured feed.

It exists because reading a stranger's bytes otherwise means handing them to a program that will act on them, as the user that runs the site. Anywhere the platform needs a file's text — a mail attachment preview, a chat upload fed to a model, a report to file, a list snippet — it asks here, and gets text back or an honest reason why not.

The two sides, and why the split is the design

The parent side runs in a web request, a cron task, or the Postfix pipe. It answers "could this be read?" and starts the reader. It never opens the bytes: not with finfo, not with ZipArchive, not with DOMDocument.

DocumentText::isExtractable($mime);            // is this a type we can read?
DocumentText::categoryForMime($mime);          // 'pdf' | 'docx' | 'text' | …
DocumentText::mimeForExtension('invoice.pdf'); // what a filename claims
DocumentText::bestMimeGuess($declared, $filename);

DocumentText::extractPath($path, $mime, $maxChars);
DocumentText::extractBytes($bytes, $mime, $maxChars);

DocumentText::parseWith($class, $bytes, $options);       // a SandboxParserInterface class, one input
DocumentText::parseWithMany($class, $inputs, $options);  // the same class, many inputs, one subprocess

The sandbox side is utils/extract_document_text.php, a short-lived subprocess. Every byte of the document is opened there and nowhere else — sniffing, unpacking, and parsing included. A bomb, a hang, or a runaway allocation kills only that child; the parent reads the exit code and reports the file unreadable.

The isolation is not politeness. An in-process memory fatal is uncatchable, and the PDF parser retains per-document state that accumulates across files in a long-lived process — a loop over 54 real PDFs peaked at 512MB in one process versus 18–35MB per file in isolation. The subprocess is both the security boundary and the memory boundary.

Both extraction entry points return the same array and never throw:

['status' => …, 'category' => …, 'text' => …, 'detail' => …]

statusMeans
oktext is present
emptyparsed cleanly, but there is no text layer (a scanned document)
securedencrypted or permission-restricted; the parser refuses
failedparser error, timeout, or out of memory
skippednot a type anything here can read
too_largeover the caller's byte ceiling, never parsed
empty, secured and failed are kept apart because they are different facts a user acts on differently: download it and read the pages, find the password, or give up. Roughly a third of real PDFs land on one of the first two.

The parser jail

The subprocess runs under the parser jail wherever the launcher is installed: /usr/local/sbin/joinery-jail, a small setuid-root Go program (maintenance_scripts/install_tools/joinery_jail/) that takes one command line and runs it as the joinery-jail user inside an allowlist fence the command cannot leave. The command starts with nothing and is given short lists of what it may touch; anything not on a list is refused, including what a later change to the machine adds. DocumentText builds the command as joinery-jail --timeout=20 --rlimit-as=<bytes> --scratch=<bytes> --read=… --read-php=… -- php -n -d extension=… -d enable_dl=0 extract_document_text.php … (enable_dl=0 because the named extensions are the whole set: with dl() on, the subprocess could load any extension on the machine by name); the launcher carries no policy about PHP or documents. In order, it:

  1. Discards the caller's environment and replaces it (PATH, LANG, and TMPDIR naming the run's own folder).
  2. Builds the file list (Landlock): execute and read on the PHP binary and its program loader; read on the shared libraries, the loader cache and the time-zone files; listing of core's includes/ and data/ and every folder beneath them (the class loader walks them) and read on their .php files, file by file (the folders hold other files, an IP list or a certificate, which stay unreadable), on utils/extract_document_text.php, on the one handler file a parser call names, on the vendor directory and on cache/class_map.json; and read and write on one folder of the run's own under /dev/shm (below), with no remove: every byte the run writes stays in a named file the supervisor can count. No TCP connect or bind, no abstract Unix socket, no signal to a process outside the run. A grant that is a link, or passes through one, is refused before anything runs.
  3. Enters a fresh, empty network namespace where the kernel allows one (bare metal; a container cannot make one, and step 6 closes the same door either way).
  4. Sets kernel limits the command inherits: CPU seconds, file size, 256 open files, no core dumps.
  5. Becomes joinery-jail: no supplementary groups, verified by reading the ids back, not dumpable, and set to die with the supervisor (a parent-death signal, then a check that the supervisor is still there).
  6. Sets PR_SET_NO_NEW_PRIVS, applies the file list, then installs a seccomp allowlist: the system calls PHP makes reading every document type, written from a trace, and nothing else. Every argument rule is a list of exact values matched on all 64 bits (fcntl commands, prctl options, two ioctl requests, prlimit64 on its own process only). There is no socket, fork, unlink, O_TMPFILE open, inotify, System V IPC, memfd_create, chmod/chown/utime/xattr, ptrace, io_uring or setuid call; a call from another architecture's table is killed outright. It then checks, on the thread that will exec, that the filter and the Landlock domain both took, and refuses below Landlock ABI 6. Ubuntu 26.04's kernel has it; 24.04's 6.8 kernel does not. Every machine's host report tries one run through the launcher, on the machine and inside each site container, and the management node opens plane:parser_jail when it is refused (see the Server Manager overview).
  7. Sets umask 077, puts the address-space cap (--rlimit-as, the backstop for what libzip, libxml2 and the interpreter map outside PHP's own memory_limit) on itself with nothing allocated in between, and execs the command.
The launcher is two stages in one binary. The first is a supervisor: it makes its real uid root (the second stage refuses to start without that, so no caller can enter it directly), makes the run's folder, starts the fenced child, drops its own privileges to the jail user, and waits with the deadline, killing the child on expiry. It sums the run folder every 50 ms and kills the run past --scratch bytes, and removes the folder when the run ends; a folder a killed supervisor left behind is removed by a later run once it is ten minutes old. The supervisor stays outside the Landlock domain, so the command cannot signal it, and once it has dropped to the jail user the caller cannot either; it kills the run itself when its caller goes away. The wall-clock has to be enforced by something that can still signal the child after the uid change — the web user cannot signal a joinery-jail process — and the supervisor holds no root while it waits. Exit codes follow timeout(1): the command's own, 124 on the deadline, 128+signal when it died of one, 125 when the launcher refused. Its usage line carries JOINERY_JAIL_INTERFACE=2; DocumentText::jailFenced() reads that from the installed binary, and calls an installed launcher without it, one that has no file or call list, with only --timeout and --rlimit-as until the next root moment installs the current binary. The same line carries JOINERY_JAIL_FEATURES= and a list of what the launcher can do beyond the fence (watch-fd, stdin-file); DocumentText::jailFeatures() is the one reader of it, and a caller that needs a feature asks there.

What the jailed subprocess has: what step 2 lists, the bytes on stdin, and the vendor path on its argv. What it does not have: the config file, /etc, /proc, /dev/shm itself, /tmp, uploads, the rest of the tree, a database connection, a key, a network, another process. config/Globalvars_site.php is also root:www-data 0640 and the jail user is in neither, and the tree is not writable by anybody but its owner. utils/extract_document_text.php calls ClassAutoloader::restrictToCore() and PathHelper::setComposerVendorPath() before anything else, so nothing on the sandbox side ever asks for a setting — under the jail that ask would be a fatal error, not an exception. The jail protects the pool from the parser, not the parser from the pool: the web user can run joinery-jail -- anything, and what it can read as the jail user is a subset of what it reads already.

Installing it. maintenance_scripts/install_tools/install_parser_jail.sh is a core host installer, run by _plugin_installers_start.sh after the agent's at every root moment the platform has — container start, site build, an agent-run upgrade, the Run Plugin Installers action — and by hand on a box those never reached:

sudo bash /var/www/html/SITE/maintenance_scripts/install_tools/install_parser_jail.sh

It creates the user, grants the read ACL where the probe says the user cannot already read the tree (a container's tree is world-readable and needs none; on public_html and vendor the ACL states group r-x, its mask and its defaults, so the grant never leaves the executable set group-writable, and a wider grant found there is narrowed on every run), installs the prebuilt joinery_jail/bin/joinery-jail-<uname -m> at 4755 root:root, runs one command through the fence to check, lets qpdf read a run's input file where the distribution confines it with AppArmor (below, A program that reads a file), and keeps one jpx-NAME user per sandboxed PHP plugin (docs/sandboxed_plugins.md). On the management node itself, whose tree is the source and is never upgraded, a publish queues that same installer run on the node's own agent, so a new launcher lands there without a shell. Nothing is compiled on a node: ParserJailPublisher cross-compiles both architectures at publish time, and a stale launcher refuses the release.

Without it. A self-hosted box upgraded from the browser gets the launcher from the host converger, the root timer every site install leaves behind (docs/deploy_and_upgrade.md), within a minute of the upgrade. A node that has not had the installer runs the same subprocess as the web user under timeout, and says so: once per process in the error log, as an unmet check in VaultHealth, and to superadmins in the admin header (ParserJailNotice) with the command above. DocumentText::JAIL_REQUIRED would turn a missing launcher into a refusal to parse; it stays false, because a self-hosted box whose owner never runs the installer keeps the previous posture rather than losing previews, reports and fetched pages. Managed nodes are always jailed: the agent-run upgrade installs it.

Sandbox parsers

The document formats are DocumentText's own. Anything else that opens outside bytes with a C parser is a class implementing SandboxParserInterface:

class DeliverabilityReportParser implements SandboxParserInterface {
    public static function sandboxParse(string $bytes, array $options): string { … }
}

$r = DocumentText::parseWith('DeliverabilityReportParser', $bytes);   // $r['text'] is what sandboxParse() returned
$texts = DocumentText::parseWithMany('MailboxHtmlSanitizer', $htmls, ['op' => 'readable']);  // keyed like $htmls, null per failure

The parent side resolves the class to its file and hands the subprocess the path, the class name, and the options as JSON; the subprocess loads that one file (it must be inside the code tree), checks the class implements the interface, and calls sandboxParse() with the bytes from stdin. What comes back is a string: text, a fragment, or a JSON document for structured results. parseWithMany() sends many inputs as one JSON array and gets one array back — a page of fifty list rows is one spawn, not fifty.

What a sandboxParse() may rely on, and nothing more: the bytes, the options, core classes under includes/ (DocumentText::xmlDoc() is the one XML door), and its own file. It must not name a plugin class, read a setting, or reach for a model; it runs with none of them. Throw DocumentTextException to refuse with a kind; any other throw is a failed parse.

A parser's own data folder. The fence grants a handler its own file and core's .php files, and nothing else of the tree. A handler whose library reads data files (font definitions) declares the folders:

public static function sandboxReads(): array {
    return array(PathHelper::getRootDir() . '/includes/pdf_fonts');
}

A grant on a folder is every file beneath it, so DocumentText::sandboxReadFolders() holds an allowlist: each entry is a real directory with no link on the way to it, under core's includes/ or under the handler's own plugin folder, and is neither the folder the handler file sits in nor any folder above it. One refused entry fails the parse before anything is started, with the reason.

The parsers in the tree:

ClassOpensReturnsFor
DeliverabilityReportParser (mailbox)a report attachment: zip or gzip holding DMARC XML, or TLS-RPT JSON{kind, extract, error} — the flat record the ingest filesmail arriving on the Postfix pipe, in cron, and on Refresh
MailboxHtmlSanitizer (mailbox)received HTMLreadable one-line text (op: readable), or the print sheet's sanitized fragment (op: print)the thread list and search index, the print sheet
GmailFilterExportParser (mailbox)a Gmail mailFilters.xml export{entries: [[name, value], …]}the filter import
FetchUrlReader (joinery_ai)a fetched web page{text, note} — reader-mode Markdown with its fallbacks, or the full flattenthe AI's fetch_url tool
ScanUrlPageResources (dns_filtering)a fetched web pagethe list of resource URLs it refers tothe URL scan
FacebookFeedExtractor (persona_browser)a captured feed's markup{items, stories}the persona browser
ImageCutter (core)an uploaded image{type, variants}: every size asked for, encoded, or a refusal in wordsevery thumbnail and size the site cuts (FileBlob::resize(), ensure_variant())
PdfComposer (core)an outside PDF and the images to put on ita line of JSON (page sizes, warnings, the seal's byte range), then the PDF as base64every PDF the site writes (PdfWriter, PDF Writer)
tests/security/parser_surfaces_test.php pins the rule: a file that names ZipArchive, DOMDocument, loadHTML, simplexml_load_string, gzdecode, PharData, one of GD's image readers, getimagesize, exif_read_data, or a libmagic function (finfo_*, mime_content_type) is a sandbox parser, DocumentText itself, or on that test's list with the reason its bytes are not a stranger's (a package we signed, the owner's own import, a provider's API answer under our credentials). It pins the PDF rules the same way: the PDF library's document classes are named only in PdfComposer, its signing classes only in PdfSeal, and the qpdf program only in PdfWriter.

Images

An uploaded picture is outside bytes like any other, and making a thumbnail hands it to libjpeg, libpng, libwebp, libavif, giflib and the EXIF reader. No web worker opens one. FileBlob::resize() calls ImageCutter::cut(), which sends the file's bytes to the subprocess and gets back each size already encoded; the caller writes those bytes to disk and never reads them as an image.

$cut = ImageCutter::cut($path, ImageSizeRegistry::get_sizes(), $max['width'], $max['height']);
// $cut['variants'][$size_key] is that size's bytes; throws ImageDecodeRefused with words a user can read

Inside the subprocess ImageDecoder reads the header, refuses a decode that would cost more than the ceiling it was handed (ImageDecoder::ceiling_mb(), worked out by the caller, where the setting and the machine's memory can be read), decodes once, turns the picture upright, and cuts every size from that one image.

A large JPEG takes three short runs. The first reads the header and answers how far the JPEG can be shrunk while it is decoded. ImageDecoder::shrink_jpeg() then runs djpeg -scale M/8 through DocumentText::runTool(), which fences a program the same way the extractor is fenced: the bytes on stdin, a BMP on stdout, the program's own binary the only thing of the site it can read. The second run cuts the sizes from that small picture. Without djpeg on the machine the JPEG is decoded in full, at more memory.

A GIF's colours are reduced by ImageCutter itself. GD's own reduction goes through a library that starts threads, and the fence has no call that makes one. The picture is mapped to its colours first and the one see-through entry is given afterwards, only to the pixels the source says are see-through, so no colour of the picture can fall through.

What comes back has a ceiling. A subprocess's answer is collected in the caller's memory, and a web worker that runs out of memory dies in a way no caller can catch. DocumentText::MAX_ANSWER_BYTES (32 MB) stops a parser that answers more, and runTool() takes its own ceiling. ImageCutter asks for a shrunk JPEG only when the source and its shrunk copy together fit 48 MB (WORKER_BUDGET_BYTES), and holds the cut's own answer to what that budget leaves (never under 16 MB); otherwise the JPEG is decoded in full inside the fence, where the ceiling refuses it in words if that does not fit either. The scale the fenced side names is held to a shrink before djpeg is given it.

A file over 48 MB (ImageCutter::MAX_SOURCE_BYTES) is kept as uploaded with no sizes, as is one the ceiling refuses; fbb_variant_refused records why. A run killed for memory records nothing, so the next view tries again.

A program that reads a file

qpdf cannot read its standard input, and standard input is how bytes reach a fenced program. DocumentText::runTool() hands such a program its input as a file: the caller passes $stdin_as_file and puts DocumentText::STDIN_FILE_TOKEN ({stdin-file}) in the arguments where the path belongs.

  • Under the launcher it runs with --stdin-file=1. The launcher, already the run's own user and tied to its supervisor, copies standard input into a new 0600 file named input in the run's folder, puts that path where the token stood, points standard input at /dev/null, then closes the fence and starts the program. The copy stops at the folder's size limit with exit 125 before the program runs, and the supervisor's deadline and its count of the folder cover the copy.
  • A launcher without stdin-file on its features line starts nothing: the answer has unavailable set. The program is never run outside the fence on a box that has one. This is the state between an upgrade and the next root moment.
  • With no launcher, or not fenced, the caller writes the bytes to a 0600 file of its own in the temporary directory, substitutes the path, and removes the file when the program ends. Before writing, it removes its own files of that prefix (joinery_tool_input_) older than the timeout plus a minute, which is what a killed worker leaves. $stdin_as_file may be an extension ('pdf') for that file.
unavailable is decided from what is installed, before anything runs. Exit 125 is never read as it: 125 also means an input over the limit or a full /dev/shm.

AppArmor. Ubuntu's qpdf package ships an AppArmor profile that lets qpdf read *.pdf in a home directory, the temporary directory and a few other places, and nothing in /dev/shm. The profile applies inside the fence too. install_parser_jail.sh writes a marked block into /etc/apparmor.d/local/qpdf, which the profile includes, allowing a read of /dev/shm/joinery-jail-run.*/input by its owner, and reloads the profile where it is in force. Other lines in that file are kept; a block with one mark missing is left alone with a warning. A site container runs under the container runtime's profile and is not affected. The caller's own file, where there is no launcher, carries the .pdf extension in the temporary directory, which the stock profile allows.

What kind of file is this

Asking a file's type from its content is a job for libmagic, a C library that reads dozens of formats' headers, and every stored file is asked: an upload, a Drive file, an attachment on mail from anyone. No web worker, cron task or mail pipe runs it. File::detect_mime_file() and File::detect_mime_bytes() answer in two steps:

  1. The first bytes, in plain PHP (File::leading_signature()): PNG, JPEG, GIF, WebP, AVIF and a PDF that starts with its marker. String compares, no parser, no cost. These are most uploads.
  2. Everything else is asked outside the worker (MimeSniffer::sniff()): the file program, the same libmagic as PHP's own, run through DocumentText::runTool() with the bytes on stdin and its magic database the one other thing it may read. About 8 ms. file is a declared system package (composer.json extra.joinery-system-packages); where it is missing, PHP's fileinfo answers in the extraction subprocess instead, slower by the cost of starting PHP.
An answer that is not a plain type/subtype is application/octet-stream: unknown bytes, the least trusted kind. A question that could not be asked at all (the launcher refused, the run timed out or was killed) is asked once more, and then also stored as unknown bytes, with File::$mime_was_unasked set and a line in the log. That is a different fact from "libmagic does not know", so it does not stand for good: FileBlob::createFromPath() asks again when the same bytes next arrive, and corrects the blob and the files that took their type from it. A launcher that refuses to start, which is never something the bytes did, is answered by file without the fence, the privilege libmagic had in the worker; a run that timed out or died is not, since the bytes may be why. The answer is null only for a path that cannot be read.

Formats

CategoryReads
pdfPDF, via pure-PHP smalot/pdfparser
htmlHTML and XHTML — visible text, with script/style/head removed
textplain text, Markdown, CSV, JSON, YAML, TOML, SQL, shell, and any other text/*
docxWord — body, headers, footers, footnotes, endnotes
xlsxExcel — rows tab-separated, sheets labelled, cell text resolved through sharedStrings
pptxPowerPoint — per-slide text plus speaker notes
odfOpenDocument text, spreadsheet, presentation
docWord 97-2003 — body, footnotes, endnotes, headers; a field shows its result, a table reads as tabs and lines
epubEPUB — chapters through the HTML branch
rtfRTF, body text only
xmlXML and SVG — text values, one per line
emla forwarded message: From/To/Cc/Date/Subject plus the text body
icsa calendar invite, as a readable event summary
archiveZIP — a manifest of entry names, sizes and dates. Nothing inside is decompressed
The office formats need no dependency at all: OOXML, OpenDocument and EPUB are ZIP plus XML, and zip, dom and libxml are already loaded. A Word 97-2003 .doc is read with byte arithmetic alone: its compound file (a small FAT file system) is walked with every sector chain bounded by the file's sector count and stopped on a revisit, and its piece table may claim no more characters than its text stream has bytes. An encrypted .doc is secured; Word 95 and older fail. The mailbox's browser reader (mailbox_doc_text.js) follows docText() function for function, held to it by plugins/mailbox/tests/doc_text_gate.sh over real Word files from Apache POI's test data.

Not read, deliberately: legacy binary Excel and PowerPoint (.xls, .ppt), Outlook .msg, iWork, .7z/.rar, and encrypted databases like .kdbx. Each of the first four needs a reader the platform does not have; the last is encrypted and correctly unreadable. No text is read out of an image — there is no OCR anywhere on the platform.

The security properties

  1. Everything that touches the bytes runs in the subprocess, as the jail user. Including type detection, for a document and for every stored file alike: libmagic, libzip and libxml are C, which is exactly why they run nowhere else. A parser bug corrupts a process that can read the bytes it was given and nothing else.
  1. Detected type, never declared. The sandbox sniffs the bytes with finfo_buffer and parses only what it found. The MIME the caller passes is a hint, consulted when detection is inconclusive. This matters because senders lie: most real PDFs arrive declared application/octet-stream.
  1. One XML door. DocumentText::xmlDoc() holds the class's single loadXML() call; every XML-reading branch, and every sandbox parser, goes through it. It passes LIBXML_NONET affirmatively and never passes LIBXML_NOENT, LIBXML_DTDLOAD or LIBXML_PARSEHUGE. That first omission is load-bearing: with LIBXML_NOENT, an entity declaring SYSTEM "file:///etc/passwd" puts that file's contents straight into the extracted text; without it the same document is inert. A branch or a parser that calls loadXML() for itself is a defect, and the tests fail on one at the source level.
  1. Containers are bounded before they are read — per-member size (12MB), summed size (40MB), compression ratio (200:1 above 1MB), and a cap on parts. A 61KB file expanding to 60MB is refused, not discovered by the memory limit.
  1. Nothing is written to disk. Every entry point sends the bytes down the subprocess's stdin — extractPath() reads the file in the caller and streams it too, so the jail user never needs to open a caller's path — and decrypted content never lands on disk-backed storage. ZipArchive can only open a file, so a container is staged in memory-backed tmpfs, 0600 and the jail user's own, and unlinked the moment the parser has it open — the open handle keeps reading, so a timeout or kill mid-parse leaves nothing behind. Under the jail the staging goes in the run's own folder, which no other run can reach; the run cannot unlink, so the file stays named while it is parsed, is emptied by a truncating open when the parse ends, and goes with the folder, which the launcher removes when the run ends, killed or not. Without the jail it goes in /dev/shm, and each child sweeps, at startup, any staging a killed predecessor left older than a live child could still be holding (/dev/shm is sticky, so only the user that staged a file may remove it). A missing or unwritable staging folder is a refusal, never a fallback to /tmp. Two files are whole for longer, both for a program that reads a file and not its standard input (above): under the jail, the input the launcher stages stays in the run's folder until the run ends, because the run cannot unlink it and nothing of ours runs after the program; if the supervisor itself is killed, the file stays, readable by the jail user and root only, until a later run removes folders older than ten minutes. Without the jail, the caller's own input file is in the temporary directory, which may be disk, for as long as the program runs; a worker killed mid-run leaves it until the next such call sweeps it.
  1. Metadata is not content. RTF \info (title, author), OOXML docProps, and EPUB OPF metadata are excluded. An RTF stripped with a regex leaks all three, because destination groups nest — the RTF branch is a brace-depth state machine for exactly that reason.
  1. Output is always valid UTF-8. The text crosses a JSON boundary and json_encode() fails outright on a malformed sequence, so charsets are converted with substitution and truncation is multibyte-safe.

Calling it

The parent must not write all of stdin before reading: up to 15MB can go down that pipe, and a child that rejects the input early and writes to stdout leaves both sides blocked, which the deadline turns into a guaranteed 20-second stall. extractBytes() pumps with stream_select for this reason. Callers get that for free — the point is not to reimplement the spawn.

Consumers should apply their own byte ceiling before calling, because the cheapest parse is the one that never starts. And a caller with many documents should call once: parseWithMany() for a parser class, one spawn per page or per chunk of a fold, never one per row.

Measured on dev: a bare php -r 'exit;' is 0.12 s and the extractor on a one-line text file 0.18 s; the launcher adds one execve and a handful of syscalls.

joinery_ai

AiAttachment owns policy — which types the chat accepts, per-category byte caps, model capability gating, untrusted-input framing — and delegates every read here. Its four stored statuses (aia_extract_status) are aliases of the core constants; secured and too_large collapse to failed, because for send-time routing an encrypted PDF is simply one with no readable text, and blocksForAttachment() then offers the original to a document-capable model.

The chat's accepted set is AiAttachment::CATEGORY, and it stays narrower than what this class can read — an upload there becomes part of a model payload, so what the chat accepts is a decision about what a model ingests, not a consequence of the extractor learning a format. Archives are refused there for that reason, and so is SVG.

Two rules make the container formats safe to accept. resolveUploadMime() consults the filename only when detection landed on a bare container and the name claims a format built on one — a real need, because Office and OpenDocument files are zips and libmagic tells them apart by convention. It can never reach image or pdf, the categories that send raw bytes to a model. And whatever gets past that, categoryForCoreCategory() compares the category this class reports after actually opening the bytes against the one ingress accepted, so a plain zip renamed .docx is refused after the fact.

fetch_url downloads a page in the pool with every URL checked, converts the charset, and hands the body to FetchUrlReader; the DOM walk, the reader-mode escalation and the full-page flatten all run in the jail.

mailbox

The reader's Preview button calls mailbox/attachment_text, which gates on mailbox-grant scope exactly as the download endpoint does, applies mailbox_preview_max_bytes, throttles per IP, and hands the bytes here. A deliverability report is recognised and filed by DeliverabilityReportIngest, which never opens the attachment: DeliverabilityReportParser does, in the jail, and answers with the record. The thread list's HTML-only previews and the search index's HTML bodies go through MailboxHtmlSanitizer::toReadableTextMany(), one subprocess per page or per chunk of a fold. See the Mailbox plugin overview.

Tests

tests/unit/document_text_test.php (safe tier). Fixtures are generated at run time by tests/fixtures/documents/generate_fixtures.php, so the suite carries no binary blobs and each fixture's tricky bit stays visible in source: the sharedStrings indirection, the RTF \info group, the XML that tries to read /etc/passwd, the 61KB zip that expands to 60MB. Its last sections exercise parseWith()/parseWithMany() through JailProbeParser, a fixture class that reports what the subprocess can do, and — where the launcher is installed — prove the fence from inside: the uid, no socket, no fork, no write into the tree, no read of the site config, staging 0600. Two more sections cover a handler's declared folders (each refused shape of declaration, and from inside the fence that only the declaring handler reads the folder) and runTool() handing a program a file (each launcher age, the caller's own file, the sweep).

tests/security/parser_jail_gate.sh (safe tier, needs: [parser-jail]) proves the launcher from outside on a box that has it: the setuid install, the scrubbed environment, the refusals, the deadline, the address-space cap, and one extraction through the fence. tests/security/parser_surfaces_test.php pins that no file in the pool names a C parser on outside bytes. tests/vault/vault_health_test.php covers the health check.

The OOM branch (exit 137) is not covered automatically; exercise it by hand against a crafted file.