Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#######################
.vscode/
/target
# Not needed in a library.
Cargo.lock

# Compiled source #
###################
Expand Down Expand Up @@ -39,4 +41,4 @@ bundle
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Thumbs.db
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.6] - 2026-01-05
### Security
- Redact password from debug prints

## [0.3.1] - 2021-08-15
### Fixed
- CI workflows issues due to missing conditional publishing triggerer and out of
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ about behavior to being permanently banned from the http-auth-basic repository.

Not all interactions that require remediation are clear violations
of the Code of Conduct. Project maintainers will take appropriate
action, when neccessary, to ensure the http-auth-basic community is a space
action, when necessary, to ensure the http-auth-basic community is a space
where individuals can comfortably collaborate and bring their
entire selves. Unfortunately, if bringing your entire self is
infringing on others from doing the same, you may be asked to leave.
Expand Down
16 changes: 0 additions & 16 deletions Cargo.lock

This file was deleted.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "http-auth-basic"
version = "0.3.5"
version = "0.3.6"
authors = ["Esteban Borai <estebanborai@gmail.com>"]

edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
description = "HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications"
description = "HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compliant, base64-encoded credentials) for Rust applications"
readme = "README.md"
repository = "https://github.com/EstebanBorai/http-auth-basic"
categories = ["authentication", "encoding", "web-programming", "web-programming::http-server", "web-programming::http-client"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<h1 align="center">http-auth-basic</h1>
<h4 align="center">
HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications
HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compliant, base64-encoded credentials) for Rust applications
</h4>
</div>

Expand Down
16 changes: 13 additions & 3 deletions src/credentials.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::str::FromStr;
use std::{fmt, str::FromStr};

use base64::{prelude::BASE64_STANDARD, Engine};
use base64::{Engine, prelude::BASE64_STANDARD};

use crate::error::AuthBasicError;

/// A `struct` to represent the `user_id` and `password` fields
/// from an _Authorization Basic_ header value
#[derive(Debug, PartialEq)]
#[derive(PartialEq)]
pub struct Credentials {
pub user_id: String,
pub password: String,
Expand Down Expand Up @@ -102,3 +102,13 @@ impl FromStr for Credentials {
Self::decode(s.into())
}
}

/// Debug implementation never prints out the password.
impl fmt::Debug for Credentials {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Credentials")
.field("user_id", &self.user_id)
.field("password", &"REDACTED")
.finish()
}
}
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,22 @@ mod tests {

assert!(credentials.is_err());
}

#[test]
fn debug_redacts_password() {
let password = "secret teapot";
let credentials = Credentials::new("username", password);

let debugged = format!("{credentials:?}");
let pretty = format!("{credentials:#?}");

// The password should not appear in the prints.
assert!(!debugged.contains(password));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a check for REDACTED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it out intentionally so as not to be flaky wrt. changes in the text, but ya I can add it. Just means that the test will need to be updated if someone wants to change the text.

assert!(!pretty.contains(password));

// It should be replaced with this:
const REDACTED: &str = "REDACTED";
assert!(debugged.contains(REDACTED));
assert!(pretty.contains(REDACTED));
}
}
Loading