Skip to content

Commit

Permalink
Fix URL validation issue in request_data_handler (#93)
Browse files Browse the repository at this point in the history
* Fix URL validation issue in request_data_handler

* trigger rebuild

* trigger rebuild
  • Loading branch information
royshil committed May 15, 2024
1 parent ab17af0 commit 17e1319
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/request-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,6 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
response.status_code = URL_SOURCE_REQUEST_STANDARD_ERROR_CODE;
return response;
}
// validate the url
if (!hasOnlyValidURLCharacters(request_data->url)) {
obs_log(LOG_INFO, "URL is invalid");
// Return an error response
response.error_message = "URL is invalid";
response.status_code = URL_SOURCE_REQUEST_STANDARD_ERROR_CODE;
return response;
}

// Build the request with libcurl
CURL *curl = curl_easy_init();
Expand All @@ -218,7 +210,6 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
response.status_code = URL_SOURCE_REQUEST_STANDARD_ERROR_CODE;
return response;
}
curl_easy_setopt(curl, CURLOPT_URL, request_data->url.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str());
if (request_data->fail_on_http_error) {
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
Expand Down Expand Up @@ -386,10 +377,17 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
}
response.request_url = url;

if (request_data->url != url) { // If the url was changed
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// validate the url
if (!hasOnlyValidURLCharacters(url)) {
obs_log(LOG_INFO, "URL '%s' is invalid", url.c_str());
// Return an error response
response.error_message = "URL is invalid";
response.status_code = URL_SOURCE_REQUEST_STANDARD_ERROR_CODE;
return response;
}

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

// this is needed here, out of the `if` scope below
std::string request_body_allocated;

Expand Down

0 comments on commit 17e1319

Please sign in to comment.