SPB Git

Repository Public

security.md 25.6 KB 345 lines markdown

1# Security23This document describes what ORIX Sheet does with untrusted input and what its components are4allowed to do, as implemented in the repository on 2026-11-21. Every statement names the source5file that implements it. Where a protection is absent or has not been verified by a test, the text6says so. Nothing here has been reviewed by an external auditor.78Related documents: [architecture/python-runtime.md](architecture/python-runtime.md),9[architecture/data-engine.md](architecture/data-engine.md),10[architecture/intelligence.md](architecture/intelligence.md),11[architecture/persistence.md](architecture/persistence.md),12[compatibility/formats.md](compatibility/formats.md),13[release/signing.md](release/signing.md).1415## 1. Process and platform posture1617| Property | Value | Source |18|---|---|---|19| App Sandbox | **Off** (`ENABLE_APP_SANDBOX: NO`). The app runs with the user's full file access. | `project.yml` |20| Hardened runtime | On (`ENABLE_HARDENED_RUNTIME: YES`) | `project.yml` |21| Entitlements | Empty dictionary: no hardened-runtime exception (no JIT, no unsigned executable memory, no disabled library validation, no Apple Events) | `App/Resources/ORIXSheet.entitlements` |22| Privacy usage strings (`NS…UsageDescription`), App Transport Security exceptions | None declared | `App/Resources/Info.plist` |23| Accounts, analytics, crash upload, update checker | No code for any of them (see section 2) | source search |24| Third-party code linked into the app | DuckDB C library only, downloaded at build time from the DuckDB GitHub release `v2.0.1` and checked against a pinned SHA-256 before use | `Scripts/fetch-duckdb.sh` |25| Preferences | `UserDefaults` only | `App/Sources/AppSettings.swift` |2627Source: the files in the last column.2829The app is not sandboxed because it must start a user-installed Python interpreter and read data30files chosen by scripts and workflows; the isolation that exists is applied per subsystem (Python31restricted mode, DuckDB external-access lock, workflow path authorization) and is described below.3233## 2. Network access3435**The application's own code opens no network connection** (no `URLSession`, no sockets), and one36user-confirmed action starts a program that does: installing a Python package with `pip` (listed37below). This was checked on 2026-11-21 by searching38`Packages/*/Sources`, `App/Sources` and `Scripts` (Swift, Python, shell, C, headers, plists) for39`URLSession`, `URLRequest`, `NWConnection`, `NWListener`, `import Network`, `CFSocket`, `CFStream`,40`socket(`, `getaddrinfo`, `NSURLConnection`, `WKWebView`, `WebKit`, `NSWorkspace.shared.open`,41`Process(`, `posix_spawn`, `launchctl`, `dlopen`, `NSAppleScript`, `httpfs`, DuckDB `INSTALL`/`LOAD`,42`enable_external_access`, `autoinstall`, `autoload` and literal `http://`/`https://` URLs (XML43namespace URIs excluded). Every hit is listed here.4445| Hit | Classification |46|---|---|47| `URLSession`, `URLRequest`, `Network` framework, `NWConnection`, sockets, `CFStream`, `WKWebView`/`WebKit` | **No occurrence** in any source file. |48| `Packages/SheetUI/Sources/SheetUI/Grid/GridView+Events.swift:149` — `NSWorkspace.shared.open(url)` | Opens a cell hyperlink in the user's default browser or mail client. Only on ⌘-click of a cell that has a hyperlink, only for the schemes `http`, `https` and `mailto`; a target starting with `#` is an in-workbook jump. The request is made by the other application, not by ORIX Sheet. |49| `…/GridView+Events.swift:373–375` — the literal `https://` | Placeholder text of the "Link" prompt. No request. |50| `Packages/SheetData/Sources/SheetData/Engine/DataEngine.swift:81–82, 113` — `autoinstall_known_extensions=false`, `autoload_known_extensions=false`, `SET enable_external_access = false` | Settings that **disable** DuckDB's ability to download extensions and to reach files or URLs outside the staging directory (section 5). |51| `Packages/SheetPython/Sources/SheetPython/Spawn.swift` — `posix_spawn` | Starts the Python interpreter (section 4). In restricted mode the child is denied all network access by the sandbox profile; in unrestricted mode a script has the user's network access. |52| `Packages/SheetPython/Sources/SheetPython/Environment.swift:95–110` — `PythonEnvironmentManager.install` | **Uses the network through a child process.** Runs `<managed venv>/bin/python3 -I -m pip install --disable-pip-version-check --no-input -- <requirement>`, which downloads from the package index and runs third-party installation code **outside any sandbox**, with a 900 s timeout. The requirement must match a strict pattern (project name, optional extras and version constraints; no options, URLs or paths). It is called only after the confirmation alert "Install … from the internet?" in Python Studio (`FeaturePython/Sources/FeaturePython/StudioSheets.swift`). |53| `SheetPython` — other `CapturedProcess.run` calls (`Environment.swift:43, 73`, `Sandbox.swift:27`, `Discovery.swift:56`) | Local child processes: creating the managed virtual environment, probing interpreters with the bundled probe script, checking once per launch that `sandbox-exec` can apply a profile. Whether creating the virtual environment contacts the network was not measured for this document; `SECURITY.md` names a test `managedVenvIsCreatedOffline`. |54| `Packages/SheetIntelligence/Sources/SheetIntelligence/PythonChecker.swift:23` — `Process()` | Runs `python3 -I -c <compile program>` to syntax-check suggested code passed on standard input. The code is compiled, not executed. No network. |55| `Packages/FeatureAutomation/Sources/FeatureAutomation/Schedule.swift:127` — `Process()` running `/bin/launchctl` | Loads or unloads a per-user LaunchAgent when the user installs or removes a schedule (section 7). Local only. |56| `Packages/FeatureAutomation/Sources/FeatureAutomation/Chrome.swift:235` — `NSWorkspace.shared.open(URL(fileURLWithPath:))` | Opens a local output file of a workflow run in its default application (line 234 reveals it in Finder). |57| `Scripts/fetch-duckdb.sh:9` — `curl … https://github.com/duckdb/duckdb/releases/download/v2.0.1/…` | **Build-time** download on the developer's machine, verified with `shasum -a 256 -c`. Not part of the app. |5859Source: `grep -rnE` over the directories named above, run on 2026-11-21; file and line numbers60are those of that day.6162Consequences and limits of this statement:6364- Network access can still originate from **programs the user starts through the app**: `pip`65  when installing a package (after confirmation), a Python script in unrestricted mode, and the66  browser or mail client opened by a hyperlink.67- The first search pattern list did not catch the `pip` path, because it goes through the68  package's own `CapturedProcess` wrapper around `posix_spawn`; it was found by reading the Python69  packages. The table is therefore complete for the patterns listed and for every call site of70  `posix_spawn`, `Process(` and `CapturedProcess.run`.71- The on-device language model is reached through Apple's Foundation Models framework72  (`SystemLanguageModel.default`); the request is served by the operating system. The source never73  references `PrivateCloudComputeLanguageModel` (checked with `grep`). What macOS itself does when74  it downloads or updates the system model is outside the app.75- macOS services used implicitly by AppKit (for example autosave to a folder that happens to be in76  iCloud Drive) are not controlled by the app.77- The Settings window (Privacy section, `App/Sources/AppSettings.swift`) states: "ORIX Sheet has no78  account and no analytics. Calculation, files, Python and AI assistance all run on this Mac. The79  only network use is installing a Python package, and only when you ask for it in Python Studio."80  That text agrees with the table above and with the Python Studio alert, which describes the81  `pip` installation as "the only part of Python Studio that uses the network". The search above82  is the evidence; there is no automated test that monitors the network during a session of the83  app. Only the Python sandbox has such a test (a local TCP listener counting connections, see84  section 4).8586## 3. Untrusted files8788Threat: a file received from someone else (XLSX/XLSM, ODS, CSV/TSV, JSON/JSONL, `.orixsheet`) that89tries to exhaust memory, write outside its container, execute code, contact a server, or mislead90the user.9192### 3.1 ZIP containers (XLSX, XLSM, ODS)9394`SheetIO` has its own read-only ZIP reader over an in-memory buffer; nothing is extracted to disk.9596| Check | Default limit or behaviour | Source |97|---|---|---|98| Number of entries | 100 000 | `ZipLimits.maxEntries`, `Zip/ZipArchive.swift` |99| Declared uncompressed size of one entry | 1 GiB (`1 << 30`) | `ZipLimits.maxEntrySize` |100| Sum of declared uncompressed sizes | 4 GiB (`4 << 30`) | `ZipLimits.maxTotalSize` |101| Compression ratio | 500:1, checked for entries larger than 32 MiB (`ratioFloor`) | `ZipLimits.maxCompressionRatio` |102| Inflation | The inflater stops and fails when the stream would produce more bytes than the limit it was given, instead of growing | `Zip/Deflate.swift` (`decompress(_:limit:…)`) |103| Overlapping entry data (non-recursive ZIP bombs) | Rejected: entry spans are sorted and compared | `ZipArchive.init` |104| Entry names | Must be non-empty, at most 1 024 UTF-8 bytes, relative (no leading `/`, no `X:` drive prefix), without backslash, NUL or control characters, without `..` or `.` components and without `//` | `ZipArchive.validate(name:)` |105| Encrypted entries | Rejected with "password-protected files cannot be opened" | `ZipArchive.init` |106| Truncated central directory, entry data beyond the end of the file, invalid ZIP64 fields | Rejected as corrupted | `ZipArchive.init` |107108Source: `Packages/SheetIO/Sources/SheetIO/Zip/ZipArchive.swift`, `Zip/Deflate.swift`.109110The format-detection path (`WorkbookIO.swift`) opens archives with the size limits lifted because111it only lists entry names and expands nothing.112113### 3.2 XML114115All XML is parsed with Foundation's `XMLParser` in streaming mode through `SheetIO/XML/SAX.swift`:116`shouldResolveExternalEntities = false`, and any internal entity, external entity, unparsed entity,117element or attribute **declaration** aborts parsing with "the XML contains a document type118definition, which is not allowed". No DOM is built.119120### 3.3 Macros121122VBA is never executed and there is no VBA interpreter in the code base. The XLSX reader detects a123`vbaProject` relationship or a part named `vbaProject.bin`, reports `hasMacros`, and keeps the part124as opaque bytes (`PreservedParts.vbaProject`) only so that an explicit export to `.xlsm` can write125it back; an export to `.xlsx` drops it (`XLSX/XLSXReader.swift`, `XLSX/XLSXWriter.swift`). The126import report tells the user: "ORIX Sheet never runs macros; they are kept only if you export as127.xlsm" (`App/Sources/WorkbookDocument.swift`).128129### 3.4 External links and remote content130131Relationships marked external are skipped when the reader resolves parts (`!$0.external` on every132relationship lookup in `XLSXReader.swift`). External-link parts are preserved as bytes and flagged133(`hasExternalLinks`); the import report says "ORIX Sheet does not fetch external data; cached134values are shown". There is no code that could fetch them (section 2). Formulas that reference135other workbooks are not evaluated against those workbooks; see136[compatibility/excel.md](compatibility/excel.md).137138### 3.5 Formula injection from CSV139140- **Reading.** `CSVReadOptions.parseFormulas` is `false` by default, and the application opens CSV141  and TSV files with default options (`WorkbookReader.load(url:format:)` in142  `WorkbookDocument.readOnMain`). A field beginning with `=` is therefore loaded as **text**, not143  as a formula (`CSV/CSVReader.swift`: the formula branch requires `options.parseFormulas`).144  Fields beginning with `+`, `-` or `@` are never treated as formulas by the CSV reader.145- **Writing.** The CSV writer exports the displayed text of each cell. It does **not** prefix or146  otherwise neutralize text that begins with `=`, `+`, `-` or `@`: a CSV exported from ORIX Sheet147  and opened in another spreadsheet program can be interpreted there as formulas. This protection148  is not implemented.149- **Typing.** Text typed or pasted into a cell follows the normal input rules (a leading `=`150  starts a formula); that is user input, not file import.151152### 3.6 Native `.orixsheet` packages153154The manifest records a SHA-256 and a size for every part, and the reader compares both when it155loads a part (`Native/NativeFormat.swift`). This detects corruption and accidental modification;156it is **not** a signature — someone who edits a part can also rewrite the manifest. Cell chunks157are inflated with a hard size limit (`Native/NativeCells.swift`). Feature payloads stored in a158workbook (Python scripts, workflows, chart specifications, transform pipelines) are data: opening159a file decodes them and runs none of them (sections 4 and 7).160161### 3.7 Size limits162163Rows and columns beyond the grid limits raise `SheetIOError.tooLarge` in the CSV and JSON readers164(`CSVReadOptions.maxRows/maxColumns`, `JSON/JSONIO.swift`). Files are read on the main actor165(`canConcurrentlyReadDocuments` is `false`), so a very large file blocks the interface while it166loads; there is no time limit on parsing.167168### 3.8 Hyperlinks169170A hyperlink is followed only on ⌘-click and only for `http`, `https` and `mailto` targets171(`GridView.openHyperlink`). Other schemes (`file:`, custom URL schemes) are ignored. The app does172not display a confirmation with the destination before handing the URL to the system.173174## 4. Python175176Full description and the test that backs each claim: `Packages/SheetPython/SECURITY.md`, summarized177in [architecture/python-runtime.md](architecture/python-runtime.md). The points that matter for178the application-wide threat model:179180- **No auto-execution.** Scripts are stored in the workbook as JSON attachments. Opening a181  workbook, showing Python Studio or selecting a script starts no interpreter on that script; the182  only path is the Run command, after consent.183- **Consent is bound to the exact text.** A script that arrived with a workbook shows the full184  code, interpreter, mode, time limit and SHA-256 before its first run. "Always trust" stores the185  hash of the text together with the workbook identifier and the mode in186  `~/Library/Application Support/ORIX Sheet/python-trust.json` (mode 0600); any change of text,187  workbook or mode asks again.188- **Restricted mode is the default at every launch.** The interpreter runs under189  `/usr/bin/sandbox-exec` with a profile that denies network, writes outside the run directory,190  reads of the home directory, execution of other programs and signals to other processes. If the191  sandbox cannot be applied, the run is refused; it never falls back to unrestricted.192- **Isolation of writes.** A script talks to the app over two pipes with newline-delimited JSON.193  Writes are buffered and applied as one undoable step only if the run succeeds.194- **Resource limits** in both modes: wall-clock timeout, CPU time, file size, open files, output195  size, a memory watchdog, and termination of the whole process tree.196197Stated non-guarantees (from the package document): the sandbox is Apple's deprecated Seatbelt198launcher, not a virtual machine; system directories remain readable; a restricted script can read199the whole open workbook (but cannot send it anywhere); memory is enforced by sampling, so a script200can overshoot between samples; **unrestricted mode has no sandbox** and gives the script the201user's file and network access; the trust store and audit log are ordinary user files that an202unrestricted script could edit.203204Interpreter discovery executes the Python interpreters found at standard locations with a bundled205probe script (not workbook content). An attacker able to place an executable named `python3` in206one of those locations already has the user's privileges.207208## 5. DuckDB data engine209210DuckDB runs in-process (`Packages/SheetData`). `DataEngine.init` configures every database before211any user SQL runs (`Engine/DataEngine.swift`):212213| Setting | Value | Effect |214|---|---|---|215| `autoinstall_known_extensions`, `autoload_known_extensions` | `false` | No extension is downloaded or loaded on demand |216| `allow_community_extensions`, `allow_unsigned_extensions` | `false` | — |217| `extension_directory` | A private, empty directory named `extensions-disabled` | Nothing to load from |218| `allow_persistent_secrets` | `false` | No credential storage |219| `allowed_directories` | Set to the engine's staging directory; DuckDB appends its `temp_directory` (the engine's private spill directory) itself, so the effective list is staging + spill | The only two file-system locations SQL may read or write. Both are private to the engine; the spill directory holds only DuckDB's temporary files. Asserted by `spillingWorksAndTheAllowListIsStagingPlusSpill` (`Packages/SheetData/Tests`) |220| `enable_external_access` | `false`, set after the allow-list | SQL cannot read or write other files, nor reach URLs |221| `lock_configuration` | `true`, set last | None of the above can be changed by a later statement |222| `memory_limit` | Half of physical memory unless overridden (minimum 64 MiB); spill to the private spill directory | Bounded memory |223224Source: `Packages/SheetData/Sources/SheetData/Engine/DataEngine.swift`, `Packages/SheetData/README.md`.225226SQL typed by the user in the data tools, SQL compiled from transform pipelines and SQL in a227workflow's "Run SQL" step all execute under this configuration. What the package tests assert228about it, and what they do not, is documented in229[architecture/data-engine.md](architecture/data-engine.md). DuckDB itself is a large C++ library230parsing untrusted files (CSV, Parquet, JSON); a memory-safety defect in it would run inside the231app process, which is not sandboxed.232233## 6. On-device assistance234235Source of truth: `Packages/SheetIntelligence/PRIVACY.md`; architecture in236[architecture/intelligence.md](architecture/intelligence.md).237238- Inference uses the system's on-device model only. There is no fallback to any other model or239  service; when the model is unavailable the controls are disabled and no request is made.240- The model never receives the workbook. A bounded context is built deterministically (6 000241  characters per request by default) and shown to the user before it is sent; sample cell values242  can be switched off.243- **Prompt injection.** Sheet content is presented to the model as data, with an instruction that244  text from the sheet is never an instruction. The defence that does not depend on the model is245  output validation: a suggested formula is parsed by the real parser, checked against the246  function registry and evaluated on a private clone of the workbook; it is inserted only when the247  user clicks Insert, as one undoable step. Review items must reference an existing auditor248  finding. Chart and transform suggestions are restricted to fixed vocabularies and existing249  columns. Suggested Python is text that is syntax-checked (compiled, never executed) and can only250  be run by the user in Python Studio, under the consent rules of section 4.251- The model's prose can still be wrong or misleading. Numbers in prose that match nothing computed252  by the engine are labelled unverified; the measured quality is reported in253  `Packages/SheetIntelligence/EVALUATION.md`.254255## 7. Automation workflows and schedules256257`SheetAutomation` (engine and the `orix-sheet` command-line tool) and `FeatureAutomation` (the258Automation studio, schedules and App Intents) are built into the application (`project.yml`,259`App/Sources/Features.swift`); the release build embeds the tool at `Contents/MacOS/orix-sheet`260(`Scripts/sign.sh`). Architecture: [architecture/automation.md](architecture/automation.md).261262- **Workflows are data.** A workflow is JSON (`.orixflow`), stored in the user's library or as a263  workbook attachment. `AutomationFeature.register()` only registers a pane and a command;264  workflows stored in a workbook are listed and never run when the workbook opens265  (`Store/Store.swift`, `AutomationFeature.swift`).266- **No step starts a program or uses the network** (`Engine/WorkflowEngine.swift`). The step267  vocabulary is closed (25 kinds). The Python step runs only a script stored in the workbook whose268  exact text the user already approved for restricted mode in Python Studio269  (`PythonTrust.isTrusted(…, restricted: true)`), and always in restricted mode; a workflow cannot270  approve a script (`Steps/PythonStep.swift`). SQL steps run under the DuckDB configuration of271  section 5.272- **Approval.** `WorkflowTrust` stores the SHA-256 of the workflow's JSON in273  `~/Library/Application Support/ORIX Sheet/workflow-trust.json` (mode 0600). In the studio, an274  unapproved workflow first shows every file and folder it reads and writes275  (`WorkflowValidator.fileAccesses`); the run host is then limited to those locations276  (`StandardWorkflowHost.isAuthorized`, paths standardized with symbolic links resolved). Any edit277  made outside the studio changes the hash and removes the approval.278- **Atomic outputs.** Outputs are written to a private staging folder and moved to their279  destinations only if the run ends without a stopping failure or cancellation280  (`Engine/Host.swift`, `OutputStage`). Static validation errors prevent the run.281- **Command line.** `orix-sheet run <workflow.orixflow>` builds282  `StandardWorkflowHost(baseDirectory:, unrestricted: true, …)`: `isAuthorized` returns true for283  every path, and the command never calls `WorkflowTrust` (`Sources/orix-sheet/RunCommand.swift`).284  This is the design stated in the source: "the user typed this command: every location they285  named, or that the workflow names, is theirs to use" — typing the command is the explicit act286  that the studio's confirmation sheet replaces. The consequence is not softened by anything else287  in the tool: a workflow file received from someone else and run from the command line can read288  and write any path it names with the user's privileges, within the closed step vocabulary (no289  program is started, no network; a Python step still requires a script already approved for290  restricted mode). `orix-sheet run --validate-only` checks a workflow without running it.291- **Schedules.** Nothing is scheduled implicitly. Only a workflow saved in the user's library can292  be scheduled (`AutomationModel.scheduleWorkflowFile`). When the user clicks Install schedule,293  `WorkflowSchedule` writes a LaunchAgent property list in `~/Library/LaunchAgents` (label prefix294  `ai.spboucher.orix.sheet.workflow.`), with `RunAtLoad` false and a calendar interval, and loads295  it with `/bin/launchctl bootstrap gui/<uid>`; removal uses `bootout` and deletes the file. The296  agent's program is the `orix-sheet run …` command line above, shown in full in the schedule297  panel before installation. A scheduled workflow therefore runs **with the unrestricted host and298  without any `WorkflowTrust` check**, neither when the schedule is installed299  (`AutomationModel.installSchedule` does not consult it) nor at run time. The explicit act is300  installing the schedule. Logs go to `~/Library/Logs/ORIX Sheet/`. The agent names the workflow301  file in the library (`~/Library/Application Support/ORIX Sheet/Workflows/<id>.orixflow`), an302  ordinary user file: anything able to modify it, including a later edit in the studio, changes303  what the schedule does.304- **App Intents** (Shortcuts): the Run ORIX Workflow intent builds a host that can read the given305  input file and write only into its output directory (`Intents.swift`).306307## 8. Other local surfaces308309- **Clipboard.** Copy and paste use the general pasteboard; pasted text follows the normal input310  rules.311- **Launch arguments.** The `-ORIX…` arguments (open a file, select a range, write a screenshot or312  a menu dump to a given path, then quit) exist for tests and screenshots313  (`App/Sources/AppDelegate.swift`, `LaunchArguments`). They are processed in all builds,314  including Release. They require the ability to start the app with chosen arguments, which315  already implies the user's privileges.316- **Temporary files.** DuckDB spill and staging directories, Python run directories (removed317  after each run; stale ones are removed at launch by `PythonRunner.removeStaleRunDirectories`)318  and workflow staging folders live under the user's temporary directory.319- **Secrets in the repository.** `Scripts/secret-scan.sh` scans tracked and untracked,320  non-ignored files for private keys, common token formats and credential-like assignments, and321  for key/certificate file extensions; `.gitignore` excludes `*.p8`, `*.p12`, `*.cer`,322  `*.mobileprovision`, `.env` files and `asc.env`. Notarization credentials are referenced by323  keychain profile, see [release/notarization.md](release/notarization.md).324325## 9. Known gaps326327Collected from the sections above so that they are not overlooked:3283291. The app is not sandboxed; a memory-safety defect in a parser or in DuckDB would have the330   user's privileges.3312. CSV export does not neutralize cells that begin with `=`, `+`, `-` or `@`.3323. Unrestricted Python mode has no isolation by design. Package installation (`pip`) uses the333   network and runs third-party installation code unsandboxed, after one confirmation.3344. `orix-sheet run` (and therefore scheduled workflows) does not check workflow approval and uses335   an unrestricted file host. This is by design (a command the user types or schedules336   explicitly), and it means the approval list protects runs started in the studio only.3375. The native format's hashes detect corruption, not tampering.3386. No automated test observes the network during a whole app session; the "no network request"339   statement rests on the absence of networking code.3407. Hyperlinks open without showing the destination first.3418. File loading has no time limit and runs on the main actor.3429. Sheet protection is not a security boundary: there is no password, and the only check found343   in the sources is in `WorkbookSession.beginEdit` (typing into a locked cell of a protected344   sheet). Other edit paths were not found to consult the flag.345
Files main
Menu

Theme