Architecture & Security
WordGit uses a layered "unified Rust core + lightweight editor clients" architecture. All core version-control and security logic lives in a single Rust core engine; the Word and WPS add-ins are only responsible for the native UI and for calling the editor's own compare / tracked-changes features.
Layers at a Glance
┌──────────────────────────────┐ ┌──────────────────────────────┐
│ Microsoft Word (Windows) │ │ WPS Writer (Win/Linux/macOS)│
│ .NET 4.8 COM Add-in (src/) │ │ WPS JS Add-in (addin-wps/) │
└──────────────┬───────────────┘ └──────────────┬───────────────┘
│ HTTP 127.0.0.1 + x-wordgit-token │
└──────────────────┬─────────────────┘
▼
┌────────────────────────────────────┐
│ wordgit local service │
│ (crates/wordgit) │
│ HTTP API · Setup · CLI commands │
└──────────────────┬─────────────────┘
▼
┌────────────────────────────────────┐
│ wordgit-core (crates/wordgit-core)│
│ Chunked snapshots · Semantic diff │
│ Branches / returned drafts │
│ Remote sync · Auto compaction │
│ Crash recovery │
└────────────────────────────────────┘Source Tree Overview
| Folder | Responsibility |
|---|---|
crates/wordgit-core/ | Pure-Rust version history core: content-chunked snapshots, .docx semantic diff summaries, Git invocation wrapper, branches and returned-draft merges, remote sync, background compaction and crash recovery |
crates/wordgit/ | The resident local HTTP service wordgit (also provides the installer and CLI subcommands) |
src/ | The Microsoft Word COM add-in for Windows (no VSTO dependency): ribbon, left and right task panes, Settings window, light/dark theme support, the AI commit assistant and adaptation to Word's native merge |
addin-wps/ | The cross-platform WPS Writer JS add-in (ribbon, panes, settings and dialogs, cross-platform update tests) |
ui/, i18n/ | The single definition of the ribbon structure, plus the Word, WPS and kernel interface text per language (zh-CN, en); the generator scripts/generate-ui.js builds both add-ins' ribbons and text tables from them |
packaging/ | The standalone self-extracting Windows setup / maintenance program (Setup.exe) and UI verification tools |
tests/ | Automated tests for core integration, UI layout, sidebar first frame and the installer |
website/ | This official website and online manual (VitePress) |
Local Service Security Boundary
To prevent web pages or other untrusted processes on the machine from abusing the local service, the WordGit core engine enforces the following protections:
- Loopback-only listening: the HTTP service is strictly bound to
127.0.0.1and exposes no port to the internet or the local network. - Random token authentication: each start generates a random 48-character hexadecimal token and writes it to
service.jsonin the current user's runtime folder (deleted when the service exits). Every endpoint except the/api/v1/pinghealth check requires a validx-wordgit-tokenrequest header. - Strict Host / Origin checks: cross-site or invalid
Host/Originrequests from browsers are rejected, blocking DNS rebinding and CSRF-style attacks. - Isolated Git subprocesses: all
gitinvocations go throughcrates/wordgit-core/src/git.rs, which clears inheritedGIT_*environment variables, enablescore.longpathsandcore.fsync=committed, and supports timeouts with cleanup of the entire process tree. - Settings and secrets kept by the kernel: the settings shared by Word and WPS live in
settings.jsonin the runtime folder (permission0600on Unix). The AI Summary API key is encrypted with DPAPI for the current user on Windows and protected by file permissions on other systems; the settings endpoint never returns the key, and the add-ins fetch it only right before sending an AI request. - Redacted diagnostics packages: when a diagnostics package is exported, user folders, user names, the service token, the saved API key,
Bearerandx-wordgit-tokenvalues, common access tokens and sign-in details in URLs are replaced with[REDACTED]or placeholders, and no document content is included.
Two-Phase Document Replacement Protocol
To avoid half-written files caused by the editor holding a file open or crashing, every operation that rewrites the user's working file (Switch Branch, Restore, Finish Merge, Pull) strictly follows a two-phase transaction:
- Create a plan: the add-in asks the core engine to create a replacement plan, and the core engine locks the document (the lock expires automatically after 10 minutes);
- Close the document and apply: the add-in closes the current document in the editor and calls
plan/apply; the core engine writes a recovery log (journal), backs up the working document, performs an atomic replacement and then tells the editor to reopen it; - Roll back on failure: if the user cancels,
plan/cancelis called to release the lock immediately; if something crashes midway, the journal is used to recover automatically on the next start.
Building from Source and Contributing
Issues and pull requests are welcome. For local build, test and container verification commands, see DEVELOPMENT.md in the repository.
