-
Notifications
You must be signed in to change notification settings - Fork 238
Support allowed domains parameter #3912
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
Changes from all commits
e85d080
17c7bb5
57e8612
05f05ca
c502b83
ade85ef
50e75af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |||||||
| #include "src/port/rapidjson_stringbuffer.hpp" | ||||||||
| #include "src/port/rapidjson_writer.hpp" | ||||||||
| #include <set> | ||||||||
| #include <string.h> | ||||||||
|
|
||||||||
| #include "openai_json_response.hpp" | ||||||||
|
|
||||||||
|
|
@@ -100,7 +101,6 @@ static size_t appendChunkCallback(void* downloadedChunk, size_t size, size_t nme | |||||||
| if (status == CURLE_OK) { \ | ||||||||
| status = setopt; \ | ||||||||
| } | ||||||||
|
|
||||||||
| static absl::Status downloadImage(const char* url, std::string& image, const int64_t& sizeLimit) { | ||||||||
| CURL* curl_handle = curl_easy_init(); | ||||||||
| if (!curl_handle) { | ||||||||
|
|
@@ -113,7 +113,11 @@ static absl::Status downloadImage(const char* url, std::string& image, const int | |||||||
| CURL_SETOPT(curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, appendChunkCallback)) | ||||||||
| CURL_SETOPT(curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &image)) | ||||||||
| CURL_SETOPT(curl_easy_setopt(curl_handle, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA)) | ||||||||
| CURL_SETOPT(curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L)) | ||||||||
| const char* envAllowRedirects = std::getenv("OVMS_MEDIA_URL_ALLOW_REDIRECTS"); | ||||||||
| if (envAllowRedirects != nullptr && (std::strcmp(envAllowRedirects, "1") == 0)) { | ||||||||
| SPDLOG_LOGGER_TRACE(llm_calculator_logger, "URL redirects allowed"); | ||||||||
| CURL_SETOPT(curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L)) | ||||||||
| } | ||||||||
| CURL_SETOPT(curl_easy_setopt(curl_handle, CURLOPT_MAXFILESIZE, sizeLimit)) | ||||||||
|
|
||||||||
| if (status != CURLE_OK) { | ||||||||
|
|
@@ -131,6 +135,37 @@ static absl::Status downloadImage(const char* url, std::string& image, const int | |||||||
| return absl::OkStatus(); | ||||||||
| } | ||||||||
|
|
||||||||
| static bool isDomainAllowed(const std::vector<std::string>& allowedDomains, const char* url) { | ||||||||
| if (allowedDomains.size() == 1 && allowedDomains[0] == "all") { | ||||||||
| return true; | ||||||||
| } | ||||||||
| CURLUcode rc; | ||||||||
| CURLU* parsedUrl = curl_url(); | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure it's a valid pointer at this point? |
||||||||
| rc = curl_url_set(parsedUrl, CURLUPART_URL, url, 0); | ||||||||
| if (rc) { | ||||||||
| SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Parsing url {} failed", url); | ||||||||
| curl_url_cleanup(parsedUrl); | ||||||||
| return false; | ||||||||
| } | ||||||||
| char* host; | ||||||||
| rc = curl_url_get(parsedUrl, CURLUPART_HOST, &host, 0); | ||||||||
| if (rc) { | ||||||||
| SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Parsing url {} hostname failed", url); | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leak, missing |
||||||||
| curl_url_cleanup(parsedUrl); | ||||||||
| return false; | ||||||||
| } | ||||||||
| bool allowed = false; | ||||||||
| for (const auto& allowedDomain : allowedDomains) { | ||||||||
| if (allowedDomain.compare(host) == 0) { | ||||||||
| allowed = true; | ||||||||
|
||||||||
| allowed = true; | |
| allowed = true; | |
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OVMS_API_VERSION_MINOR?