Skip to main content

resolve_urls

Function resolve_urls 

Source
fn resolve_urls(
    url: &Url,
    config: Option<&ConfigFile>,
) -> (String, String, bool)
Expand description

Resolve the API and identity base URLs to talk to for a given Send link, plus whether that host is trusted.

Both URLs are needed: the send-access token is minted at {identity}/connect/token and the send itself is read from {api}. Precedence:

  1. A known Bitwarden cloud host (exact match — see CLOUD_HOSTS). Trusted.
  2. The locally configured deployment (bw config server) when the link’s origin matches it — explicit api/identity overrides win, otherwise the base is suffixed. Trusted.
  3. Otherwise <origin>/api + <origin>/identity, the single-domain self-host convention and the legacy CLI’s final fallback. Not trusted.

The trust flag gates the send-access-token cache (send_access_token_cache): only a trusted host’s token gets persisted to disk at all, matching the corresponding TS client fix (which caches only for configured and trusted domains). This is a stricter rule than correctness alone requires — send_access_token_cache’s (resolved_host, send_id) key already prevents a token from being looked up under a different host than the one it was minted against — but it keeps this CLI from ever writing a persistent, on-disk credential for an arbitrary, untrusted Send-link host, not just from misusing one it already wrote.

Pure so the precedence can be unit-tested without a client or a config file on disk.

See the module-level PM-40120 note: this unconditional host resolution — always the link’s own host, never a separately configured environment.