From 5ba6e820ca2fbdcf5675431771716229f21765b9 Mon Sep 17 00:00:00 2001 From: ari Date: Tue, 20 Oct 2026 16:16:30 -0400 Subject: [PATCH] H: name the token mode check after what it rejects --- src/peers/secrets.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/peers/secrets.rs b/src/peers/secrets.rs index 28069d4..806eb87 100644 --- a/src/peers/secrets.rs +++ b/src/peers/secrets.rs @@ -21,7 +21,8 @@ fn header_safe(text: &str) -> bool { && axum::http::HeaderValue::from_str(&format!("Bearer {text}")).is_ok() } -/// Read `peer.token_file`, trimming one trailing newline. +/// Read `peer.token_file`, trimming one trailing newline. The value must be +/// usable as a bearer header verbatim, so control characters are refused. /// /// Group- and world-accessible files are rejected unless the path is inside /// `$CREDENTIALS_DIRECTORY` (systemd's credential dir is not mode 0600; the @@ -49,7 +50,7 @@ pub fn load_token_at( return Err(PeerError::TokenFile("not a file".into())); } if !under_credentials(path, credentials_dir) { - reject_group_or_world_readable(&meta)?; + reject_group_or_world_accessible(&meta)?; } if meta.len() > MAX_TOKEN_BYTES as u64 { return Err(oversize()); @@ -76,7 +77,7 @@ fn oversize() -> PeerError { PeerError::TokenFile(format!("larger than {MAX_TOKEN_BYTES} bytes")) } -fn reject_group_or_world_readable(meta: &std::fs::Metadata) -> Result<(), PeerError> { +fn reject_group_or_world_accessible(meta: &std::fs::Metadata) -> Result<(), PeerError> { use std::os::unix::fs::PermissionsExt; // Other users who can reach the file can call the peer as this // consolidator, and one who can write it can swap the token.