[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:
@@ -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),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -123,6 +123,8 @@ pub struct Runtime {
|
||||
pub share_key: Option<Arc<ShareKey>>,
|
||||
/// Loaded when any host has `device_certs`.
|
||||
pub device_trust: Option<Arc<crate::tls::DeviceTrust>>,
|
||||
/// Peers whose X-Forwarded-For names the client.
|
||||
pub trusted_proxies: Vec<std::net::IpAddr>,
|
||||
/// SHA-256 (hex) of the config file bytes this runtime was built from; empty when it was
|
||||
/// built from a parsed config.
|
||||
pub sha256: String,
|
||||
@@ -470,9 +472,20 @@ pub fn build(cfg: EdgeConfig, credentials_dir: Option<&Path>) -> Result<Runtime,
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let trusted_proxies = cfg
|
||||
.trusted_proxies
|
||||
.iter()
|
||||
.map(|s| {
|
||||
s.parse().map_err(|_| EdgeError::Config {
|
||||
path: PathBuf::from("<config>"),
|
||||
message: format!("trusted_proxies: {s:?} is not an IP address"),
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<std::net::IpAddr>, _>>()?;
|
||||
|
||||
Ok(Runtime {
|
||||
cfg,
|
||||
trusted_proxies,
|
||||
hosts,
|
||||
forward_auth,
|
||||
access_log,
|
||||
|
||||
Reference in New Issue
Block a user