[control] QC minors: device install links open a page and download on POST (never listed), approve and install failures show on the request and the CLI waits, PBKDF2 floor, private pki dirs or an error, trusted_proxies for a proxy in front, a placeholder keeps the device allow list from being empty (Caddy refuses that)

This commit is contained in:
2026-11-08 11:02:50 +01:00
parent bc336d1188
commit 3bf5fa0e1a
27 changed files with 548 additions and 46 deletions
+42 -7
View File
@@ -75,11 +75,35 @@ pub fn hostname(host_header: &str) -> String {
name.to_ascii_lowercase()
}
pub fn client_ip(session: &Session) -> Option<IpAddr> {
session
/// The client's address: the peer, or, when the peer is a trusted proxy, the rightmost
/// `X-Forwarded-For` entry that is not itself trusted (the same right-to-left rule as Caddy's
/// `trusted_proxies_strict`). Anything a client could forge to the left is ignored.
pub fn client_ip(session: &Session, trusted: &[IpAddr]) -> Option<IpAddr> {
let peer = session
.client_addr()
.and_then(|a| a.as_inet())
.map(|a| a.ip())
.map(|a| a.ip())?;
if !trusted.contains(&peer) {
return Some(peer);
}
let mut last = peer;
for v in session
.req_header()
.headers
.get_all("x-forwarded-for")
.iter()
.rev()
{
let Ok(s) = v.to_str() else { return Some(last) };
for part in s.rsplit(',') {
match part.trim().parse::<IpAddr>() {
Ok(ip) if trusted.contains(&ip) => last = ip,
Ok(ip) => return Some(ip),
Err(_) => return Some(last),
}
}
}
Some(last)
}
/// A response with an empty body, like Caddy's `static_response` and error responses.
@@ -157,7 +181,7 @@ impl ProxyHttp for EdgeProxy {
if !host.cfg.share_links {
share::strip_any_token(session)?;
} else {
let ip = client_ip(session);
let ip = client_ip(session, &rt.trusted_proxies);
let revs = self.shared.revocations();
match share::handle(
session,
@@ -198,7 +222,7 @@ impl ProxyHttp for EdgeProxy {
// A valid share link stands in for the sign-in on its prefix.
return self.after_auth(session, &host).await;
}
let ip = client_ip(session).map(|i| i.to_string());
let ip = client_ip(session, &rt.trusted_proxies).map(|i| i.to_string());
let outcome = match forward_auth::check(
&self.connector,
fa,
@@ -322,7 +346,12 @@ impl ProxyHttp for EdgeProxy {
}
req.insert_header(header::HOST, ctx.host_header.as_str())?;
// Forwarding headers are always edge's own; client-supplied values are replaced.
match client_ip(session) {
let trusted = ctx
.rt
.as_ref()
.map(|r| r.trusted_proxies.as_slice())
.unwrap_or(&[]);
match client_ip(session, trusted) {
Some(ip) => req.insert_header("X-Forwarded-For", ip.to_string())?,
None => {
req.remove_header("X-Forwarded-For");
@@ -415,7 +444,13 @@ impl ProxyHttp for EdgeProxy {
method: req.method.as_str(),
path: req.uri.path(),
status: session.response_written().map_or(0, |r| r.status.as_u16()),
remote_ip: client_ip(session).map(|i| truncate_ip(i).to_string()),
remote_ip: client_ip(
session,
ctx.rt
.as_ref()
.map_or(&[], |r| r.trusted_proxies.as_slice()),
)
.map(|i| truncate_ip(i).to_string()),
duration_ms: u64::try_from(ctx.start.elapsed().as_millis()).unwrap_or(u64::MAX),
});
}