Skip to content

Commit

Permalink
Merge pull request #103 from aws/validation_fixes
Browse files Browse the repository at this point in the history
Add more validation
  • Loading branch information
saikiranakula-amzn authored Jan 16, 2024
2 parents 0e89bd0 + 435aee8 commit d4ca16d
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions api/src/gmsa_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#define LEASE_ID_LENGTH 10
#define UNIX_SOCKET_NAME "credentials_fetcher.sock"
#define INPUT_CREDENTIALS_LENGTH 256
#define INPUT_CREDENTIALS_LENGTH 104

static const std::vector<char> invalid_characters = {
'&', '|', ';', '$', '*', '?', '<', '>', '!',' '};
Expand Down Expand Up @@ -359,7 +359,7 @@ class CredentialsFetcherImpl final
password = std::get<1>( userCreds );
domain = krb_ticket_info->domain_name;

if ( !contains_invalid_characters_in_credentials( domain ) )
if ( !contains_invalid_characters_in_credentials( domain ) && !contains_invalid_characters_in_credentials( username ))
{
if ( !username.empty() && !password.empty() && !domain.empty() &&
username.length() < INPUT_CREDENTIALS_LENGTH &&
Expand Down Expand Up @@ -402,7 +402,7 @@ class CredentialsFetcherImpl final
}
else
{
err_msg = "ERROR: invalid domainName";
err_msg = "ERROR: invalid domainName/username";
std::cout << getCurrentTime() << '\t' << err_msg
<< std::endl;
break;
Expand Down Expand Up @@ -723,7 +723,8 @@ class CredentialsFetcherImpl final
password = std::get<1>( userCreds );
domain = krb_ticket_info->domain_name;

if ( !contains_invalid_characters_in_credentials( domain ) )
if ( !contains_invalid_characters_in_credentials( domain
) && !contains_invalid_characters_in_credentials( username ) )
{
if ( !username.empty() && !password.empty() &&
!domain.empty() &&
Expand All @@ -744,7 +745,7 @@ class CredentialsFetcherImpl final
}
else
{
err_msg = "ERROR: invalid domainName";
err_msg = "ERROR: invalid domainName/username";
std::cout << getCurrentTime() << '\t' << err_msg
<< std::endl;
}
Expand Down Expand Up @@ -1209,7 +1210,8 @@ class CredentialsFetcherImpl final
std::string domain = create_domainless_krb_request_.domain();

std::string err_msg;
if(!contains_invalid_characters_in_credentials(domain))
if(!contains_invalid_characters_in_credentials(domain) &&
!contains_invalid_characters_in_credentials(username))
{
if ( !username.empty() && !password.empty() && !domain.empty() && username.length() < INPUT_CREDENTIALS_LENGTH && password.length() <
INPUT_CREDENTIALS_LENGTH )
Expand Down Expand Up @@ -1511,7 +1513,8 @@ class CredentialsFetcherImpl final
std::string domain = renew_domainless_krb_request_.domain();

std::string err_msg;
if(!contains_invalid_characters_in_credentials(domain))
if(!contains_invalid_characters_in_credentials(domain) &&
!contains_invalid_characters_in_credentials(username))
{
if ( !username.empty() && !password.empty() && !domain.empty() && username.length() < INPUT_CREDENTIALS_LENGTH && password.length() <
INPUT_CREDENTIALS_LENGTH )
Expand Down Expand Up @@ -2007,6 +2010,15 @@ int parse_cred_spec( std::string credspec_data, creds_fetcher::krb_ticket_info*
if (service_account_name.empty() || domain_name.empty())
return -1;

if(contains_invalid_characters_in_credentials(domain_name) ||
contains_invalid_characters_in_credentials(service_account_name))
{
std::cout << getCurrentTime() << '\t' << "ERROR: credentialspec file is not formatted"
" properly" <<
std::endl;
return -1;
}

krb_ticket_info->domain_name = domain_name;
krb_ticket_info->service_account_name = service_account_name;
}
Expand Down Expand Up @@ -2058,6 +2070,15 @@ int parse_cred_spec_domainless( std::string credspec_data, creds_fetcher::krb_ti
if (service_account_name.empty() || domain_name.empty())
return -1;

if(contains_invalid_characters_in_credentials(domain_name) ||
contains_invalid_characters_in_credentials(service_account_name))
{
std::cout << getCurrentTime() << '\t' << "ERROR: credentialspec file is not formatted"
" properly" <<
std::endl;
return -1;
}

krb_ticket_info->domain_name = domain_name;
krb_ticket_info->service_account_name = service_account_name;
krb_ticket_info->credspec_info = krb_ticket_mapping->credential_spec_arn;
Expand Down

0 comments on commit d4ca16d

Please sign in to comment.