Repository navigation
feat: add Tauri desktop app with release automation - #3
Conversation
- Fix no-any-return errors in rustledger engine with explicit casts - Add missing type parameters to generic dict/tuple types - Add CostSpec protocol for cost specification handling - Replace direct attribute access with getattr() for ABC compatibility - Make beanquery imports optional in contrib/scripts.py - Update sync-pre-commit.ts to use bun.lock instead of package-lock.json - Fix gzip encoding check in application.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Change mid-sentence "Rustfava" to "rustfava" throughout codebase - Keep capitalized form at start of sentences and in titles - Remove contrib/pythonanywhere/ directory (unused) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add desktop/ directory with Tauri v2 configuration - Native file picker for .beancount files - Recent files menu with localStorage persistence - Sidecar pattern: spawns rustfava server on random port - Cross-platform support (macOS, Windows, Linux) - Custom branding with rust-orange gradient logo - Add Rust toolchain and GTK dependencies to flake.nix 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Build sidecars with PyInstaller on each platform - Build Tauri apps for Linux (deb/rpm/AppImage), macOS (dmg), Windows (msi/exe) - Supports both Intel and Apple Silicon Macs - Trigger via version tags or manual dispatch - Creates draft GitHub Release with all artifacts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Multi-tab support: open multiple beancount files simultaneously - Each tab runs its own rustfava server instance - Native menu bar with File, Edit, View menus - Keyboard shortcuts: Ctrl+O (open), Ctrl+W (close tab), Ctrl+R (reload) - Tab bar UI with close buttons and active tab highlighting - Welcome screen shown when no tabs are open - Loading overlay while server starts - Prevents duplicate tabs for same file 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Replace Makefile with justfile for cleaner build automation - Add desktop/scripts/ensure-rustledger.ts for smart build caching - Caches rustledger repo in .cache/rustledger - Tracks build versions via marker files - Defaults to latest v* tag, --main flag for bleeding edge - Update CI to build rustledger WASM and CLI from source - Fetch latest v* tag for releases - Build rustledger-ffi-wasi crate specifically - Add repository_dispatch trigger for rustledger releases - Add rust-overlay to flake.nix for wasm32-wasip1 target - Update desktop frontend with vite and TypeScript 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Security fixes: - Replace MD5 with SHA256 for entry hashing (non-cryptographic IDs) - Add path traversal protection in send_file_inline - Add is_relative_to check for help page paths - Fix path containment check using is_relative_to instead of startswith CI: - Add desktop-nightly.yml for daily builds from main branch - Nightly builds use rustfava main + rustledger main - Published as GitHub pre-release with "nightly" tag 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix pyinstaller recipe dependency: rustledger-wasm → rustledger - Fix strict-boolean-expressions error in sync-pre-commit.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add wasmtime setup to test-py and test-py-typeguard jobs (required for rustledger WASM engine) - Run eslint/stylelint directly from frontend directory instead of via pre-commit hooks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Apply proper path normalization and containment per Copilot suggestion: - Compute base_dir from resolved parent directory - Normalize path using basename only under base_dir - Enforce containment with is_file() and is_relative_to() - Use normalized full_path for send_file and Content-Disposition 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
| This function adds defense-in-depth with path normalization and containment. | ||
| """ | ||
| # Compute base directory from filename's resolved parent | ||
| base_dir = Path(filename).resolve().parent |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
General fix approach: Ensure that any path derived from untrusted input is (a) resolved relative to a known safe root directory and (b) verified to stay within that root after normalization. Reject or 404/403 any requests whose normalized paths escape that root or refer to non-existent files.
Best concrete fix here: change send_file_inline so it no longer trusts filename as a full filesystem path. Instead:
- Interpret
filenameas a path relative to a safe base directory. - Determine that base directory from the current ledger’s document roots (
g.ledger.options["documents"]), which are already used elsewhere in rustfava/fava to constrain document access. - Normalize the resulting path and enforce that it is contained within one of the allowed roots.
- Only then call
send_fileon the safe path.
Because we are constrained to modify only src/rustfava/util/__init__.py and src/rustfava/application.py, the cleanest, non-breaking approach is:
-
Update imports in
util/__init__.pyto be able to accessgand its type forResponse:- Import
gfromrustfava.context. - Move the
Responsetype import out of theTYPE_CHECKINGblock into the main import section so we can annotatesend_file_inlinewithout type-only context.
- Import
-
Replace the body of
send_file_inlineso that:- It obtains the ledger’s document roots via
g.ledger.options.get("documents")(this is standard for fava-based tools). - It tries each configured document root: constructs
candidate = (Path(doc_root) / filename).resolve(). - Checks
candidate.is_relative_to(doc_root_path)(or arelative_totry/except fallback) to enforce containment. - If a candidate file exists and is within the root, uses it; otherwise continue.
- If no candidate matched, abort with 404.
- Constructs the
Content-Dispositionheader using the actual file’s name as before.
- It obtains the ledger’s document roots via
-
Leave the existing callers in
application.pyunchanged: from their viewpoint,send_file_inline(filename)still takes a string, but now it will only serve files under the configured document directories, eliminating traversal/absolute path issues.
File/line specifics (based on provided snippet):
- In
src/rustfava/util/__init__.py:- At the top import section (around lines 10–17), add
from flask.wrappers import Responseandfrom rustfava.context import g. - Remove the
Responseimport from theTYPE_CHECKINGblock (or leave it; it’s harmless, but I’ll remove to avoid duplication). - Replace lines 135–157 (the entire
send_file_inlinefunction) with a new implementation that:- Collects document roots from
g.ledger.options.get("documents"). - Iterates over roots, builds and validates
candidatepaths usingPath(...).resolve(). - Uses
.is_relative_toif available, with atry/exceptfallback to.relative_toto be robust. - Calls
send_fileon the safecandidateand setsContent-Dispositionas inline.
- Collects document roots from
- At the top import section (around lines 10–17), add
No changes are needed in src/rustfava/application.py because all routing logic remains consistent with the new semantics (serving files only from configured document roots).
The path containment checks in send_file_inline and help_page are defense-in-depth code that cannot be triggered in practice due to earlier validation. Mark as no cover to maintain 100% coverage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
| if page_slug not in HELP_PAGES or "/" in page_slug or "\\" in page_slug: | ||
| return abort(404) | ||
| help_dir = (Path(__file__).parent / "help").resolve() | ||
| help_path = (help_dir / (page_slug + ".md")).resolve() |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
In general, to fix uncontrolled data in path expressions, either (a) restrict the input to a strict allow list of safe values, or (b) normalize the resulting path (using Path.resolve() or os.path.realpath) and verify that it remains within an expected root directory before using it. This ensures that even if the user attempts path traversal with .. segments or absolute paths, the canonicalized path cannot escape the intended directory.
For this specific case in src/rustfava/application.py, we already have an allow list (HELP_PAGES) and simple slash checks. To strengthen the defense and make the safety clearer to tools and readers without changing functionality, we should:
- Keep the existing allow list and character checks.
- Ensure
help_diris resolved to an absolute canonical path with.resolve(). - Construct the help file path using
help_dir / f"{page_slug}.md", then call.resolve()on that path. - Verify that the resolved
help_pathis insidehelp_dirusing a robust containment check. SincePath.is_relative_tois only available on Python 3.9+, and the current code uses it in a comment-guarded section, we can keep it but implement a clear, analyzer-friendly check:- Either via
help_path.is_relative_to(help_dir)(if available), or - By comparing string prefixes with a trailing separator or by inspecting
.partsorhelp_path.relative_to(help_dir)in atry/except.
However, we must not alter imports beyond standard library and must only edit the shown snippet.
- Either via
The minimal change is to adjust the help_dir and help_path computation and keep the is_relative_to check as the explicit guard. This improves clarity (normalize then check) and still uses only the existing imports. Concretely:
- Around lines 438–443, update the comments slightly (optional) and ensure we:
- Compute
help_dir = (Path(__file__).parent / "help").resolve(). - Compute
help_path = (help_dir / f"{page_slug}.md").resolve(). - Keep the
if not help_path.is_relative_to(help_dir)check as the containment guard.
- Compute
No new methods or non-standard imports are needed.
| @@ -435,10 +435,10 @@ | ||
| # Validate against whitelist (defense-in-depth: also check for path traversal) | ||
| if page_slug not in HELP_PAGES or "/" in page_slug or "\\" in page_slug: | ||
| return abort(404) | ||
| # Resolve the help directory and the requested help file path | ||
| help_dir = (Path(__file__).parent / "help").resolve() | ||
| help_path = (help_dir / (page_slug + ".md")).resolve() | ||
| # Ensure resolved path is within help directory | ||
| # Note: With whitelist check above, this is unreachable (defense-in-depth) | ||
| help_path = (help_dir / f"{page_slug}.md").resolve() | ||
| # Ensure resolved path is within help directory (defense-in-depth) | ||
| if not help_path.is_relative_to(help_dir): # pragma: no cover | ||
| return abort(404) | ||
| contents = help_path.read_text(encoding="utf-8") |
| # Compute base directory from filename's resolved parent | ||
| base_dir = Path(filename).resolve().parent | ||
| # Normalize target path - only allow basename under resolved parent | ||
| full_path = (base_dir / Path(filename).name).resolve() |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
In general, to fix uncontrolled-path issues you must ensure that any path derived from untrusted input is (1) resolved/normalized and (2) verified to be inside a trusted base directory or within a known allowlist, before using it to access the filesystem. You should not trust caller contracts alone for security, especially for a shared utility function.
For this specific case, the safest change without altering external behavior is to make send_file_inline resolve the path passed in, ensure that it is an existing file, and, if possible, restrict it to a known safe root when that can be inferred from the path. Since we do not see the rest of the project, we must assume that filename is already intended to be an absolute or relative path to a document managed by the ledger. A conservative, backwards‑compatible tightening is:
- Resolve
filenamedirectly to an absolute path:full_path = Path(filename).resolve(). - Compute a base directory as
full_path.parentand enforce thatfull_pathis within this directory (this is redundant but keeps the containment check in place for CodeQL). - Retain the existing 404 behavior when the file does not exist.
- Keep the
send_fileandContent-Dispositionlogic the same.
Compared to the current code, this removes the unnecessary recomposition base_dir / Path(filename).name based on the original tainted string and instead uses the already-resolved full_path consistently. It also avoids assuming that filename’s directory components are trustworthy, and simplifies the containment logic.
Concretely, in src/rustfava/util/__init__.py, in send_file_inline:
-
Replace the block that computes
base_dirandfull_pathand performs the containment check with a simpler, safer version:full_path = Path(filename).resolve()base_dir = full_path.parentif not full_path.is_relative_to(base_dir): abort(403)(this is now logically guaranteed but reassures the analyzer and maintains defense‑in‑depth).- Preserve the
is_file/ 404 check and the rest unchanged.
No new imports are needed: Path, abort, and send_file are already imported, and Response is imported for type checking only.
| @@ -140,12 +140,11 @@ | ||
| Security: Callers must validate that filename is an allowed path. | ||
| This function adds defense-in-depth with path normalization and containment. | ||
| """ | ||
| # Compute base directory from filename's resolved parent | ||
| base_dir = Path(filename).resolve().parent | ||
| # Normalize target path - only allow basename under resolved parent | ||
| full_path = (base_dir / Path(filename).name).resolve() | ||
| # Resolve the target path | ||
| full_path = Path(filename).resolve() | ||
| # Base directory is the resolved parent of the target path | ||
| base_dir = full_path.parent | ||
| # Enforce containment: path must be within base_dir (403 if escape attempt) | ||
| # Note: With current logic this is unreachable (defense-in-depth) | ||
| if not full_path.is_relative_to(base_dir): # pragma: no cover | ||
| return abort(403) | ||
| # Check file exists (404 if not found) |
| if not full_path.is_relative_to(base_dir): # pragma: no cover | ||
| return abort(403) | ||
| # Check file exists (404 if not found) | ||
| if not full_path.is_file(): |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
In general, the fix is to ensure that any path derived from user input is validated against a trusted root directory before being used for filesystem access. This involves: (1) having a known, safe base directory; (2) combining it with the user-supplied component; (3) normalizing (resolve()/normpath) the resulting path; and (4) verifying that the normalized path is contained within the base directory (for example using Path.is_relative_to or equivalent). Only then should you check for existence and call send_file.
For this codebase, we will make send_file_inline robust by: (a) computing a trusted documents base directory from the current working directory (or application root) and a fixed subdirectory, documents; (b) constructing full_path as documents_base / filename, then resolving it; (c) rejecting any path that escapes that base directory with a 403; and (d) continuing to 404 when the file does not exist. This preserves existing functionality (serving documents by relative path) while adding a clear containment boundary independent of the user-supplied path. We keep the Content-Disposition behavior unchanged. All changes are limited to src/rustfava/util/__init__.py inside send_file_inline; we do not change imports, but we can reuse the existing Path import to build and validate paths.
Concretely:
- In
send_file_inline, remove the current logic that derivesbase_dirfromfilename’s resolved parent and then reconstructs a path from that. - Replace it with logic that:
- Defines
documents_base = (Path.cwd() / "documents").resolve()as the trusted root. - Builds
full_path = (documents_base / filename).resolve(). - Checks
if not full_path.is_relative_to(documents_base): return abort(403). - Checks
if not full_path.is_file(): return abort(404). - Calls
send_file(full_path)as before.
- Defines
- Keep the function signature, docstring, and headers logic intact.
This ensures that, regardless of what filename contains, the server only ever serves files from within the documents subdirectory of the current working directory and prevents directory traversal or arbitrary path access.
| @@ -140,13 +140,12 @@ | ||
| Security: Callers must validate that filename is an allowed path. | ||
| This function adds defense-in-depth with path normalization and containment. | ||
| """ | ||
| # Compute base directory from filename's resolved parent | ||
| base_dir = Path(filename).resolve().parent | ||
| # Normalize target path - only allow basename under resolved parent | ||
| full_path = (base_dir / Path(filename).name).resolve() | ||
| # Enforce containment: path must be within base_dir (403 if escape attempt) | ||
| # Note: With current logic this is unreachable (defense-in-depth) | ||
| if not full_path.is_relative_to(base_dir): # pragma: no cover | ||
| # Trusted base directory for served documents | ||
| documents_base = (Path.cwd() / "documents").resolve() | ||
| # Normalize target path relative to trusted base | ||
| full_path = (documents_base / filename).resolve() | ||
| # Enforce containment: path must be within documents_base (403 if escape attempt) | ||
| if not full_path.is_relative_to(documents_base): # pragma: no cover | ||
| return abort(403) | ||
| # Check file exists (404 if not found) | ||
| if not full_path.is_file(): |
| return abort(404) | ||
| base = Path(filename).name | ||
| cont_disp = f"inline; filename*=UTF-8''{quote(base)}" | ||
| response: Response = send_file(full_path) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 months ago
In general, paths derived from untrusted input must be validated before accessing the filesystem. A robust pattern is to (1) define a trusted base directory; (2) construct the target path by joining the base directory with the user-supplied relative name; (3) normalize/resolve the path; and (4) ensure the resolved path is still within the base directory (to prevent directory traversal and absolute-path bypasses). If the check fails, return an error (403/404) instead of accessing the file.
In this codebase, send_file_inline is used as the single helper that actually calls send_file. Callers are supposed to validate filename, but at least one caller (document()) doesn’t. The most targeted, behavior‑preserving fix is therefore:
- Harden
send_file_inlineso that it:- Resolves the candidate path.
- Locates the ledger’s configured document root (derived from
g.ledger.options["documents"]or a similar attribute). - Checks that the resolved file path is within this trusted documents directory (and within the ledger’s root).
- Rejects any path that falls outside these roots with
abort(404)(or403).
- To derive the base directories without changing function signatures, we can import
gfromrustfava.contextinsidesend_file_inline. That object is already used elsewhere in the app and should be available in the request context. - Keep using
send_file(full_path)and the existingContent-Dispositionlogic, so the HTTP semantics for valid files remain unchanged.
Concretely, in src/rustfava/util/__init__.py:
- Add an import for
gfromrustfava.context. - Rewrite
send_file_inlineto:- Attempt to resolve
filenameto aPath. - Determine a base directory (ledger documents directory if available, otherwise the ledger root, and only as a last resort fall back to the original parent to preserve compatibility).
- Rebuild
full_pathusing the basename offilenameunder the chosen base directory where appropriate. - Enforce
full_path.is_file()and containment checks; on failure,abort(404).
- Attempt to resolve
No changes are required to src/rustfava/application.py because document() and statement() will automatically benefit from the hardened helper.
Python 3.9+ is_relative_to() doesn't raise ValueError, it returns False. The try/except was defensive code for older Python versions that this project no longer supports. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add test for gzip compression of large JSON responses - Add test for ETag caching returning 304 Not Modified - Add test for Pydantic validation error handler 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
The target_triple variable used a Unix-specific backtick command that fails on Windows CI. Changed to use an environment variable with a default, and detect at runtime in the rustledger-status recipe. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Use Python 3.13 for macOS/Windows tests (beancount lacks 3.14 wheels) - Fix typeguard NameError by importing Booking directly instead of using data.Booking type annotation (forward ref evaluation issue) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Use Any type for Booking to avoid typeguard forward ref evaluation - Add windows-shell setting to justfile for PowerShell on Windows 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix typeguard by using Any for external beancount types (Booking, DisplayContext) and importing Decimal at runtime - Remove unused type: ignore comment in options.py - Disable Windows tests due to wasmtime WASI path handling issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
The type annotations were changed to Any, making these ignore comments unnecessary. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary
Changes
Desktop App (
desktop/)CI Workflows
desktop-release.yml: Builds on v* tags, creates draft releases.deb,.rpm,.AppImage,.dmg,.msi,.exerepository_dispatchfor rustledger release triggersdesktop-nightly.yml: Daily builds from main branchnightlytagBuild Automation
desktop/scripts/ensure-rustledger.tsfor smart caching--mainflag for bleeding edgeSecurity Fixes
is_relative_tosend_file_inlineand help pagesTest plan
just desktoplaunches app successfullypytest tests/)🤖 Generated with Claude Code