Home / Docs / Diagnostics

U4003: Sink label exceeded

Release v0.4.0

A capability operation is given data, or runs under a program counter, that is not below the operation's accepts label.

Why Una rejects it

Every argument of a capability operation is a sink with the operation's accepts label, public when the operation declares none (spec/05 §2, spec/07 §4). The data an operation sends outside the program, every label of its type, and the program counter under which it runs, must be below that label. Interpolation keeps the labels of what it interpolates, so printing "id {phone}" of a secret phone to Console, which accepts public, is U4003. (Edition 0.3, ADR 0094 rule 7.)

When the label comes from the answer of an operation that its binding labels with gives, the message and the first repair name that binding and operation, as "the answer of @service_files.owner, labeled internal[Service]", and the call is a related location.

In a program that serves (edition 0.4, spec/31 §1 rule 5 item 6), a start that moves a reply right to its task is a sink of internal too. When the task ends without replying, the host answers for it, and a task that runs past --task-depth ends alone and is answered 500. So a peer that varies its request could read from the status how deep the task went. A start is therefore U4003 at the start when both hold:

The rule is coarse: it does not ask whether that data decides the recursion.

What Env.get and Files.read return is internal, so printing it, or anything computed from it, is U4003 too, and no label of the program can be lowered to fix it.

How to fix it

The repairs that keep the label come first:

Declassifying through a policy is the last repair, marked as an escape (ADR 0095): the guarantee then rests on the policy's trusted code, whose labels are not checked.

When the label comes from the answer of an operation that its binding labels with gives:

In a program that serves, the repair keeps the task's data at most internal, by moving the secret work out of a task that recurses, or keeps a task that holds secret data free of recursion and of function values. Prelude functions such as trim and sort are fine.

When what Env.get and Files.read return must be printed, the escape is the only route: declassify it through a policy in a module that both its header and una.toml mark trusted, and call the policy where the data is printed, as the second fixed example does. The build report lists every call of a policy with its purpose and owner.

The repair at a glance

diff
  module demo

- pub greet(name: secret Text) -> Unit
+ pub greet(name: Text) -> Unit
    uses @console: Console[print]
  =
    @console.print("hello {name}")

Failing example

una
module demo

pub greet(name: secret Text) -> Unit
  uses @console: Console[print]
=
  @console.print("hello {name}")

Fixed example

una
module demo

pub greet(name: Text) -> Unit
  uses @console: Console[print]
=
  @console.print("hello {name}")

Fixed example: data from the environment, through a policy

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"

[trusted]
modules = ["release"]
src/release.unauna
trusted module release

pub policy shown_name
  from internal Text
  to public Text
  via as_shown
  purpose "greet the user by the name the environment gives"
  owner demo_owner

as_shown(name: internal Text) -> public Text = name
src/demo.unauna
module demo

import release (shown_name)

pub main() -> Unit
  uses @console: Console[print]
  uses @env: Env[get]
=
  let name = @env.get("USER")
    if none use "nobody"
  @console.print("hello {shown_name(name)}")