ztk is experimental, and this version is a beta. Do not use it to run scripts from a source that you do not trust. To report a vulnerability, see Report a vulnerability.
In short:
- A script in the
ztkprogram has the files of the user, the file channels, and the clock by default, as a script ofwishhas them. It has no socket, no process, and no environment. - The
ztkprogram sets no compute limit and no memory limit. - An app in WebAssembly from an https URL runs in a sandbox with no capability, its own clipboard, and a memory limit of 1 GiB.
- A program that embeds the ztk library gives a script only the capabilities that the program turns on.
- ztk runs on the ztcl interpreter. The security model of ztcl applies to each script.
The program that runs ztk is the embedder, and it is trusted: the ztk program, a bundled app, a Zig program with the ztk library, or a web page. These are trusted as much as the user:
- A Tcl script that you give to the
ztkprogram. - A
.wasmfile that you give to theztkprogram as a file. It gets the same capabilities as a script. - A bundled app.
An app from an https URL is not trusted. It runs in the sandbox of Apps from a URL.
The ztk program turns on three capabilities of ztcl with no flag. src/main.zig sets them, and the docs build checks that the "On" rows of this table agree with it.
| Capability | What it adds | Default in ztk |
|---|---|---|
file |
file, glob, cd, pwd, the file dialogs, and the paths of ztk::recent and ztk::taskbar. |
On |
channels |
open, source, read, gets, puts to a channel, and the other channel commands. image create photo -file reads its file through open. |
On |
clock |
clock, time, and timerate. |
On |
hotkey |
ztk::hotkey: global shortcuts of the desktop. This grant is of ztk, and ztcl has no such capability. |
Off |
| The other capabilities of ztcl | socket, exec, env, thread, event, package, and the others of the table of ztcl. |
Off |
--allow a,b turns on more capabilities, with the names of the ztcl runner and hotkey. These commands work with no capability:
after,update, and the event loop of the window.interp create. At its first call, the ztk library turns on the capabilityinterpof ztcl. A child interpreter never has more capabilities than its parent, so a child gets no host access from it.package requireof the modules built into ztcl.clipboardandselection.
With no --root, the file commands use the real paths of the host, with symlinks followed. A script reads and writes each file that the user can read and write.
--root DIR keeps the file commands and the file channels in DIR, which a script sees as /. .. and symlinks cannot leave DIR. ztk::taskbar add needs a real path of the host, so it gives an error with --root.
ztk::style load reads style sheets from the folder of the script, also with --root. It reads only files below that folder, with each symlink resolved.
The ztk program has no --compute flag and no --mem flag, so a script has no compute limit and no memory limit. ztk::limit -compute UNITS -memory BYTES script runs one script with lower limits, for example a script of a user in a child interpreter. See ztk::limit.
The JIT of ztcl is on. A macOS app of ztk bundle has the entitlement com.apple.security.cs.allow-jit for it.
ztk bundle --allow CAPS sets the capabilities of the app. The default is file,channels,clock. A bundled app reads no flag of the command line, so a user cannot add a capability at the start. An app in one program file also reads its own files from its zip mount (embedded).
ztk https://HOST/app.wasm downloads a WebAssembly module and runs it as an app. src/wasmapp.zig sets these rules:
- The URL on the command line must start with
https://. The file has at most 64 MB and must start with the magic number of WebAssembly. A Tcl script from a URL does not run. - The interpreter has no capability of ztcl.
--allowand--rootwith a URL are an error. - Before the module starts, the sandbox removes each command that reaches outside the window of the app:
send,interp,package,source,open,file,exec,socket,load, the file dialogs,ztk::hotkey,ztk::tray,ztk::recent,ztk::taskbar,ztk::dnd,ztk::toast,ztk::terminal,ztk::inject,ztk::snapshot,ztk::debug, the commands ofztk::macandztk::win, and eachztcl::command exceptztcl::wasm. - The app has its own clipboard. It does not read and does not write the clipboard of the system.
- The memory limit is 1 GiB for the interpreter and the module.
The sandbox does not limit these things:
- What the app draws in its own windows. An app can show a window that looks like the window of another program. Read the address before you type a password into it.
- CPU time. The app has no compute limit, so a module can keep the processor busy. Close the window of an app that does not answer.
The module runs in the WebAssembly engine of ztcl. On x86-64 Linux and macOS, the engine compiles the module to machine code, so the engine and its JIT are part of the attack surface. Rust, Go, or JavaScript has the steps to run an app.
The ztk library turns on no capability of ztcl, except interp at the first call of interp. It reaches the host only through its backend. A program that embeds it decides each capability and each limit. See Embed in Zig.
In the browser, the page is the embedder. A script there has no file, network, or process access.
A script in the ztk program reaches parts of the desktop through the backend of each system:
| Part | What a script can do | Notes |
|---|---|---|
| The clipboard | Read and write the text of the clipboard of the system with clipboard. |
Windows, macOS, and Wayland. On X11 and in the browser, the clipboard is local to the app. |
| Drag and drop | Get the paths of the files and the text that the user drops on a window of ztk::dnd. Start a drag out of a window. |
ztk::dnd |
| File dialogs | Show the dialog of the system and get the path that the user picks. | They need file. On Linux they go through the FileChooser portal when the session bus has one. |
| Global shortcuts | Get a key of the desktop with ztk::hotkey. |
Only with --allow hotkey. |
| The tray, the taskbar, recent documents, and notifications | ztk::tray, ztk::taskbar, ztk::recent, and ztk::toast. |
The ztk:: commands |
These tools act on the widgets of the app with no person at the keyboard:
ztk::injectsends pointer, wheel, key, and text events to the widgets of the app.ztk::debuggives the state of each widget, the trace of each event, and images of the window.ztk --mcp app.tclruns the app on the headless backend and serves the MCP tools ofztk::debugon stdin and stdout. The tooltcl_evalruns each script that the client sends, with the capabilities of the program. Treat the MCP client as trusted.
Each script has ztk::inject and ztk::debug. They act only on the windows of the app. An app from a URL has neither of them. See MCP tools.
Send a private report through the GitHub Security tab of beetlebugorg/ztk. Do not file a public issue or start a public Discussion.
You can also write to [email protected]. Put "security" in the subject.
Include these items:
- The smallest script or module that shows the problem.
- The output of
ztk --version, and the system and the backend. - The command line: the flags, the capabilities, and the root folder.
- What happened, and what you expected.
A problem in the interpreter goes to ztcl. Report it to ztk when you are not sure.
The docs site publishes this file, SECURITY.md of the repository, as its Security page.