Skip to main content

daemon_credential_for

Function daemon_credential_for 

Source
pub fn daemon_credential_for(base_url: &str) -> Option<String>
Expand description

The credential to send to base_url, or None when there is none to send or none that may be sent.

Why: the token authenticates a caller to the LOCAL daemon, and nothing else. A base URL can legitimately name a non-loopback address (an operator forwarding a port, a remote daemon over a tunnel), and attaching the local machine’s credential to a request leaving loopback would hand it to whatever answers. This crate resolves it in one place so no request site grows its own answer. What: a thin naming of trusty_common::daemon_token::credential_for, which owns the loopback gate, the override precedence, and the file read.

The gate lives THERE and not here for a reason worth stating: the first version of this function called server::origin_is_loopback, an Origin-HEADER parser, which reads http://127.0.0.1:7882@attacker.example as loopback and shipped the token off-machine. trusty-code-gui had the identical bug in its own copy. One implementation, parsing the way the client that dials the URL parses. Test: http_credential_tests::credential_is_withheld_from_a_non_loopback_url, http_credential_tests::credential_env_override_wins_for_a_loopback_url.