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

rgw ldap: protect rgw::from_base64 from non-base64 input #10777

Merged
merged 1 commit into from Aug 18, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rgw/rgw_rest_s3.h
Expand Up @@ -710,7 +710,12 @@ class RGWLDAPAuthEngine: RGWS3V2AuthEngine
store(store),
apl_factory(apl_factory) {
init(cct);
base64_token = rgw::from_base64(access_key_id);
/* boost filters and/or string_ref may throw on invalid input */
try {
base64_token = rgw::from_base64(access_key_id);
} catch(...) {
base64_token = std::string("");
Copy link
Contributor

Choose a reason for hiding this comment

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

base64_token is already in its default-constructed state, is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It feels cleaner to re-assert it in an empty state, at least to me.

}
}
const char* get_name() const noexcept override {
return "RGWLDAPAuthEngine";
Expand Down
28 changes: 28 additions & 0 deletions src/test/test_rgw_token.cc
Expand Up @@ -43,6 +43,9 @@ namespace {

std::string enc_ldap{"ewogICAgIlJHV19UT0tFTiI6IHsKICAgICAgICAidmVyc2lvbiI6IDEsCiAgICAgICAgInR5cGUiOiAibGRhcCIsCiAgICAgICAgImlkIjogIlNtb25ueSIsCiAgICAgICAgImtleSI6ICJUdXJqYW4gb2YgTWlpciIKICAgIH0KfQo="};

std::string non_base64{"stuff here"};
std::string non_base64_sploded{"90KLscc0Dz4U49HX-7Tx"};

Formatter* formatter{nullptr};
bool verbose {false};
}
Expand Down Expand Up @@ -71,6 +74,31 @@ TEST(TOKEN, DECODE) {
}
}

TEST(TOKEN, EMPTY) {
std::string empty{""};
RGWToken token{from_base64(empty)}; // decode ctor
ASSERT_FALSE(token.valid());
}

TEST(TOKEN, BADINPUT) {
RGWToken token{from_base64(non_base64)}; // decode ctor
ASSERT_FALSE(token.valid());
}

TEST(TOKEN, BADINPUT2) {
RGWToken token{from_base64(non_base64_sploded)}; // decode ctor
ASSERT_FALSE(token.valid());
}

TEST(TOKEN, BADINPUT3) {
try {
std::string stuff = from_base64(non_base64_sploded); // decode
} catch(...) {
// do nothing
}
ASSERT_EQ(1, 1);
}

TEST(TOKEN, SHUTDOWN) {
delete formatter;
}
Expand Down