Home / Docs / Diagnostics
U6004: A header value contains a control character
Release v0.4.0
una run and native executables abort when an operation of Http is given a header whose value contains a control character other than a tab: a byte below 0x20, or 0x7f (spec/24 §1). The diagnostic points at the operation. Nothing is sent.
Why Una rejects it
It is an abort, not an HttpError, because a header's value is internal (spec/24 §5). A failure the program could handle would tell it whether an internal value holds a control character, one bit per request. An abort ends the run, which is outside the noninterference model, as running out of depth or memory is (spec/07 §1).
How to fix it
A program that builds a header value from data removes the control characters first, for example with replace.
The repair at a glance
src/demo.una
module demo
pub main() -> Unit
uses @http: Http[get]
=
- let token = "abc\ndef"
+ let token = "abc\ndef".replace(pattern: "\n", by: "")
let r = attempt @http.get("http://127.0.0.1:9/", headers: [Header(name: "X-Token", value: token)], key_name: None)
unitFailing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
[run]
entry = "demo"
grants = ["http:http://127.0.0.1:9"]src/demo.una
module demo
pub main() -> Unit
uses @http: Http[get]
=
let token = "abc\ndef"
let r = attempt @http.get("http://127.0.0.1:9/", headers: [Header(name: "X-Token", value: token)], key_name: None)
unitFixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
[run]
entry = "demo"
grants = ["http:http://127.0.0.1:9"]src/demo.una
module demo
pub main() -> Unit
uses @http: Http[get]
=
let token = "abc\ndef".replace(pattern: "\n", by: "")
let r = attempt @http.get("http://127.0.0.1:9/", headers: [Header(name: "X-Token", value: token)], key_name: None)
unit