SPB Git

Repository Public

security.md 28.7 KB

# Security report

This report states the threat model of ORIX DJ, the mechanisms the code relies on, the tests that exercise them, and what has not been tested. It was written by reading the source and the test suites and by running Scripts/check.sh; nothing here comes from an external audit.

Related documents: automation, AI integration, persistence, audio engine, testing, signing, notarization, and the user-facing security chapter of the language.

# Summary

Area Status
Script sandbox The language has no construct for file, network, process or system access; every name is resolved at compile time against one fixed schema. Covered by unit tests and a randomised no-crash test.
Runtime budgets Fixed limits on operations, commands per beat, tasks, ramps, handlers, loop turns and call depth; exceeding one cancels the automation. Covered by tests.
Malformed input Scripts, audio files, library databases, projects, MIDI bytes and mapping files have explicit failure paths with tests. Audio decoding itself is delegated to Apple frameworks and was not fuzzed.
API key Stored in the Keychain only; shown masked; sent only in the x-api-key header to the Anthropic client's endpoint. Static check in Scripts/check.sh.
Network surface One client, AnthropicClient. No listener, no telemetry, no update check.
Model output Compiled and simulated locally; never run without two user actions.
App Sandbox Not enabled. Hardened Runtime is enabled in the build settings. No entitlements file exists.
Release signing Not done yet; the signing and notarization run has not happened.
External review None. No penetration test, no third-party code review.

# Trust boundaries

flowchart LR
    subgraph U["Untrusted input"]
        S1["Script text: typed, imported, preset, Auto DJ, model output"]
        A1["Audio files"]
        P1["Project packages and library database"]
        M1["MIDI bytes and mapping files"]
        N1["Anthropic API responses"]
    end
    subgraph V["Validation in ORIXDJCore"]
        C["ScriptCompiler with schema, limits, capabilities"]
        SIM["Simulator with RuntimeLimits"]
        IMP["MediaImporter validation, AVFoundation decoding"]
        PS["ProjectStore and LibraryStore: version checks, corruption recovery"]
        MP["MIDIParser and MIDIMappingProfile.validate"]
        AC["AnthropicClient: status mapping, stop reason check"]
    end
    subgraph T["Trusted core"]
        RT["AutomationInstance on the scheduler thread"]
        Q["Control event queue"]
        RC["RenderCore on the audio thread"]
        KC["Keychain item with the API key"]
    end
    S1 --> C
    C --> SIM
    C -->|"user starts it"| RT
    RT --> Q
    Q --> RC
    A1 --> IMP
    P1 --> PS
    M1 --> MP
    MP -->|"control targets only"| Q
    N1 --> AC
    AC -->|"answer text"| C
    KC -->|"x-api-key header only"| AC

# Threat model

Assets: the audio output during a performance; the user's files and system; the user's Anthropic API key and account spend; the content of the user's library (track titles are treated as private).

Adversaries and sources of hostile input considered:

  1. A script the user did not write: downloaded, shared by someone else, or produced by a model.
  2. Media, project, mapping and database files that are malformed, by accident or on purpose.
  3. A MIDI device or virtual source sending arbitrary bytes.
  4. The network peer of the one outbound connection, and anything able to influence a model's answer (prompt injection through shared context, for example a track title or a comment in the shared script).

Out of scope: an attacker who already runs code as the user (such a process can read the user's files and, depending on Keychain access control, may be able to request the key); physical access; the security of Apple's frameworks; the Anthropic service itself.

# Script sandbox

# What the language cannot do, and why

Each line was verified in the compiler and the runtime.

Capability Verified in the code
File access The ORIXScript module imports only Foundation and ORIXDSP; neither Compiler.swift nor Runtime.swift opens a file or calls FileManager. A script cannot name a path: every dotted path is resolved by resolveParam against ScriptSchema tables, and an unknown one is a compile error (E-PATH, E-UNDECLARED).
Network access No networking symbol appears in the module (see the repository-wide search below).
Process or shell execution None in the module; Scripts/check.sh fails on Process(), NSTask, posix_spawn, NSAppleScript, dlopen( anywhere in the application or the package sources.
Host calls beyond the capability set The runtime reaches the outside world only through the four members of AutomationTarget: read, write, perform, clockBPM. Addresses are ParamAddress and ActionAddress values built by the compiler from schema entries. AutomationHost.perform is a closed switch over action names and returns "Unknown deck action" for anything else.
Calling arbitrary functions A call with one segment must be a user function, a schema builtin or print; otherwise E-UNDECLARED. The builtins are pure arithmetic and conversions (Evaluator.builtin). There is no eval, no import, no reflection, and no way to build a path from a string at run time.
Unbounded loops repeat, for and every counts are checked against 10000 at compile time when constant and again at run time; while requires limit N with a constant N from 1 to 10000 (E-UNBOUNDED at compile time without it, and at run time when the limit is reached with the condition still true).
Recursion Rejected at compile time by a depth-first search of the call graph (E-RECURSION), direct or indirect. Call depth is additionally bounded at run time.
Unbounded memory Arrays are limited to 256 elements and cannot grow; strings to 512 characters as literals and 2048 when concatenated; variables to 512 per body; tasks to 256; ramps to 128; handlers to 32; pending handler runs to 64. Parser nesting is limited to 20 levels for blocks and expressions, which bounds recursion in the parser and the evaluator.
Running forever An automation without event handlers terminates because every loop and wait is bounded (a wait or ramp is at most 100000 beats). An automation with handlers can stay alive by design; it remains subject to every budget and is visible in the run list.
Out-of-range control values Constants are range-checked at compile time (E-RANGE); computed values are clamped to the parameter's range by conform before every write, and non-finite numbers become the range minimum.
Running on the audio thread The runtime runs on the scheduler thread (or, in the simulator, on a background queue) and only enqueues control events.

The one place where a script touches data outside the mixer is deck.X.load("title") and deck.X.loadNext(). load passes the string to DJSession.scriptedLoad, which runs it as a search of the library database with a limit of one result and loads that track; it cannot name a file path, and loading is refused on a playing deck. A script can read deck.X.title and deck.X.key and print them to the automation log, which stays on the machine.

What a script can do is everything a hand on the mixer can do within the documented ranges: pause the playing deck, pull the master volume down, raise gains to their maximum, switch on effects, seek, loop, load another track on a paused deck. The sandbox protects the computer, not the mix. The mitigations for the mix are the simulator, the list of risks shown for model proposals, the run confirmation, and the emergency stop (see automation).

# Tests

Property Test (suite)
Unbounded while and empty script rejected emptyAndUnboundedRejected (ParserTests)
Nesting bounded: 80 nested if blocks and 500 nested parentheses give E-LIMIT instead of a stack overflow deepNestingIsBounded (ParserTests)
A table of invalid scripts, each with its expected error code parameterised test in CheckerTests
Capabilities: deck C and reverb rejected for a two-deck, delay-only host capabilityValidation (CheckerTests)
Recursion, purity of value-returning functions, return on every path functionsAndRecursion (CheckerTests)
Budgets: E-BUDGET, E-RATE, run-time E-UNBOUNDED, task E-LIMIT budgetsStopRunawayScripts (RuntimeTests)
Computed values clamped and counted dynamicValuesAreClampedAndCounted (RuntimeTests)
A run-time error cancels the automation and bypasses its effects runtimeErrorsCancelAndBypassEffects (RuntimeTests), failingScriptLeavesAudioRunningAndBypassesItsEffects (AutomationLiveTests)
Every path in the generated reference compiles, so the schema and the compiler agree referenceOnlyDocumentsWhatCompiles (PresetTests), everySchemaEntryIsReachableFromSource (ToolTests)
Invented calls in model output (system("rm -rf"), deck.A.scratch(4beats)) are compile errors and are not simulated proposalsAreValidatedLocally (AnthropicTests)
Randomised input never crashes malformedInputNeverCrashes (RuntimeTests), described below

The randomised test, RuntimeTests.malformedInputNeverCrashes in Tests/ORIXScriptTests/LanguageTests.swift, has two parts. First, 3000 inputs of 1 to 40 tokens drawn from 40 language fragments (keywords, braces, paths, unit literals, an oversized number, comment openers, an unterminated quote) are compiled; any that compile are also executed in a DebugSession for up to 32 beats. Second, 500 inputs of 0 to 200 random bytes decoded as UTF-8 are compiled. The test passes when nothing traps. It uses the system random number generator without a recorded seed, so a failure would not be reproducible from the log alone; it is a smoke test, not coverage-guided fuzzing, and no sanitizer build was run.

# Runtime budgets

The values are those of RuntimeLimits() in Runtime.swift, used unchanged by the live host and the simulator. The full tables, including compile-time limits, are in automation.

Budget Value Error
Operations in one scheduler step 20000 E-BUDGET
Operations over the life of an automation 5000000 E-BUDGET
Statement-issued writes and actions per beat 512 E-RATE
Tasks 256 E-LIMIT
Ramps 128 E-LIMIT
Handlers 32 E-LIMIT
Pending handler runs 64 events dropped and counted
Loop turns 10000 E-LIMIT
Depth of value-returning calls 16 E-LIMIT
Wait, ramp or position 100000 beats E-LIMIT

Exceeding a budget is handled as a run-time error: the automation's tasks, ramps and handlers are removed and the effects it switched on are switched off. The budgets bound the work of one automation per scheduler step; they do not bound the number of automations a user starts. The worst case for the scheduler thread is therefore the per-step budget multiplied by the number of running automations, and the audio thread is unaffected in either case because it never waits for the scheduler. Between the scheduler and the audio thread sits a bounded queue (4096 events) and a bounded pending list (512 events); when the queue is full a command is dropped and counted (droppedControlEvents) rather than blocking. Flooding that queue from scripts has not been tested beyond the benchmark, which reports zero drops for sixteen commands per beat plus three continuous ramps.

# Malformed input

Input Handling Tests
Script text Lexer and parser recover and report diagnostics (E-LEX, E-UNIT, E-SYNTAX); source over 256 KB is refused before parsing LexerTests.errors, highlightCoversInvalidSource, ParserTests.recoversAndReportsSeveralErrors, syntaxErrorsCarryLineAndColumn, malformedInputNeverCrashes
Audio files MediaImporter validates before import: empty file, unsupported extension, missing file, a directory with an audio extension, 4096 bytes of noise named .wav, .mp3, .m4a and .flac, a WAV header with no samples, and a file without read permission each give a typed error (emptyFile, unsupportedFormat, unreadableFile with a reason). A folder import with mixed good and bad files reports the failures and imports the rest MediaImporterTests.validationRejectsUnusableFilesWithClearErrors, importFolderTreeWithMixedFiles, scanSkipsHiddenInvalidAndPackageContent
Audio analysis Silence, very short inputs, steady tones and noise do not crash the analyser and do not produce a confident tempo RobustnessTests in ORIXAnalysisTests
Library database A file of garbage is moved aside as library.sqlite.corrupt-… and a fresh library starts; a database with a valid header and overwritten pages is recovered the same way; a database with a newer schema version is refused without being treated as corruption CorruptionTests.garbageFileIsMovedAsideAndAFreshLibraryStarts, databaseDamagedInTheMiddleIsRecovered, MigrationTests.newerSchemaIsRefusedAndNotTreatedAsCorruption
Search strings and smart-crate rules Values are bound as SQL parameters; the generated SQL text is built from fixed fragments. Injection strings are tried for every field and comparison SmartCrateTests.injectionStringsAreBoundNotInterpolated, invalidRulesAreRejected, SearchAndSortTests.searchTreatsLikeWildcardsAndQuotesLiterally
Project packages The format version is read first; invalid JSON, a newer format (ProjectError.newerFormat) and a missing package throw and change nothing; media missing at restore time is reported per file SessionTests.projectsRoundTripAndReportMissingMedia
MIDI bytes MIDIParser handles running status, real-time bytes, SysEx (skipped) and truncated messages; out-of-range fields are masked. 4000 random byte buffers (0 to 96 bytes, two distributions) must not crash, must yield only in-range messages, and must parse identically when fed in random chunks; 200000 random UMP words must not crash MIDIParserTests.fuzzRandomBytesNeverCrashAndStayInRange, fuzzRandomUMPWordsNeverCrash, outOfRangeFieldsAreMasked, tableOfSingleMessages
MIDI mapping files Newer format versions, non-JSON and unknown modes throw; validate() reports duplicate controls, empty targets, invalid controls, ranges and sensitivities MIDIMappingProfileTests.rejectsNewerFormatAndGarbage, validationReportsDuplicateControls, validationReportsEverythingElse
MIDI mapping targets A mapped control can only drive an entry of ControlTargets.all; ControlSurface scales values into the parameter's range SessionTests.controlSurfaceAndScaling, MIDIMappingEngineTests
Anthropic responses Non-200 statuses are mapped to typed errors; stream lines that are not valid JSON are skipped; the stop reason is checked before the text is used AnthropicTests.errorsAreTypedAndRetriesAreBounded

MIDI was tested with CoreMIDI virtual endpoints only; no hardware controller was attached during development.

Decoding of compressed audio (MP3, AAC, ALAC, FLAC) is performed by AVFoundation and Core Audio inside the application's process. The tests show that the application handles the errors those frameworks return for obviously invalid files. They do not exercise the decoders with crafted files, and because the App Sandbox is not enabled, a memory-safety defect in a system decoder would run with the user's full file access.

# API key handling

Implementation (APIKeyStore in AnthropicClient.swift, ClaudeAccess.swift, AISettingsTab.swift):

  • Stored as a generic password in the macOS Keychain: service ai.spboucher.orix.dj.anthropic, account api-key, accessibility kSecAttrAccessibleWhenUnlockedThisDeviceOnly. Isolated test and screenshot instances use the service name with the suffix .test.
  • The query does not set kSecUseDataProtectionKeychain or an access group, so the item is created in the user's default keychain with the default access control for the creating application.
  • Entered through a SecureField that is cleared when Save is pressed. Views only receive APIKeyStore.masked (first 7 characters, ellipsis, last 4).
  • Read at the moment of a request by ClaudeAccess.keyForRequest(), passed to AnthropicClient as an argument and set as the x-api-key header. It is not stored in AnthropicSettings (the value written to preferences), in projects, or in the request body.
  • The client uses an ephemeral URLSession: no cookie, cache or credential storage on disk.
  • Not logged: the client and Claude Studio contain no logging call. The only NSLog in the application reports a Metal shader compilation failure, and the only print calls outside the benchmark tool report visual-builder self-check results; neither has access to the key.

Checks:

  • AnthropicTests.keychainStoresAndMasksTheKey exercises save, replace, load, delete and masking against the real Keychain under a unique service name.
  • AnthropicTests.streamsTextAndSendsTheDocumentedRequest asserts that the key is in the header and that the body does not contain sk-ant.
  • Scripts/check.sh (below) greps for logging calls that mention the key and for key-shaped strings in the repository.

Limits of these checks: the logging check is a single-line regular expression and would not catch a key logged through an intermediate variable; it is a guard against an obvious mistake, not a proof. The key necessarily exists in process memory while a request is being built, and it is not zeroed afterwards. Spend is limited by the hourly request budget (default 60) and by max_tokens, both of which are client-side settings the user can raise.

# What Scripts/check.sh checks

The script is a set of grep passes over the files tracked or untracked-but-not-ignored in git. It exits non-zero when any pass finds something.

Pass Exactly what it does
headers Every *.swift, *.sh, *.py and project.yml must contain Author: Simon-Pierre Boucher in its first 16 lines.
signing material and audio No file whose name ends in .p8, .p12, .cer, .mobileprovision, .provisionprofile, .keychain, .pem, .wav, .aiff, .mp3, .flac, .m4a, .caf, starts with .env, or contains AuthKey_.
secrets In all text files except images, PDFs, icons and the script itself: no PEM private key header, no AuthKey_ followed by 10 characters, no sk-ant- followed by 24 or more key characters (lines containing the test placeholder sk-ant-test-0000 are excepted), no ghp_ token, and no private network address in the ranges 192.168.x.x, 100.x.x.x (two- or three-digit second octet) or 10.67.x.x.
network code only in the Anthropic client URLSession, NWConnection, CFSocket, import Network and WKWebView may appear under App/Sources and Packages/ORIXDJCore/Sources only in paths containing Sources/ORIXDJEngine/Anthropic/, Features/ClaudeStudio/ or Features/Settings/.
the API key is never logged or written No line under those two source trees matches `(print
no private API, privilege escalation or shell No occurrence of AuthorizationExecuteWithPrivileges, SMJobBless, NSAppleScript, /usr/bin/sudo, dlopen(, Process(), NSTask, posix_spawn under those two source trees.

Result when run for this report (2026-11-21, final state of the working tree): all six passes found nothing; the script printed clean and exited 0. An earlier run the same day reported one header finding (Scripts/shot.sh), unrelated to security, before the header pass was widened from 9 to 16 lines.

Observations on the script itself: the network pass excludes the whole Features/Settings/ directory, not only the AI settings tab, although no file there uses a networking API today; it does not look for URLRequest, BSD socket( or NSURLConnection; and the title of the last pass mentions private API, which the pattern does not actually detect.

# Network surface

A search of every Swift, plist, YAML, shell and Python file in the repository for URLSession, URLRequest, NWConnection, NWListener, import Network, CFSocket, socket(, CFStream, WKWebView, NSURLConnection, MIDINetworkSession, NSNetService, NSXPCConnection and MCSession gives:

Location Use
Packages/ORIXDJCore/Sources/ORIXDJEngine/Anthropic/AnthropicClient.swift The client: https://api.anthropic.com, endpoints /v1/models and /v1/messages
App/Sources/Features/ClaudeStudio/ClaudeStub.swift Debug-only URLProtocol that answers inside the process; not compiled in Release
Tests/ORIXDJEngineTests/SessionTests.swift Test URLProtocol stub

There is no other match. The application opens no listening socket, has no telemetry, analytics, crash reporting or update check, embeds no web view, and does not enable network MIDI. App/Info.plist contains no App Transport Security exception, so the system default (HTTPS required) applies. No certificate pinning is implemented; the connection relies on the system trust store.

Outbound activity that is not a connection made by the application: two links in the About settings (https://orix.spboucher.ai, https://git.spboucher.ai) and external links in the built-in documentation viewer are handed to the system and open in the default browser; the recordings folder is opened in Finder with NSWorkspace.

A connection to Anthropic is made only when the user validates a key in Settings or sends a request from Claude Studio. With the default setting, each request is preceded by a sheet that shows the exact text. What a request contains is listed in AI integration.

# Untrusted model output

A model's answer is handled as untrusted text from the network (see AI integration):

  • The script is extracted, compiled by the same ScriptCompiler with the same limits, and executed in the simulator. It has exactly the capabilities of a typed script and no others.
  • The "points to check" are computed locally from the compiled program and the simulated trace, not taken from the model's explanation.
  • Nothing runs on the live engine as a result of receiving an answer. Running requires pressing Run… on a proposal that compiled and simulated without error, then confirming an alert that names the decks affected. ClaudeStudioModel holds no reference to the automation host.
  • A proposed MIDI mapping is decoded, entries with targets outside ControlTargets are removed and reported, the profile is validated, and saving requires a confirmation.
  • The explanation text is rendered as text in the conversation; it is not interpreted as commands.

Prompt injection: text the user chooses to share (the current script, and track titles if switched on) reaches the model and could influence its answer. The consequence is bounded by the above: the worst outcome is a proposal for a script that does something unwanted to the mix, which is subject to the same validation, risk list and confirmation as any proposal. The model has no tools, and the application takes no action based on the content of an answer other than displaying and validating it.

Residual risk: a valid script that the user confirms can still damage a performance (silence, sudden level changes). Compile and simulation success say that a script is well formed and runs, not that it is musically appropriate.

# App Sandbox, entitlements, Hardened Runtime

Read from project.yml, App/Info.plist and Scripts/sign.sh:

  • App Sandbox: not enabled. There is no .entitlements file in the repository and no CODE_SIGN_ENTITLEMENTS setting. The application runs with the user's normal file and network access. The setting ENABLE_USER_SCRIPT_SANDBOXING: YES in project.yml concerns Xcode build-phase scripts, not the application.
  • Hardened Runtime: enabled in the build settings (ENABLE_HARDENED_RUNTIME: YES). With no entitlements file, none of the Hardened Runtime exceptions (JIT, unsigned executable memory, disabled library validation, DYLD environment variables) is requested.
  • Release configuration: manual signing with Developer ID Application, --timestamp, CODE_SIGN_INJECT_BASE_ENTITLEMENTS: NO (so that get-task-allow is not added), arm64 only.
  • Scripts/sign.sh verifies after building that the signature is valid (codesign --verify --deep --strict), that the runtime flag is present, and that get-task-allow is absent, and prints the entitlements of the built application.
  • Info.plist declares two document types and no usage-description keys: the application does not request the microphone, camera, contacts or location. It plays audio; it does not capture it.

None of the signing checks has been run on a release build yet: a Developer ID identity and a notarytool profile exist on the build machine, but the signing and notarization run has not happened. Until it has, "Hardened Runtime enabled" is a statement about the project settings, not about a shipped binary. See signing and notarization.

Consequence of running unsandboxed: the script sandbox, not the operating system, is what confines scripts; and a defect in native code that parses untrusted files (the application's own parsers, SQLite, AVFoundation) would not be contained by the system.

# Security-scoped bookmarks

Not used. The library and project code store bookmarks created with url.bookmarkData() with empty options (MediaImporter.makeBookmark is documented in the code as "A plain (not security-scoped) bookmark"), and resolve them to find files that were moved or renamed. There is no call to startAccessingSecurityScopedResource anywhere. This is consistent with the App Sandbox being off; enabling the sandbox later would require security-scoped bookmarks and user-selected file entitlements, which is work that has not been done.

# Other observations

  • Launch options. Claude Studio reads the defaults ORIXClaudeTask and ORIXClaudePrompt at first appearance (in all build configurations) and, when a key is stored, calls send with that prompt. With the default "Ask before every request" setting this stops at the confirmation sheet; with that setting switched off, launching the application with these arguments sends one request without further interaction. Automatic confirmation (ORIXClaudeAutoConfirm) is honoured only with the debug stub transport, which does not exist in Release builds. Passing launch arguments already requires the ability to start programs as the user.
  • Automation log. print in a script writes to the in-memory automation log (last 2000 lines), each line cut at 2048 characters. Track titles a script prints stay there.
  • Preferences. AnthropicSettings and the verified model list are stored in user defaults (ai.anthropic, ai.models); they contain no secret.
  • Effect tracking after failure. The runtime switches off the effects an automation enabled when it fails. Its record of a toggle() assumes the effect was off beforehand, so toggling an effect that was already on can leave the record and the real state out of step. The consequence is limited to which effects are bypassed after a failure.

# What was not tested

  • No external penetration test and no independent code review.
  • No coverage-guided fuzzing (libFuzzer or similar) of the lexer, parser, compiler, runtime, MIDI parser or project loader; only the randomised smoke tests described above, without recorded seeds.
  • No fuzzing of AVFoundation or Core Audio decoders with crafted media, and no test with deliberately malicious tag or artwork data.
  • No build with Address Sanitizer, Thread Sanitizer or Undefined Behavior Sanitizer was run for this report.
  • No test against the real Anthropic API: TLS behaviour, real error bodies and real streams are unverified, and no request has ever carried a real key.
  • No inspection of a release binary: entitlements, Hardened Runtime flag and notarization are unverified until the release run.
  • No test of Keychain access control from another process, and no review of what remains in memory or in a crash report after a request.
  • No resource-exhaustion test with many concurrent automations, a flooded control queue, a very large library database crafted to be slow, or a MIDI source sending at the maximum rate for a long time (a 1000-message latency test exists; a sustained flood test does not).
  • No test with hardware MIDI controllers or a multi-channel audio interface.
  • No review of the localisation, build and packaging scripts as an attack surface (they run only on the developer's machine).
Files main
Menu

Theme