Skip to content

Commit

Permalink
Merge pull request #1067 from jagerman/secure-auth-construction
Browse files Browse the repository at this point in the history
Fix sensitive data leaking in Authentication
  • Loading branch information
COM8 authored Jul 29, 2024
2 parents 79a8a56 + cb7f4bf commit 57e263d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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, NEGOTIATE };

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

0 comments on commit 57e263d

Please sign in to comment.