Kaydet (Commit) 33f7485d authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Properly encode OAuth2 credentials

Change-Id: Ic3edeae035262309e91fb01e3aca5c2f905bc3e5
Reviewed-on: https://gerrit.libreoffice.org/59986
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 7e7a1ff3
...@@ -22,6 +22,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,libcmis, \ ...@@ -22,6 +22,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,libcmis, \
external/libcmis/libcmis-fix-error-handling.patch \ external/libcmis/libcmis-fix-error-handling.patch \
external/libcmis/c++17.patch.0 \ external/libcmis/c++17.patch.0 \
external/libcmis/boost-1.68.patch.0 \ external/libcmis/boost-1.68.patch.0 \
external/libcmis/xwwwformurlencoded.patch.0 \
)) ))
ifeq ($(OS),WNT) ifeq ($(OS),WNT)
......
--- src/libcmis/oauth2-providers.cxx
+++ src/libcmis/oauth2-providers.cxx
@@ -26,6 +26,8 @@
* instead of those above.
*/
+#include <cassert>
+
#include <libxml/HTMLparser.h>
#include <libxml/xmlreader.h>
@@ -45,6 +47,29 @@
#define HTML_PARSE_RECOVER 0
#endif
+namespace {
+
+// See <https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer>:
+void addXWwwFormUrlencoded(std::string * buffer, std::string const & data) {
+ assert(buffer);
+ for (string::const_iterator i = data.begin(); i != data.end(); ++i) {
+ unsigned char c = static_cast<unsigned char>(*i);
+ if (c == ' ' || c == '*' || c == '-' || c == '.' || (c >= '0' && c <= '9')
+ || (c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z'))
+ {
+ *buffer += static_cast<char>(c);
+ } else {
+ static const char hex[16] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+ *buffer += '%';
+ *buffer += hex[c >> 4];
+ *buffer += hex[c & 0xF];
+ }
+ }
+}
+
+}
+
string OAuth2Providers::OAuth2Gdrive( HttpSession* session, const string& authUrl,
const string& username, const string& password )
{
@@ -97,7 +120,7 @@
return string( );
loginEmailPost += "Email=";
- loginEmailPost += string( username );
+ addXWwwFormUrlencoded(&loginEmailPost, username);
istringstream loginEmailIs( loginEmailPost );
string loginEmailRes;
@@ -119,7 +142,7 @@
return string( );
loginPasswdPost += "Passwd=";
- loginPasswdPost += string( password );
+ addXWwwFormUrlencoded(&loginPasswdPost, password);
istringstream loginPasswdIs( loginPasswdPost );
string loginPasswdRes;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment