minio-cpp icon indicating copy to clipboard operation
minio-cpp copied to clipboard

The GetPresignedObjectUrl() function has an error and does not return the correct value.

Open bboy-hui opened this issue 10 months ago • 4 comments

The expected signature generation is incomplete.

bboy-hui avatar Apr 07 '24 06:04 bboy-hui

Duplicate of https://github.com/minio/minio-cpp/issues/110

balamurugana avatar Apr 07 '24 11:04 balamurugana

You can use an example to test it; the returned URL is incomplete. The function utils::Multimap PresignV4(http::Method method, the std::string& host, the std::string& uri, the std::string& region, utils::Multimap query_params, the std::string& access_key, the std::string& secret_key, the utils::UtcTime& date, unsigned int expires) is erroneous.

bboy-hui avatar Apr 07 '24 12:04 bboy-hui

Found the bug. query_params needs to be passed by reference into PreSignV4, otherwise the query params are lost with the stack frame when it returns.

diff --git a/include/miniocpp/signer.h b/include/miniocpp/signer.h
index b8c912b..670a93d 100644
--- a/include/miniocpp/signer.h
+++ b/include/miniocpp/signer.h
@@ -69,7 +69,7 @@ utils::Multimap SignV4STS(http::Method method, const std::string& uri,
                           const utils::UtcTime& date);
 utils::Multimap PresignV4(http::Method method, const std::string& host,
                           const std::string& uri, const std::string& region,
-                          utils::Multimap query_params,
+                          utils::Multimap& query_params,
                           const std::string& access_key,
                           const std::string& secret_key,
                           const utils::UtcTime& date, unsigned int expires);
diff --git a/src/signer.cc b/src/signer.cc
index c3ffb59..067f6b0 100644
--- a/src/signer.cc
+++ b/src/signer.cc
@@ -165,7 +165,7 @@ utils::Multimap SignV4STS(http::Method method, const std::string& uri,
 
 utils::Multimap PresignV4(http::Method method, const std::string& host,
                           const std::string& uri, const std::string& region,
-                          utils::Multimap query_params,
+                          utils::Multimap& query_params,
                           const std::string& access_key,
                           const std::string& secret_key,
                           const utils::UtcTime& date, unsigned int expires) {

ijoseph avatar Apr 13 '24 02:04 ijoseph

Before the above fix, we just get a bare URL with no query params whatsoever.

ijoseph avatar Apr 13 '24 02:04 ijoseph