git-ents.gitmain
⌘K
foforge
commit 798fe87
fix: source web tokens from getrandom so editing works on Windows

random_token opened /dev/urandom directly, which does not exist on Windows, so login nonces and CSRF/session/staging tokens could not be generated and every web-edit test failed on windows-latest. Read OS randomness through getrandom instead.

fix: replace /dev/urandom read with getrandom::fill build: add getrandom dependency Assisted-by: Claude:claude-opus-4-8

Joseph D. Carpinelli · 1 month ago

Reviews

No reviews of this commit yet — record a verdict below.

Start a review

verdict

Cargo.lock @@ -1041,6 +1041,7 @@ "clap", "clap_mangen", "facet", + "getrandom", "git-ents", "gix-actor", "gix-date",
Cargo.toml @@ -36,6 +36,7 @@ clap = { version = "4.5.60", features = ["derive"] } clap_mangen = "0.2.31" facet = { version = "0.50.0-rc.0", features = ["reflect"] } +getrandom = "0.4" facet-git-tree = { git = "https://github.com/git-ents/facet-git-tree" } git-store = { path = "crates/git-store" } gix = "0.84"
crates/git-ents-server/Cargo.toml @@ -15,6 +15,7 @@ clap = { workspace = true } clap_mangen = { workspace = true } facet = { workspace = true } +getrandom = { workspace = true } gix-actor = { workspace = true } gix-date = { workspace = true } gix-hash = { workspace = true }
crates/git-ents-server/src/web/write.rs @@ -14,7 +14,7 @@ //! their public key. use std::collections::HashMap; -use std::io::{Read as _, Write as _}; +use std::io::Write as _; use std::path::Path; use std::process::{Command, Stdio}; use std::sync::{Arc, Mutex}; @@ -414,9 +414,7 @@ /// A fresh, unguessable token: 32 random bytes from the OS, hex-encoded. fn random_token() -> Result<String, String> { let mut bytes = [0u8; 32]; - std::fs::File::open("/dev/urandom") - .and_then(|mut file| file.read_exact(&mut bytes)) - .map_err(|e| format!("could not read randomness: {e}"))?; + getrandom::fill(&mut bytes).map_err(|e| format!("could not read randomness: {e}"))?; Ok(bytes.iter().map(|byte| format!("{byte:02x}")).collect()) }