---
title: "Information flow"
url: https://una-lang.org/en/docs/language/information-flow/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/docs/guide/syntax-reference.md
---

# Information flow

## 8.1 Labels

Every type can carry a label: `secret[PII] Phone`, `internal Hashed`. A type without a label is `public`.

- **Levels,** from least to most sensitive: `public` ⊏ `internal` ⊏ `confidential` ⊏ `secret` ⊏ `restricted`.
- **Categories** are declared per package in `una.toml` (`[labels] categories = ["PII", "Location"]`). An undeclared category is U4007.
- **Order:** a label flows into another if its level is lower or equal **and** its categories are a subset.

## 8.2 Explicit and implicit flows

- **Results carry their inputs' labels.** The result of an operation is labeled with the join of its operands.
- **Branches raise the program-counter label (pc).** Branching on labeled data raises the pc inside the branches, and values produced there carry it.

```una
module demo

pub kind Person
  name: Text
  age: secret Int

--- The branch is on secret data, so the result is secret too.
pub adult_flag(r: Person) -> secret Int = if r.age > 17 then 1 else 0
```

- **Returns.** A function's result label must fit its declared return type (U4001).
- **Editable bindings** keep their declared label: a rebind under a pc above it is U4001.

## 8.3 Failing and calling under a raised pc

- `fail` inside a branch on secret data leaks information through the failure, so it is rejected (U4002). Return a labeled value instead.
- Calling a function that performs effects or can fail is allowed under a raised pc only if every sink it reaches accepts that pc (U4002).

```una
-- fails with U4002
module demo

pub kind PinError = | Rejected

pub check(pin: secret Int) -> secret Int
  fails PinError
=
  if pin == 1234
    1
  else
    fail Rejected
```

## 8.4 Sinks

- **Operation arguments are sinks.** Every capability operation argument is a sink bounded by the operation's `accepts` label: `pc ⊔ label(args) ⊑ accepts`, otherwise U4003.
- **Console is public.** `Console.print` accepts `public` only:

```una
-- fails with U4003
module demo

pub show(phone: secret Text) -> Unit
  uses @console: Console[print]
=
  @console.print("phone {phone}")
```

- **Tests are exempt.** `expect` lines in examples observe values for the test harness and are exempt from sink checks.

## 8.5 Declassification: policies in trusted modules

Labels are lowered only through a declared policy, inside a trusted module:

`una.toml`

```toml
[package]
name = "events"
version = "0.1.0"
edition = "0.2"

[labels]
categories = ["PII"]

[trusted]
modules = ["events.keys"]
```

`src/events/types.una`

```una
module events.types

pub kind Phone = Text where valid_phone(it)

pub predicate opaque valid_phone(t: Text) -> Bool = t.len == 11 and is_digits(t)
```

`src/events/keys.una`

```una
trusted module events.keys

import events.types (Phone)

pub policy attendee_key
  from secret[PII] Phone
  to internal Hashed
  via hmac_phone
  purpose "registration lookup and audit correlation"
  owner privacy

hmac_phone(phone: secret[PII] Phone) -> internal Hashed
  uses @keys: Keys[hmac]
  fails KeyError
=
  @keys.hmac(key_name: "phone_pepper", data: phone)
    if error pass
```

- **Callable.** The policy becomes a function: `attendee_key(phone)`. Its `uses` and `fails` are those of the `via` function.
- **Only entry point.** The `via` function must be private (U4005), so the policy is the only way in. Flow checks are not performed inside it; it belongs to the trusted computing base.
- **Where policies live.** Policies are allowed only in trusted modules (U4004). A trusted module is declared both with `trusted module` and in `una.toml` (U7005 if either is missing).
- **Reported.** Every policy call site appears in the build report with its purpose and owner.

## 8.6 What the guarantee covers

Una guarantees **termination-insensitive noninterference up to declassification**. The channels in the model are values, failures, operation arguments and the occurrence of effects. Timing, termination and resource usage are outside the model, and so is the relative order of the effects of concurrent tasks (§5.7); the build report says so.

---


## Constructs

- [Labels](https://una-lang.org/en/docs/language/information-flow/labels.md)
- [policy: declassification](https://una-lang.org/en/docs/language/information-flow/policy.md)
- [trusted modules](https://una-lang.org/en/docs/language/information-flow/trusted.md)
