Skip to content

Commit 8c64cfb

Browse files
committed
fix: redact plaintext token in APT setup stderr output
The APT setup command previously printed the full authentication token to stderr when showing the config preview and manual instructions. Tokens longer than 8 characters are now displayed as first4...last4. Closes #80
1 parent a0b2476 commit 8c64cfb

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/commands/setup/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ fn write_config_file(path: &Path, content: &str, description: &str) -> Result<()
310310
Ok(())
311311
}
312312

313+
fn redact_token(content: &str, token: &str) -> String {
314+
if token.len() > 8 {
315+
content.replace(
316+
token,
317+
&format!("{}...{}", &token[..4], &token[token.len() - 4..]),
318+
)
319+
} else {
320+
content.replace(token, "****")
321+
}
322+
}
323+
313324
fn confirm_write(path: &Path, content: &str, no_input: bool) -> Result<bool> {
314325
eprintln!("\nConfiguration to write to {}:\n", path.display());
315326
eprintln!("{content}");
@@ -821,9 +832,11 @@ async fn setup_apt(repo: Option<&str>, global: &GlobalArgs) -> Result<()> {
821832
));
822833
let auth_path = PathBuf::from("/etc/apt/auth.conf.d/artifact-keeper.conf");
823834

835+
let redacted_auth = redact_token(&auth_content, &ctx.token);
836+
824837
eprintln!("This requires writing to /etc/apt/ (needs sudo).");
825838
eprintln!("\nSources list:\n{sources_content}");
826-
eprintln!("Auth config:\n{auth_content}");
839+
eprintln!("Auth config:\n{redacted_auth}");
827840

828841
if global.no_input {
829842
eprintln!("Run the following commands manually:");
@@ -835,7 +848,7 @@ async fn setup_apt(repo: Option<&str>, global: &GlobalArgs) -> Result<()> {
835848
eprintln!(
836849
" sudo tee {} <<'EOF'\n{}EOF",
837850
auth_path.display(),
838-
auth_content
851+
redacted_auth
839852
);
840853
return Ok(());
841854
}

0 commit comments

Comments
 (0)