1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! HTTPS enforcement and the resolved-address guard tiers shared by every transport.
use crate;
use crate;
use crateRedactedUrl;
use Url;
/// Whether `url`'s host is loopback (`127.0.0.1`, `localhost`, or `::1`), with an
/// `http`/`https` scheme and an optional port — the shape every `mockito::Server` binds to.
///
/// Only compiled into test builds (see [`ensure_https`]): a non-loopback host must never
/// be allowed to bypass the HTTPS requirement, even under `cfg(test)`/`test-util`. See
/// [`crate::net_policy::validate_index_url`]'s own private loopback check (`is_loopback_url`)
/// for the counterpart this was modeled on — `is_loopback_url` now matches [`Url::host`]'s
/// structured `Host` enum (`Ipv6Addr::LOCALHOST` comparison, #1568) rather than comparing the
/// bracketed string form, closing the IPv6-loopback gap this doc used to describe as
/// pre-existing/out of scope. The two still differ in accepted scheme: this
/// function matches both `http` and `https` (symmetric with [`ensure_https`]'s own scheme
/// check), while `is_loopback_url` only ever matches `http` — its caller already treats
/// `https` as satisfying the requirement outright, so an `https` loopback host has no need for
/// the carve-out.
///
/// Parses with [`Url::parse`] and compares [`Url::host_str`] rather than splitting the raw
/// string on `:` — a naive split misreads userinfo as the host boundary (e.g.
/// `http://localhost:80@evil.com/x`'s actual host is `evil.com`, but splitting on the first
/// `:` yields `localhost`), which let a public HTTP host bypass the HTTPS requirement by
/// prefixing a loopback-looking userinfo (#1562).
pub
/// Validates that a URL uses HTTPS protocol.
///
/// Returns [`DepsError::InsecureScheme`] if the URL doesn't start with "https://".
/// This ensures all network requests are encrypted.
///
/// Callers pass only URLs built from a configured or operator-declared base; a URL a registry
/// supplies must be vetted by its ecosystem before it reaches here, so this error stays a
/// configuration fault.
///
/// A loopback HTTP URL (`127.0.0.1`/`localhost`/`::1`, the shape every `mockito::Server`
/// binds to) is allowed in `deps-core`'s own test builds (`cfg(test)`) and in other
/// workspace crates' test builds via the `test-util` feature — `cfg(test)` alone does not
/// apply there, since those crates depend on `deps-core` as a normal, non-dev dependency.
/// Any other HTTP host is still rejected even under those cfgs: `test-util` is a public,
/// independently-enablable crates.io feature, so this must not become "any host, any
/// environment" just because the feature is on.
pub
/// True when a redirect hop moves from an `https` origin to a plain `http` one.
///
/// A redirect to any scheme other than `http`/`https` is already rejected by reqwest
/// itself once a hop is followed, so the downgrade case is the only one this needs to
/// catch here.
pub
/// Whether a redirect hop's target host is one [`crate::net_policy::HostClass::never_a_registry`]
/// blocks, exempting `Loopback` in test builds — the identical carve-out [`ensure_https`]
/// already uses, without which every mockito redirect chain in this workspace's tests would
/// break.
pub
/// The tier a [`Transport`](super::transport::Transport)'s redirect policy and DNS resolver both enforce.
///
/// `WorkspaceDeclared` holds an [`AccessSnapshot`] (level and allowlist) **value snapshot**, taken once at
/// [`Transport::workspace`](super::transport::Transport::workspace) construction time — not a live `Arc<RegistryAccessPolicy>` read on
/// every `AddrGuard::permits_declared` call. [`Transport::workspace`](super::transport::Transport::workspace) takes this same snapshot for its
/// paired [`CacheTier::WorkspaceDeclared`](super::CacheTier::WorkspaceDeclared), and [`HttpCache::set_registry_policy`](super::HttpCache::set_registry_policy) rebuilds the
/// whole `Transport` (both snapshots included) on every actual policy transition, so a
/// request's cache key and its guard always come from one consistent construction-time value,
/// with no read-skew window between them.
pub