Skip to content

Commit d1fa290

Browse files
committed
fix(windows): add preflight check for proxy auth file path
1 parent c1d5e98 commit d1fa290

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎crates/openshell-core/src/driver_utils.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ pub const MAX_UPSTREAM_PROXY_CREDENTIAL_BYTES: u64 = 4096;
330330
pub fn read_upstream_proxy_credential_file(path: &str) -> Result<String, String> {
331331
use std::io::Read as _;
332332

333+
// Windows rejects opening a directory before a file handle is available,
334+
// while Unix permits the open and rejects it via handle metadata below.
335+
// Preflight the path so every platform reports the intended non-regular
336+
// file error. The post-open check remains necessary to close the TOCTOU
337+
// window if the path is replaced between these operations.
338+
let path_metadata = std::fs::metadata(path)
339+
.map_err(|e| format!("failed to open proxy auth file '{path}': {e}"))?;
340+
if !path_metadata.is_file() {
341+
return Err(format!("proxy auth file '{path}' is not a regular file"));
342+
}
343+
333344
// On Unix, open non-blocking so a FIFO with no writer does not hang the
334345
// open() call indefinitely; the regular-file check below then rejects it.
335346
// O_NONBLOCK has no effect on the subsequent read of a regular file.

0 commit comments

Comments
 (0)