Skip to content

Commit 1d237ed

Browse files
committed
fix(auth): propagate errors when token directory creation/permissions fail
Previously, failures to create the token directory or set its permissions were silently ignored using 'let _ = ...'. This could lead to confusing errors later or security issues if permissions were left insecure. Now properly propagates errors from: - tokio::fs::create_dir_all() - std::fs::set_permissions() (on Unix) Also sanitizes the path in error messages to prevent terminal escape sequence injection, aligned with codebase security practices.
1 parent e9970db commit 1d237ed

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gws": patch
3+
---
4+
5+
Fix auth error propagation: properly propagate errors when token directory creation or permission setting fails, instead of silently ignoring them

src/token_storage.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,24 @@ impl EncryptedTokenStorage {
8282
let encrypted = crate::credential_store::encrypt(json.as_bytes())?;
8383

8484
if let Some(parent) = self.file_path.parent() {
85-
let _ = tokio::fs::create_dir_all(parent).await;
85+
tokio::fs::create_dir_all(parent).await.map_err(|e| {
86+
anyhow::anyhow!(
87+
"Failed to create token directory '{}': {}",
88+
sanitize_for_terminal(&parent.display().to_string()),
89+
e
90+
)
91+
})?;
8692
#[cfg(unix)]
8793
{
8894
use std::os::unix::fs::PermissionsExt;
89-
let _ = std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700));
95+
std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700))
96+
.map_err(|e| {
97+
anyhow::anyhow!(
98+
"Failed to set permissions on token directory '{}': {}",
99+
sanitize_for_terminal(&parent.display().to_string()),
100+
e
101+
)
102+
})?;
90103
}
91104
}
92105

0 commit comments

Comments
 (0)