Skip to content

Commit d7a3e74

Browse files
committed
feat(http/plugins): add allowInsecureTls
1 parent c156a1e commit d7a3e74

5 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/net/http_client.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ void HttpClient::request(HttpRequest req, ResponseCallback cb) {
310310
curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1L);
311311
curl_easy_setopt(easy, CURLOPT_TIMEOUT, 30L);
312312
curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT, 10L);
313+
if (req.allowInsecureTls) {
314+
curl_easy_setopt(easy, CURLOPT_SSL_VERIFYPEER, 0L);
315+
curl_easy_setopt(easy, CURLOPT_SSL_VERIFYHOST, 0L);
316+
}
313317
if (req.followRedirects) {
314318
curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
315319
if (req.allowRedirectAuth) {
@@ -393,6 +397,10 @@ HttpClient::StreamId HttpClient::startStream(HttpRequest req, StreamDataCallback
393397
curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1L);
394398
// No CURLOPT_TIMEOUT: the transfer is expected to stay open indefinitely.
395399
curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT, 10L);
400+
if (req.allowInsecureTls) {
401+
curl_easy_setopt(easy, CURLOPT_SSL_VERIFYPEER, 0L);
402+
curl_easy_setopt(easy, CURLOPT_SSL_VERIFYHOST, 0L);
403+
}
396404
if (req.followRedirects) {
397405
curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
398406
if (req.allowRedirectAuth) {

src/net/http_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct HttpRequest {
1919
std::string body; // sent as the request body when non-empty
2020
bool followRedirects = false;
2121
bool allowRedirectAuth = false; // continue auth across redirect hosts; use only for trusted provider redirects
22+
bool allowInsecureTls = false; // disable origin certificate and hostname verification; use only for trusted hosts
2223
bool freshConnection = false; // bypass curl's connection cache; needed when the route may have changed
2324
// (e.g. probing the external IP after a VPN toggle), otherwise a reused
2425
// keep-alive connection answers via the old path

src/scripting/luau_host.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ namespace {
924924
request.basicUsername = reqStringField(L, tableIdx, "basic_username");
925925
request.basicPassword = reqStringField(L, tableIdx, "basic_password");
926926
request.followRedirects = reqBoolField(L, tableIdx, "follow_redirects", false);
927+
request.allowInsecureTls = reqBoolField(L, tableIdx, "allow_insecure_tls", false);
927928
lua_getfield(L, tableIdx, "headers");
928929
if (lua_istable(L, -1)) {
929930
const int headersIdx = lua_gettop(L);

src/scripting/plugin_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace scripting {
66

77
inline constexpr std::uint32_t kOldestSupportedPluginApiVersion = 3;
88
inline constexpr std::uint32_t kStringMapSettingPluginApiVersion = 6;
9-
inline constexpr std::uint32_t kCurrentPluginApiVersion = kStringMapSettingPluginApiVersion;
9+
inline constexpr std::uint32_t kAllowInsecureTlsPluginApiVersion = 7;
10+
inline constexpr std::uint32_t kCurrentPluginApiVersion = kAllowInsecureTlsPluginApiVersion;
1011

1112
static_assert(kOldestSupportedPluginApiVersion <= kCurrentPluginApiVersion);
1213

tests/plugin_manifest_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ int main() {
5959
ok = expect(scripting::supportsPluginApiVersion(4), "plugin API 4 should be supported") && ok;
6060
ok = expect(scripting::supportsPluginApiVersion(5), "plugin API 5 should be supported") && ok;
6161
ok = expect(scripting::supportsPluginApiVersion(6), "plugin API 6 should be supported") && ok;
62-
ok = expect(!scripting::supportsPluginApiVersion(7), "plugin API 7 should be too new") && ok;
62+
ok = expect(scripting::supportsPluginApiVersion(7), "plugin API 7 should be supported") && ok;
63+
ok = expect(!scripting::supportsPluginApiVersion(8), "plugin API 8 should be too new") && ok;
6364
const auto defaultManifestPath = root / "defaults/plugin.toml";
6465
ok = writeText(defaultManifestPath, "id = \"me/defaults\"\nname = \"Defaults\"\nplugin_api = 3\n") && ok;
6566

0 commit comments

Comments
 (0)