Files
zemion efd80eb18a
Verify / verify (push) Canceled after 0s
Release EPUB Tools 0.2.0
2026-09-02 08:53:49 +02:00

2.8 KiB

Architecture

The app is a relocatable static React application using the Toolbox shell and contract. EPUB work is divided into small TypeScript modules under src/epub/:

  • archive.ts applies ZIP/path/entry/ratio limits, opens the container with zip.js, and reports bounded phase/item progress to the workbench.
  • adapters.ts turns bounded UTF-8 HTML/XHTML, Markdown, and plain text into a deterministic one-chapter EPUB workspace before the same archive validation path runs. The HTML adapter retains only a small structural element/attribute allowlist; Markdown implements a documented lightweight subset.
  • xml.ts, package.ts, and paths.ts decode bounded XML, reject DTD/entity input, parse OPF/navigation/NCX, and resolve package-relative references without traversal.
  • validation.ts performs bounded package and cross-document diagnostics and reports skipped scope.
  • reader.ts sanitizes content with DOMPurify, neutralizes regular/namespaced navigation, rewrites bounded packaged stylesheets/fonts/images/media and CSS URLs to local object URLs, injects a restrictive iframe CSP plus direction/layout/theme metadata, and returns cached URLs with an explicit revocation lifecycle.
  • search.ts extracts bounded inert reading-order text and performs cancellable literal search. annotations.ts validates deterministic, publication-scoped bookmark/annotation interchange without silently persisting book data.
  • export.ts patches Dublin Core metadata and streams entries into a fresh normalized EPUB. It also produces JSON, cover, chapter, reading-order text, text-centric Markdown, and standalone HTML. The HTML path replaces packaged media, removes links and active controls, then applies a strict DOMPurify structural element/attribute allowlist before adding a deny-by-default CSP.

zip.js receives a lazy browser BlobReader, performs CRC checks when entry data is read, and can use web workers. React retains one open reader and closes the previous reader when a new book replaces it. The original File is immutable; all changes exist only in staged React state or a newly downloaded Blob.

The safe reader uses both sanitization and an iframe with allow-same-origin but without scripts, forms, popups, navigation, downloads, modals, or device permissions. Same-origin access lets the trusted parent intercept inert EPUB links, scroll to a target fragment, and read an explicitly selected quote. Its srcdoc adds default-src 'none' and permits only inline styles plus local data/blob image/font/media URLs. Publisher stylesheets are size/count bounded; imports and network URLs are removed, while CSP remains the final network boundary. A mutation observer synchronizes explicit light/dark reader tokens with Toolbox preference changes; system mode follows the browser media preference.