From 58fa1292e8be8853e13386d1aff2091aa00a167d Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Wed, 31 May 2023 09:23:38 +1000 Subject: [PATCH] fix: unquote quoted URL's to avoid libcurl errors This commit will unquote URL's allowing them to be supported by libcurl and eliminate any errors when a valid (quoted) URL is supplied by a user. Closes #2579 Signed-off-by: Daniel Wright danielwright@bitgo.com --- userspace/falco/outputs_http.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/userspace/falco/outputs_http.cpp b/userspace/falco/outputs_http.cpp index f33082e9cce..d0a32434c19 100644 --- a/userspace/falco/outputs_http.cpp +++ b/userspace/falco/outputs_http.cpp @@ -38,9 +38,18 @@ void falco::outputs::output_http::output(const message *msg) if(res == CURLE_OK) { - res = curl_easy_setopt(curl, CURLOPT_URL, m_oc.options["url"].c_str()); + // if the URL is quoted the quotes should be removed to satisfy libcurl expected format + std::string unquotedUrl = m_oc.options["url"]; + if (!unquotedUrl.empty() && ( + (unquotedUrl.front() == '\"' && unquotedUrl.back() == '\"') || + (unquotedUrl.front() == '\'' && unquotedUrl.back() == '\'') + )) + { + unquotedUrl = libsinsp::filter::unescape_str(unquotedUrl); + } + res = curl_easy_setopt(curl, CURLOPT_URL, unquotedUrl.c_str()); } - + if(res == CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg->msg.c_str()); @@ -55,7 +64,7 @@ void falco::outputs::output_http::output(const message *msg) { res = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1L); } - + if(res == CURLE_OK) { if(m_oc.options["insecure"] == std::string("true")) @@ -81,7 +90,7 @@ void falco::outputs::output_http::output(const message *msg) res = curl_easy_setopt(curl, CURLOPT_CAPATH, m_oc.options["ca_path"].c_str()); } } - + if(res == CURLE_OK) { res = curl_easy_perform(curl);