Threat model in one line: the adversary controls the content of Markdown files (and the files next to them) that the user opens — e.g. a README in a cloned repository, an e-mail attachment, an AI-generated file — and may also control other files the user drags in or pastes. Other processes of the same user are semi-trusted; other users and the network are untrusted. Assets to protect: the user's files and their integrity, the user's credentials (including NTLM hashes), the system's integrity, and the user's privacy.
- S-NET-01 MUST No networking code in the product: no socket, HTTP, DNS, TLS or WebSocket APIs or crates (bans in S-SUP-03).
- S-NET-02 MUST Nothing referenced by a document is ever fetched from a network: remote images, fonts, includes, iframes → placeholders. Never pass document-derived strings to APIs that can fetch (URL monikers,
URLDownloadToFile*,SHCreateStreamOnFileExwith URLs, WIC decoders created from URLs,LoadImageon UNC paths). - S-NET-03 MUST Automated binary check (
cargo xtask check-imports): the import and delay-import tables ofyamdv.exeMUST NOT containws2_32.dll,wsock32.dll,mswsock.dll,winhttp.dll,wininet.dll,urlmon.dll,dnsapi.dll,iphlpapi.dll,webio.dll,httpapi.dll,netapi32.dll,mpr.dll,rasapi32.dll,wlanapi.dll,winhttpcom.dll, nor functions namedURLDownloadToFile*,URLOpenStream*,Internet*,WinHttp*,socket,WSA*,connect,getaddrinfo,GetAddrInfo*. (System DLLs loaded at runtime by Windows itself — e.g. shell extensions inside the file dialog — are outside our control;memprobelists loaded modules so they are visible.) - S-NET-04 MUST The only outward hand-offs, both user-initiated and leaving our process: (a) a validated
http/https/mailtoURL passed to the default handler viaShellExecuteExW(R-LINK-04), (b) the hard-codedms-settings:defaultapps…URI (R-SYS-02). - S-NET-05 MUST Verification step in every release QA: with an outbound-block firewall rule for
yamdv.exenothing changes, andnetstat -ano/ Resource Monitor show no sockets owned by the process.
- S-PROC-01 MUST First statements in
main:SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32); anyLoadLibraryExWusesLOAD_LIBRARY_SEARCH_SYSTEM32with a bare system DLL name. Never load DLLs from the exe folder, the current directory or a document folder (DLL planting is the #1 risk for a portable exe inDownloads). - S-PROC-02 MUST
SetDllDirectoryW(""),SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT). - S-PROC-03 MUST
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, …). - S-PROC-04 MUST
SetProcessMitigationPolicy:ProcessImageLoadPolicy(NoRemoteImages, NoLowMandatoryLabelImages, PreferSystem32Images),ProcessStrictHandleCheckPolicy. SHOULDProcessDynamicCodePolicy(ProhibitDynamicCode) if DirectWrite, the renderer, WIC, IMEs, file dialogs and printing all keep working (test and record in an ADR). MUST NOT enableProcessExtensionPointDisablePolicy(breaks IMEs/accessibility),ProcessSignaturePolicy(breaks printer drivers/IMEs),ProcessFontDisablePolicy(breaks per-user fonts). - S-PROC-05 MUST Build hardening: ASLR + high-entropy VA, DEP/NX, Control Flow Guard, CET shadow-stack compatible, static CRT, no RWX sections,
overflow-checks = true,panic = "abort". Verified by xtask (PE header flags) in CI. - S-PROC-06 MUST Manifest
asInvoker; never request elevation. If running elevated, show a banner "Running as administrator is not recommended". - S-PROC-07 MUST Child processes only for: the external editor (user action); the dialog host — a second instance of our own
yamdv.exe, started by absolute path (GetModuleFileNameW) with the internal flag--dialog-host, which shows exactly one native file-open/save or print dialog, runs one print/PDF export job (ADR-0018) or performs one taskbar jump-list update, and exits; and the self-install/uninstall helper — nothing else. Showing a file in Explorer usesSHOpenFolderAndSelectItems(no process launch by us). - S-PROC-08 MUST Security-relevant behavior never depends on environment variables or
PATH(noMD_EDITOR-style variables; executables are resolved to absolute paths from known locations /App Paths).
- S-FILE-01 MUST Writes happen only to: the open document (explicit save / autosave in edit modes only), the assets folder (S-FILE-05), export targets chosen in a Save dialog or via CLI
-o, the YAMDV config/state/log/recovery folders, and the install folder during--install. Read mode never writes the document, with one opt-in exception: whenreading.task_toggle_in_read_modeis on, clicking a task checkbox performs a single edit of that[ ]/[x]marker through the editor's save path (atomic save and conflict detection, available from Phase 006). - S-FILE-02 MUST Reads happen only from: the opened document, resources per S-RES, YAMDV config files, OS-provided fonts/codecs, and directory listings (names/attributes only) for the Files tab and wikilink resolution.
- S-FILE-03 MUST Atomic save: write a hidden temp file in the same folder (
.~<name>.yamdv-<random>.tmp,CREATE_NEW),FlushFileBuffers, thenReplaceFileW(keeps ACLs/attributes), falling back toMoveFileExW(MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH). On any failure the original stays intact, the temp file is removed, the buffer stays dirty and an error is shown. Never clear the read-only attribute. If the document path is a symlink, write the final target (GetFinalPathNameByHandleW), never replace the link itself. - S-FILE-04 MUST Path validation for every path that comes from a document, IPC, CLI or config: normalize with
GetFullPathNameW; reject device namespace paths (\\.\,\\?\GLOBALROOT), reserved device names (CON PRN AUX NUL COM1–9 LPT1–9, with or without extension, any case), alternate data streams (:beyond the drive letter), and embedded NULs. Long paths are handled internally with\\?\. - S-FILE-05 MUST Assets sandbox: the target folder
<doc_dir>/<assets_dir>/<doc_stem>/must, after creation andGetFinalPathNameByHandleW, still be inside<doc_dir>(rejects.., absolute values, junction/symlink escapes). File names are sanitized (remove<>:"/\|?*and control characters, trim trailing dots/spaces, avoid reserved names, max 120 UTF-16 units) and created withCREATE_NEW(never overwrite). - S-FILE-06 MUST Temporary files only in the document folder (atomic save) or
<LocalAppData>\YAMDV\tmp\<random>\resolved withSHGetKnownFolderPath(FOLDERID_LocalAppData), never from environment variables (export staging and print/PDF jobs; S-PROC-08), created withCREATE_NEW, deleted on success, on failure and at exit. - S-FILE-07 MUST Config/state parsing is defensive: ≤ 4 MB per file, ≤ 64 KB per line, unknown keys ignored, values clamped to their ranges, nothing ever executed; corrupt files renamed to
*.corrupt-<timestamp>and defaults used. - S-FILE-08 MUST File watching covers only the open document's folder (non-recursive), the config folder, and the folders currently expanded in the Files tab (each non-recursive, at most 32; a collapsed folder stops being watched); buffer overflow → full reload of the document, or a re-list of that folder.
- S-FILE-09 MUST
.lnk,.urland other shell-link files are never followed or resolved automatically. - S-FILE-10 MUST Data integrity: never normalize line endings, never strip/add a BOM, never re-format untouched blocks, never write in read mode (also R-EDIT-01/02).
- S-RES-01 MUST Allowed image sources: relative paths, absolute local paths on local fixed/removable drives,
file:///X:/…(local), anddata:image/(png|jpeg|gif|bmp|webp|x-icon|tiff);base64,…. - S-RES-02 MUST Network-location blocking (prevents NTLM credential leaks): block UNC paths (
\\server\share\…,//server/share/…,\\?\UNC\…),file://host/…, WebDAV forms (\\host@SSL\…,\\host@port\…), and paths on mapped network drives (GetDriveTypeW == DRIVE_REMOTE) — before anyCreateFileW/WIC call. Exception: if the user opened the document itself from a network location, resources on the same server and share are allowed. Additionally open local resources withFILE_FLAG_OPEN_REPARSE_POINTfirst; if the final component is a symlink/junction whose target is a network path, block it. - S-RES-03 MUST Never fetch remote (
http,https,ftp, …) resources; show the offline placeholder. - S-RES-04 MUST Limits: image file ≤ 50 MB;
data:URI ≤ 10 MB decoded; dimensions ≤ 16 384 × 16 384 and ≤ 64 megapixels (checked from the header before decoding); animated GIF ≤ 1 000 frames; decoded-image cache within the Appendix D budget. - S-RES-05 MUST Referenced files are only ever decoded as images — never opened with another app automatically. Exports embed only files that decoded successfully as images (so
can never be exfiltrated into an exported HTML/PDF). - S-RES-06 MUST Fonts come only from the system/user font collections via DirectWrite; documents cannot load fonts.
- S-RES-07 MUST SVG images: no external references (only same-document
#idreferences are resolved;href/xlink:href/url()to files or URLs are ignored), no scripts, noforeignObject, no event attributes, no CSS@import; DTDs and entity declarations are rejected (no entity expansion); limits: file ≤ 10 MB, ≤ 50 000 elements, nesting ≤ 64,usedepth ≤ 8 and ≤ 10 000 resolved instances, ≤ 1 000 000 path commands; rendering is bounded by the display size and the S-RES-04 pixel limits.
- S-LINK-01 MUST External schemes allowlist:
http,https,mailto(ASCII-case-insensitive). Every other scheme is inert (R-LINK-06). - S-LINK-02 MUST Before hand-off: the URL is parsed and re-serialized; rejected if it contains control characters, unescaped spaces or quotes, or exceeds 2 048 characters. The Ask popover shows the real destination; internationalized host names are shown with their punycode form (homograph protection); a credential part (
user:pass@) is highlighted as suspicious. - S-LINK-03 MUST Local link targets: Markdown family → open in YAMDV; folders →
SHOpenFolderAndSelectItemsafter confirmation; "open with default app" only after confirmation and only for this extension allowlist:png jpg jpeg gif bmp webp tif tiff ico svg pdf txt log csv tsv json yaml yml toml xml docx xlsx pptx odt ods odp mp3 wav ogg flac mp4 webm mkv mov— everything else (includingexe com scr pif bat cmd ps1 psm1 vbs vbe js jse wsf wsh hta cpl msc msi msp msu reg lnk url scf inf jar appref-ms application settingcontent-ms library-ms search-ms searchconnector-ms theme themepack diagcab chm hlp iso img vhd vhdx dll sys docm xlsm pptmand extension-less files) is blocked (R-LINK-05). Confirmation dialogs focus Cancel by default. - S-LINK-04 MUST Mark-of-the-Web: if the document has a
Zone.Identifierstream withZoneId≥ 3, show a banner "This file came from the internet" and always Ask before any external link or local file launch, regardless of settings.
- S-HTML-01 MUST There is no HTML engine. Raw HTML is tokenized by a small bounded tokenizer and mapped to the allowlist (R-MD-14). Unknown elements are dropped but their text content is kept; these containers are dropped with their content:
script style iframe frame frameset object embed applet form input button select textarea template noscript link meta base title head svg math(inline SVG/MathML → placeholder). - S-HTML-02 MUST Only allowlisted attributes survive; all
on*attributes andjavascript:/vbscript:/data:(except image data URIs inimg src) values are removed;styleaccepts onlycolor,background-color,text-alignwith a strict value grammar (hex,rgb(), named colors;left|center|right|justify); everyhref/srcgoes through S-LINK / S-RES. - S-HTML-03 MUST Limits: nesting depth 64, 100 000 tags per document, 8 KB per attribute value.
- S-EXEC-01 MUST No eval, scripting, macros, plugins, or dynamic code loading of any kind.
- S-EXEC-02 MUST Launching local files: only per S-LINK-03.
- S-EXEC-03 MUST Processes are started only with
CreateProcessWwithlpApplicationName= absolute path to an existing.exe(verified not to be a network path or a reparse point to one), arguments quoted per the MSVC/CommandLineToArgvWrules (unit-tested round-trip). Nevercmd.exe, PowerShell,.bat/.cmd/.ps1targets (the "BatBadBut" class of injection). - S-EXEC-04 MUST
ShellExecuteExWis used only for: validated external URLs, the constantms-settings:URI, and allowlisted local files after confirmation. Never passSEE_MASK_NOZONECHECKS.
- S-IPC-01 MUST Single instance via a named mutex
Local\YAMDV-<hash of user SID>; arguments forwarded withWM_COPYDATAto the primary window,dwData= magic constant, payload = versioned UTF-16 structure (magic, version, count, paths/flags), ≤ 64 KB. - S-IPC-02 MUST The receiver verifies the sender's process runs as the same user (token SID comparison) and ignores anything else.
- S-IPC-03 MUST Forwarded paths get exactly the validation of user-opened paths; IPC can only open documents — never export, install, register, or change settings.
- S-IPC-04 MUST No named pipes, sockets, shared memory sections, COM servers, DDE, or listening endpoints of any kind.
- S-IPC-05 MUST Dialog-host results return through
WM_COPYDATAwith their own magic value, a versioned payload and the per-launch nonce. The main window accepts them only while it waits for a host it started, only from that host's process ID (checked withGetWindowThreadProcessIdon the sender window), and treats returned paths exactly like user-opened paths. The host refuses to run if the owner window does not belong to a process of the same user, and it never does anything other than show one dialog.
- S-REG-01 MUST Writes only to:
HKCU\Software\Classes\YAMDV.Markdown,HKCU\Software\Classes\<ext>\OpenWithProgids,HKCU\Software\Classes\Applications\yamdv.exe,HKCU\Software\Classes\SystemFileAssociations\<ext>\shell\YAMDV,HKCU\Software\YAMDV\Capabilities,HKCU\Software\RegisteredApplications(valueYAMDV),HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\YAMDV(install only). Never HKLM, neverUserChoice, neverExplorer\FileExts, never policy keys. - S-REG-02 MUST Every written key/value is listed in one place in code;
--unregister/--uninstallremove exactly those; registration is idempotent. - S-REG-03 MUST Registration happens only on explicit user action (Settings button, context-menu toggle,
--register,--install) — never on a normal launch. - S-REG-04 MUST Registry reads are limited to: theme/accessibility settings,
App Paths, editor install keys, association queries.
- S-PARSE-01 MUST No panic, hang, or unbounded allocation on any input; all recursion has explicit depth limits (visual nesting of quotes/lists capped at 64 levels — deeper content is laid out at level 64).
- S-PARSE-02 MUST Limits: file 256 MB hard / 20 MB soft prompt; a single paragraph > 1 MB uses a plain-text fast path; tables ≤ 1 000 columns and ≤ 100 000 cells (else shown as text); TOC ≤ 10 000 headings; ≤ 10 000 footnotes; ≤ 100 000 link reference definitions.
- S-PARSE-03 MUST Time budgets: any single block whose layout exceeds 200 ms is replaced by a "Content too complex" placeholder with [Render anyway]; the UI thread never blocks > 2 s.
- S-PARSE-04 MUST Only linear-time algorithms on user-controlled input; no backtracking regular expressions.
- S-PARSE-05 MUST Math: ≤ 10 000 chars per formula, depth ≤ 64, macro expansion ≤ 10 000 steps and ≤ 100 000 output tokens per formula, ≤ 5 000 rendered formulas per document (the rest shown as source).
- S-PARSE-06 MUST Mermaid: source ≤ 100 KB per diagram; soft limit 500 nodes / 1 500 edges (placeholder + [Render anyway]); hard limit 2 000 nodes / 6 000 edges; bounded layout iterations; ≤ 100 rendered diagrams per document.
- S-PARSE-07 MUST Checked or saturating arithmetic for sizes/offsets from input;
overflow-checksstay on in release. - S-PARSE-08 MUST Invalid encodings → U+FFFD for viewing; editing disabled when decoding was lossy (R-EDIT-12).
- S-PRIV-01 MUST No telemetry, analytics, usage counters, device IDs or crash upload.
- S-PRIV-02 MUST Logging off by default; when enabled: local only, rotated (≤ 1 MB × 3 files), never containing document text; file paths only when "diagnostic log" is enabled.
- S-PRIV-03 MUST Crash notes contain no document content.
- S-PRIV-04 MUST Settings offer "Clear history", "Clear favorites" and "Forget reading positions".
- S-PRIV-05 MUST The clipboard is read only on an explicit paste.
- S-PRIV-06 MUST Exports contain no personal metadata (PDF
Producer= "YAMDV ",Title= first H1 or file name; no author/user name).
- S-SUP-01 MUST
Cargo.lockcommitted;cargo deny check(advisories, bans, licenses, sources) in CI; builds use--locked. - S-SUP-02 MUST Each dependency has an ADR (H5); reports list dependency changes with
cargo tree -e normaldeltas. - S-SUP-03 MUST Banned crates (in
deny.toml):reqwest hyper hyper-util h2 h3 ureq isahc curl curl-sys surf attohttpc minreq tokio async-std smol mio socket2 native-tls openssl openssl-sys rustls webpki webpki-roots quinn tungstenite tokio-tungstenite websocket lettre trust-dns-resolver hickory-resolver wry tao tauri webview2 webview2-com winit egui eframe iced slint druid gtk glib fltk wgpu glutin sdl2 skia-safe rquickjs quick-js boa_engine v8 deno_core mlua rlua pyo3 libloading. - S-SUP-04 MUST License allowlist: MIT, Apache-2.0, Apache-2.0 WITH LLVM-exception, BSD-2-Clause, BSD-3-Clause, ISC, Zlib, Unicode-3.0, Unicode-DFS-2016, BSL-1.0, CC0-1.0. Everything else denied unless an ADR approves it.
- S-SUP-05 MUST No network access in build scripts; resource embedding (manifest, icons, version info) via a pure-Rust
.reswriter or a crate approved by ADR. - S-SUP-06 MUST GitHub Actions pinned by full commit SHA,
permissions: contents: read, no secrets, only well-known actions (actions/checkout,actions/cache,actions/upload-artifact,EmbarkStudios/cargo-deny-action, a toolchain installer).
- S-EXP-01 MUST Exports are written atomically, only to the user-chosen path.
- S-EXP-02 MUST HTML export:
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'sha256-<hash of our inline script>'; base-uri 'none'; form-action 'none'">; all text escaped; images only asdata:URIs of decoded images; external links getrel="noopener noreferrer"; no external resource of any kind. - S-EXP-03 MUST PDF: no JavaScript, launch actions, embedded files or forms; only URI annotations for
http/https/mailtoand internal GoTo links. - S-EXP-04 MUST CSV export guards against formula injection: cells starting with
= + - @or a tab/CR are prefixed with'(settingexport.csv_formula_guard, default on).
- S-UI-01 MUST The real destination of every link is visible before it is followed (status tooltip + Ask popover).
- S-UI-02 MUST Dangerous confirmations default to Cancel; nothing is auto-accepted.
- S-UI-03 MUST Banners for: Mark-of-the-Web documents, elevated process, decoding fallback.
- S-TEST-01 MUST Fuzz targets (
cargo-fuzz): Markdown → block tree → layout (mock shaper), inline extensions, HTML sanitizer, math parser + layout, each Mermaid parser + layout, INI parser, encoding detection, IPC payload decoder. Each target runs ≥ 10 minutes in the phase that introduces or changes it (locally or in a manual CI workflow); small seed corpora are committed. - S-TEST-02 MUST Security unit-test matrices: link policy (scheme × target type × MotW × setting), path validator (UNC variants, WebDAV forms, device names, ADS, traversal, reparse points), assets sandbox, HTML sanitizer (a list of ≥ 50 known XSS vectors must yield no executable output in exported HTML), CSV guard, argument quoting round-trip, IPC validation.
- S-TEST-03 MUST CI binary checks: forbidden imports (S-NET-03), PE
DllCharacteristicscontainDYNAMIC_BASE,HIGH_ENTROPY_VA,NX_COMPAT,GUARD_CF; CET compatibility flag present; no section is both writable and executable. - S-TEST-04 MUST
docs/THREAT_MODEL.md(STRIDE per entry point: document content, dropped files, clipboard, CLI, IPC, config files) is created as a skeleton in Phase 001 and completed in Phase 012.