Skip to content

Commit 063dbee

Browse files
plotnickclaude
andcommitted
Tighten the token cache
A backward clock step no longer leaves a future-stamped token trusted forever, and the cache file is born 0600 instead of being chmodded after open. Co-Authored-By: Claude Mythos 5 <noreply@anthropic.com>
1 parent 2866d77 commit 063dbee

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

client/src/cli.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
77
use std::collections::BTreeMap;
88
use std::fmt;
9-
use std::fs::{self, Permissions};
9+
use std::fs;
1010
use std::io::{self, BufRead as _, ErrorKind, Read as _, Write as _, stderr, stdin, stdout};
11-
use std::os::unix::fs::PermissionsExt as _;
11+
use std::os::unix::fs::OpenOptionsExt as _;
1212
use std::path::{Path, PathBuf};
1313
use std::sync::{Arc, Mutex};
1414
use std::time::{Duration, SystemTime};
@@ -154,13 +154,13 @@ impl Cli {
154154
}
155155
}
156156

157-
/// Atomically write a file only the user may read.
157+
/// Atomically write a file only the user may read, born that way
158+
/// rather than chmodded after opening.
158159
fn write_private(path: &Path, bytes: &[u8]) -> io::Result<()> {
160+
let mut options = fs::OpenOptions::new();
161+
options.write(true).create(true).truncate(true).mode(0o600);
159162
AtomicFile::new(path, OverwriteBehavior::AllowOverwrite)
160-
.write(|file| {
161-
file.set_permissions(Permissions::from_mode(0o600))?;
162-
file.write_all(bytes)
163-
})
163+
.write_with_options(|file| file.write_all(bytes), options)
164164
.map_err(|error| match error {
165165
atomicwrites::Error::Internal(error) | atomicwrites::Error::User(error) => error,
166166
})
@@ -282,7 +282,7 @@ impl CommandContext for Cli {
282282
created,
283283
}) if saved_url == url
284284
&& saved_fingerprint == fingerprint
285-
&& Utc::now() - created < TOKEN_REUSE =>
285+
&& (TimeDelta::zero()..TOKEN_REUSE).contains(&(Utc::now() - created)) =>
286286
{
287287
Some(token)
288288
}

0 commit comments

Comments
 (0)