Home / Docs / Diagnostics
U4001: Flow to a lower label
Data flows to a lower label. The message names the declared type and the value's type with their labels.
Why Una rejects it
A label says who may observe a value, and data never flows to a lower label (spec/07 §3): a value flows into a parameter, a field, an annotated let, a policy's from type or a function's result only when each position of its type is labeled below the declared label there.
Labels follow data:
- an operator, an interpolation or an equality takes the labels of its operands;
- a generic call the labels of its arguments;
- the value of an
iforwhenthe label of its condition, which also makes the condition of a branch in a return position an implicit flow into the result.
In a generic body, a value decided by comparing values of a type parameter T carries label(T*), every label of T's type argument, which is not below label(T): it cannot flow into an annotation, a field or a function value's parameter of type T, as in [if a == b then p else q].map(each: k).
In edition 0.4, an http grant of run grants with limits needs every Http request timed by internal data at most, since HttpError.RateLimited reveals when each request was made (ADR 0117 IF4, spec/27 §9): a request in a function that also works on a secret parameter is U4001 at the request.
A limiter of std.limit the same (ADR 0117 IF5, spec/27 §10): whether acquire finds a token depends on the timing of the statement its with scopes over, so that statement must be timed by internal data at most; U4001 at the binding otherwise.
In edition 0.4, the host hands the state of a drive module from init to step, from init and step to on_stop, and that hand-off is a flow too (spec/26 §2 rule 2): a state parameter of step or on_stop labeled below the type it receives, as step(edit count: Int, ...) after init() -> secret Int, is U4001 at the parameter's type.
In edition 0.4, no label is checked in a policy's via function, but a deadline or race outcome may reach its result only if what runs beside it cannot time it (spec/07 §5 rule 7, ADR 0098): a within, first of, for ever within or limiter in a via body, or in code it calls, is U4001 at the site when the policy can be called beside other tasks, as in a branch of together, since whether the deadline passes or which branch wins would then release their timing at the label of the policy's to.
A via that calls a function value, or applies one whose code is not known at the call, reaches the code of every lambda and every function named as a value, so their timing sites count wherever the policy is called.
(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.
How to fix it
- Raise the declared label, or lower the value's label through a policy (spec/07 §5).
- A declared label of the standard library, a field of a kind such as
HeaderorJsonor a parameter of a host operation, cannot be raised: lower the value through a policy. - For an HTTP request, a token the API takes as a bearer token goes by the name of its key,
key_name, which sendsAuthorization: Bearer <key>without the program seeing it. A token the API takes in another header, asX-Api-Token, is a header value, so asecretone goes through a policy tointernalfirst (spec/24 §1). - In a generic body, pass values of
Tthrough unchanged, or return the decision to the caller (spec/07 §7 rule 8; the guide's section on labels). - For a request under an
httpgrant with limits, move that work out of the function that makes the request, or remove the limits. - For a
limiter, move the work on data aboveinternalout of the statement, or install thelimiteraround a statement that does not compute on it. - For a state parameter of
steporon_stop, label the parameter at least as high, position by position. - For a
within,first of,for ever withinorlimiterin aviabody, or in code it calls, call the policy outside every part of a task construct, or move the deadline or the race out of theviafunction and the code it reaches. - For a
viathat calls a function value, pass only lambdas written at the call to functions such asmapin theviaand the code it calls. - When the label comes from the answer of an operation that its binding labels with
gives: read the operation through a binding that answers within the declared label, send the value where its label may go, or, last, release the answer through a policy of a trusted module.
The repair at a glance
module demo
- pub leak(pin: secret Int) -> Int = pin
+ pub keep(pin: secret Int) -> secret Int = pinFailing example
module demo
pub leak(pin: secret Int) -> Int = pinFixed example
module demo
pub keep(pin: secret Int) -> secret Int = pin