Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore new sensitive string implementation #754

Closed
wants to merge 11 commits into from
Closed

Conversation

Hinton
Copy link
Member

@Hinton Hinton commented Apr 30, 2024

Type of change

- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Code changes

  • file.ext: Description of what was changed and why

Before you submit

  • Please add unit tests where it makes sense to do so

Copy link
Contributor

github-actions bot commented Apr 30, 2024

Logo
Checkmarx One – Scan Summary & Details13ba31be-09c9-444d-9ed0-021b007e4eb1

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Unpinned Actions Full Length Commit SHA /version-bump.yml: 52 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli.yml: 339 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...

Fixed Issues

Severity Issue Source File / Package
MEDIUM Unpinned Actions Full Length Commit SHA /version-bump.yml: 54
MEDIUM Unpinned Actions Full Length Commit SHA /release-cpp.yml: 61
MEDIUM Unpinned Actions Full Length Commit SHA /release-cpp.yml: 67
MEDIUM Unpinned Actions Full Length Commit SHA /publish-java.yml: 60
MEDIUM Unpinned Actions Full Length Commit SHA /build-cli.yml: 341

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 88.71595% with 29 lines in your changes are missing coverage. Please review.

Project coverage is 59.05%. Comparing base (27cdb63) to head (258d53a).
Report is 11 commits behind head on main.

Files Patch % Lines
crates/bitwarden-crypto/src/sensitive/string.rs 93.90% 10 Missing ⚠️
crates/bitwarden/src/platform/fido2/client.rs 0.00% 4 Missing ⚠️
crates/bitwarden-crypto/src/uniffi_support.rs 0.00% 2 Missing ⚠️
...ates/bitwarden/src/platform/fido2/authenticator.rs 0.00% 2 Missing ⚠️
crates/bw/src/auth/login.rs 0.00% 2 Missing ⚠️
crates/bitwarden/src/auth/login/password.rs 0.00% 1 Missing ⚠️
crates/bitwarden/src/auth/login/two_factor.rs 0.00% 1 Missing ⚠️
crates/bitwarden/src/auth/register.rs 0.00% 1 Missing ⚠️
crates/bitwarden/src/platform/get_user_api_key.rs 0.00% 1 Missing ⚠️
...n/src/secrets_manager/projects/project_response.rs 0.00% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #754      +/-   ##
==========================================
+ Coverage   58.72%   59.05%   +0.32%     
==========================================
  Files         177      179       +2     
  Lines       11501    11620     +119     
==========================================
+ Hits         6754     6862     +108     
- Misses       4747     4758      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@MGibson1 MGibson1 left a comment

Choose a reason for hiding this comment

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

A few notes on the new SensitiveString

Comment on lines 42 to 44
/// Extend the size of the string by `size`.
///
/// Internally creates a new string with the new size and copies the old string into it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Extend the size of the string by `size`.
///
/// Internally creates a new string with the new size and copies the old string into it.
/// Extend the size of the string by `size`.
///
/// Internally creates a new string with the new size and copies the old string into it, zeroing the original.

}

/// Extends the capacity of the string to `size` if it is larger than the current capacity.
pub fn extend_spec(&mut self, size: usize) {
Copy link
Member

Choose a reason for hiding this comment

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

should be internal?

/// Extend the size of the string by `size`.
///
/// Internally creates a new string with the new size and copies the old string into it.
pub fn extend_size(&mut self, size: usize) {
Copy link
Member

Choose a reason for hiding this comment

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

What happens if size < self.inner.len()?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should have been inner.len() + size) 🤦

Copy link
Member

Choose a reason for hiding this comment

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

A bunch of references to BitString, but I think the newer name of SensitiveString is better

Comment on lines +80 to +87
pub fn as_str(&self) -> &str {
&self.inner
}

/// Expose the inner value as a byte slice.
///
/// Warning: Taking ownership of the inner value will create a copy of the string.
pub fn as_bytes(&self) -> &[u8] {
Copy link
Member

Choose a reason for hiding this comment

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

I think as long as these methods are public, it'll be really hard to identify potential leaks. I realize there are operations we need to do, but the goal should be containing those as much as possible.

The only thing I can think of right now that might be clearer is rather than allowing a method to expose the zeroized data, using something like a visitor pattern. We could more easily identify through linting rules implementers of an ExposeSensitiveData trait and develop means of understanding the level of exposure through macros that write fuzzing tests for us.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, unfortunately we do need direct access to the str and bytes in many scenarios. But as you said we need to be careful with how they are used since taking ownership of them means you need to care about zeroing it out.

I was leaning towards moving them into a separate trait so that we have more fine grained control of the usage, but I think ultimately we will have to rely on reviewers to be vigilant when using that trait.

Hinton added 3 commits May 6, 2024 11:44
# Conflicts:
#	crates/memory-testing/src/lib.rs
#	crates/memory-testing/src/main.rs
@@ -310,7 +310,7 @@
name: require!(send.name).parse()?,
notes: EncString::try_from_optional(send.notes)?,
key: require!(send.key).parse()?,
password: send.password.map(|p| SensitiveString::new(Box::new(p))),
password: send.password.map(|p| SensitiveString::new(p)),

Check failure

Code scanning / clippy

redundant closure Error

redundant closure
@Hinton
Copy link
Member Author

Hinton commented May 24, 2024

Abandoned since we decided to use an allocator instead.

@Hinton Hinton closed this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants