Skip to content
You are reading next, which describes the unreleased compiler. Khora is unstable before v1: syntax, standard-library APIs and behavior may change. The current release is documented under v0.4.

std::permissions

What the manifest allows, as data the program carries.

[permissions] in khora.toml says which paths a package may read and write. The answer itself lives in std::permissions::grants, which khora build writes; this module is the part that decides what an answer means, and std::fs’s real handlers consult it before touching a file.

The grants are compiled in, not read at run time. A file the program consults for its own permissions is a file an attacker edits; a list the compiler wrote into the binary is one nothing at run time can widen.

Why this is a file you can read rather than a check inside the compiler

Section titled “Why this is a file you can read rather than a check inside the compiler”

The compiler contributes data. Everything that decides whether a path is allowed is here, in Khora, and can be read, tested and stepped through – which is the whole reason the enforcement is not a pass in khora-types that nobody outside the compiler can see. The design document is explicit about it: “ordinary Khora in a module you can read, not a second enforcement engine hidden in the compiler”.

Everything. A missing [permissions] table grants everything, which is opt-in tightening rather than a tax on starting – the same bargain Rust makes with unsafe. The default below is the one a program with no manifest, or no [permissions.fs], compiles with, and khora build narrows it only when the manifest asks.

Types: Reach

Functions: granted · granted_followed · reach · granted_name · granted_host · may_dial · unbracketed · granted_listen · normalized

pub type Reach =
| Inside
| Outside
| Unfollowable;

What reach found.

| Inside

The text and where it leads are both inside a grant.

| Outside

The text, or where it leads, is outside every grant.

| Unfollowable

The text is inside a grant and the links along it cannot be followed: a loop, or a directory this process may not search.

pub fn granted(grants: List<String>, path: String) -> Bool

Whether any grant covers path.

The glob dialect is .gitignore’s, because it is the one everybody already has in their fingers:

  • * matches within one path segment and stops at a separator.
  • ** matches across separators, so data/** covers data/a/b.txt – though not data itself, which is .gitignore’s reading too.
  • Everything else matches itself.

On Windows, separators are normalized first, so a grant written with / covers a path spelled with \\; elsewhere \\ is an ordinary byte of a name. granted_path in khora-manifest answers the same question for the compiler and the two have to agree; the tests name the cases where agreement is not obvious.

A path with a .. segment is refused unless a grant is a bare **, and it is refused here rather than left to the matcher, because the matcher gets it wrong. ** spans separators, so the ./logs/** the capabilities guide teaches for granting a tree matches logs/../secret.txt literally: the ** swallows ../secret.txt, and a grant that reads like one directory covers the disk. A program that joins a path it was handed – an argument, a config entry, a request path – under a granted prefix was passing that reach on to whoever handed it the path. normalized says why the .. is refused rather than resolved away.

A bare ** is the one grant with no outside for a .. to reach, so under it a .. path is matched like any other. That is the grant a program with no [permissions.fs] gets, and default = "allow" too.

This answers about the text only. A symlink in the path can lead somewhere the text does not say; std::fs asks granted_followed, which follows the links as well.

pub fn granted_followed(grants: List<String>, path: String, follow_last: Bool, real: (String, Bool) -> Option<String>) -> Bool

Whether a grant covers path and where path really leads.

granted reads the path as text, and text says nothing about the links along it: under granted/**, granted/link.txt -> ../secret.txt is a path the text covers and a file outside the tree. So this asks real to follow the links, and matches the answer as well – against each grant followed the same way, because a grant is a path too, and one naming a linked directory grants the tree it leads to.

Both have to agree. The text check is granted unchanged, .. refusal and all, so following links never widens what the text allowed; it can only refuse a path the text let through.

  • real(p, true) is the absolute path p leads to with every link on it followed, or None when it cannot be followed (a loop, a directory this process may not search). A name that does not exist yet is kept as written, so a write to a new file is checked where it will land.
  • follow_last is false for an operation that acts on a link rather than through it – removing or renaming one – which follows only the directories above the last name.

A relative grant is a tree under the working directory once links are followed, because that is the only directory a relative path can be followed from. **/*.txt covers .txt files below the working directory and not an absolute path elsewhere, even one the text would match.

A path that cannot be followed is Reach::Unfollowable, not Reach::Outside. Nobody can say it is inside a grant, so it is refused either way; but a loop or a directory without search permission is the file system’s answer, not the manifest’s, and std::fs reports it as IoError::Failed so that nobody goes looking in khora.toml for it.

What this does not close: a link that changes between the check and the open. The check follows the links that are there when it runs; the open follows the ones that are there when it runs. Something else on the machine that can replace a link inside a granted tree in between can redirect one operation. Closing that needs the open itself to refuse to leave the tree, which std::fs does not do.

Nor a link a grant names. Grants are followed on every operation, so a grant like data/** where data is a link covers wherever data leads at that moment. Whoever can replace that link moves the grant, for as long as the link stays replaced – not one operation but all of them.

Nor a hard link. A hard link has no “where it leads”: it is the file, under a second name. One inside a granted tree is inside the tree, whatever other names the same file has.

Costs nothing under a bare **, which has no outside to lead to. Under any other grant it is one real for the path and one per grant, each of which is a walk of the file system.

pub fn reach(grants: List<String>, path: String, follow_last: Bool, real: (String, Bool) -> Option<String>) -> Reach

granted_followed, saying which way a refusal went.

pub fn granted_name(grants: List<String>, name: String) -> Bool

Whether any grant covers name.

For things that are not paths – an environment variable, a command – where there are no segments and so * spans everything. DATABASE_* covers DATABASE_URL, and * covers all of them.

granted_name in khora-manifest answers the same question for the compiler, and the two are tested against one table.

pub fn granted_host(grants: List<String>, host: String) -> Bool

Whether any grant covers host, which is name or name:port.

Two rules, and both are the reading that costs a newcomer least:

  • * spans dots, so *.internal covers db.eu.internal and not only db.internal. That is what a Content-Security-Policy origin means by it; the one-label reading belongs to TLS certificates, and surprising somebody into a denied connection is the worse failure.
  • A grant with no port covers every port, which is what Deno’s --allow-net=example.com does. :* says the same thing explicitly.
pub fn may_dial(grants: List<String>, host: String, port: Int) -> Bool

Whether any grant lets a program dial host on port: granted_host on host:port.

host may be an IPv6 literal with or without its brackets. Unbracketed is safe here because the port is always appended and has no colon in it, so the last colon is always the port’s: ::1 on 5432 is asked about as ::1:5432, which splits into ::1 and 5432, and [::1]:5432, [::1]:* and [::1] in a manifest all cover it. It is a grant that has to be bracketed, because a grant may have no port at all.

A host with a bracket in it is refused unless it is exactly [addr]. [::1]:5432 handed in as the host made the subject [::1]:5432:<port>, which splits to the name ::1 and the port text 5432:<port>, so a grant of [::1] with no port covered it and the name went to the resolver as written. No resolver tried took it, but a check that waves through a host it cannot read is relying on the resolver to refuse; it refuses here instead, before anything is looked up.

pub fn unbracketed(host: String) -> String

host without the brackets an IPv6 literal is written in: [::1] is ::1, which is what an address parser takes. Anything else is unchanged.

So a program may write [::1], as a URL would, and the connect it hands that to still reaches the address.

pub fn granted_listen(grants: List<String>, address: String) -> Bool

Whether any grant in [permissions] listen lets this program bind address, which is <interface>:<port> as the program binds it: 0.0.0.0:8080, or [::1]:9000 for an IPv6 interface, with port 0 for one the operating system chooses.

Matched as bound, not as meant. std::net::socket::listen_on(8080) binds every IPv4 interface, so it asks about 0.0.0.0:8080, which 8080 covers.

A manifest entry is a port (8080), a range (8000-8099), 0, or *. Port 0 is covered by 0 or a * alone, never by a number or a range: the port the operating system picks can be any of them, so a grant of 8080 that also covered port 0 would let the program listen wherever it was handed.

An entry naming an interface (127.0.0.1:9000, [::1]:*) is read here – it covers that interface’s address – but no manifest can hold one: a listener binds every interface, so one would grant nothing, and a manifest refuses it when it loads. The shape is read so that this and the compiler agree about it for when one interface can be bound.

An entry that is none of those shapes covers nothing. A manifest refuses one when it loads, so this only matters for a list that reached std some other way. An interface is compared as written: [::1] and [0:0::1] are one address and two different entries. * covers any address, even one that is not a port on an interface – 0.0.0.0:70000 – so a program with no table binds exactly what it did without one.

granted_listen in khora-manifest answers the same question for the compiler, and the two are tested against one table.

pub fn normalized(path: String) -> String

One spelling of a path, so a grant and a request can be compared.

Two things are leveled, and both were reported as traps by somebody who hit them:

  • On Windows, \\ becomes /, so a grant written with forward slashes covers a path spelled with back ones. Only there: on every other system a backslash is an ordinary byte in a file name, so granted\evil is a directory beside granted, and reading it as granted/evil let granted/** cover a tree the manifest never named.
  • A . segment is dropped, so ./data/** grants data/foo.txt and data/** grants ./data/foo.txt. Before this, the ./ was significant on both sides: two readers of capabilities.md wrote the example’s read = ["./data/**"] into a manifest, opened data/foo.txt, and were refused by a grant that looks like it says yes.

.. is neither resolved nor leveled here; granted refuses the path outright. Both of the other answers widen a grant, which is the one direction a permission check must never be wrong in.

Resolving a/../b to b is only correct if a is a real directory. Where a is a symlink, a/.. is the parent of what a points at, so the open lands on the target’s neighbor b while the check approved the b beside a – it would be answering about a file the filesystem does not open. Telling those apart needs the filesystem, and this function has only the string.

Comparing the .. as written is not the safe half it looks like. ** crosses separators, so ./logs/** matches logs/../secret.txt as text and grants it. No spelling of the comparison is right for both logs/a.txt and logs/../secret.txt, so a path with a .. segment is not compared at all. A caller that means a/../b can pass b; one that cannot is asking a question only the filesystem can answer.

Nor is anything resolved against a working directory or a package root. A grant is matched against the path the program passes, so a program that builds its paths from its own arguments needs a grant wide enough to cover what its users will type. The permissions design note records why that is the boundary and what it costs a CLI.

Khora 0.4.0built fromee766ae43388on 2026-11-26 22:56ZVersioningSecurityContributingReleasesSource