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

Fix sensitive data leaking in Authentication #1067

Merged
merged 2 commits into from
Jul 29, 2024
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
10 changes: 10 additions & 0 deletions cpr/auth.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include "cpr/auth.h"
#include "cpr/util.h"

#include <string_view>

namespace cpr {

Authentication::Authentication(std::string_view username, std::string_view password, AuthMode auth_mode) : auth_mode_{auth_mode} {
auth_string_.reserve(username.size() + 1 + password.size());
auth_string_ += username;
auth_string_ += ':';
auth_string_ += password;
}

Authentication::~Authentication() noexcept {
util::secureStringClear(auth_string_);
}
Expand Down
7 changes: 2 additions & 5 deletions include/cpr/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@
#define CPR_AUTH_H

#include <string>

#include <utility>
#include <string_view>

namespace cpr {

enum class AuthMode { BASIC, DIGEST, NTLM };

class Authentication {
public:
Authentication(std::string username, std::string password, AuthMode auth_mode) : auth_string_{std::move(username) + ":" + std::move(password)}, auth_mode_{std::move(auth_mode)} {}
Authentication(std::string_view username, std::string_view password, AuthMode auth_mode);
Authentication(const Authentication& other) = default;
Authentication(Authentication&& old) noexcept = default;
~Authentication() noexcept;

Authentication& operator=(Authentication&& old) noexcept = default;
Authentication& operator=(const Authentication& other) = default;

const char* GetAuthString() const noexcept;
Expand Down
Loading