Bug 2573634

Summary: LanguageTool API connections bypass configured proxy
Product: [Fedora] Fedora Reporter: Jiri Belka <jirib79>
Component: libreofficeAssignee: libreoffice-sig
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 44CC: dtardon, erack, gwync, libreoffice-sig
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
URL: https://bugs.documentfoundation.org/show_bug.cgi?id=158352
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
0001-tdf-158352-LanguageTool-API-connections-bypass-configured-proxy.patch none

Description Jiri Belka 2026-11-15 10:19:25 UTC
Hi,
I submitted this upstream but I am submitting here for visibility and to get help/review from more skilled people - I created a diff with gemini-3.8-flash which works and solves the problem but my skills are not able to fully review it. So, a help would be appreciated.

I tested the diff:

1. system proxy (default):
   - no http proxy env vars: direct connection
   - http proxy env vars: using the proxy (as before)

2. manual proxy (explicit in LO setting):
   - no http proxy env vars: using the explicitly set proxy (fixes the issue)
   - http proxy env vars: using the explicitly set proxy (wins over env vars)

3. none proxy (in LO settigns):
   - no http proxy env vars: direct connection
   - http proxy env vars: direct connection

When using bad proxy port, the error is visible and clear.

I made gemini-3.8-flash to generated a RCA, see below:

---

### **Bug Summary**

LanguageTool API connections and TSA cryptography requests bypass proxy configured in LibreOffice preferences (tdf#158352)

---

### **Problem Description**

When an HTTP/HTTPS proxy is configured in LibreOffice preferences (`Tools` -> `Options` -> `Internet` -> `Proxy`, `org.openoffice.Inet/Settings`):

- LanguageTool grammar checker (`lingucomponent`) and Timestamp Authority (TSA) signing (`svl`) ignore the configured proxy and establish direct outbound connections to remote servers (e.g. `api.languagetool.org:443`).

- While standard environment variables (`http_proxy`/`https_proxy`) work out of the box via libcurl's default detection, LibreOffice's own internal proxy settings are completely bypassed.

---

### **Root Cause Analysis (RCA)**

1. **Unconfigured `CURLOPT_PROXY` on libcurl handles:**

   In `lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx` (`makeHttpRequest_impl`) and `svl/source/crypto/cryptosign.cxx` (`Signing::Sign`), curl handles are initialized without querying LibreOffice's `ucbhelper::InternetProxyDecider`. Because `CURLOPT_PROXY` is never set, LibreOffice's internal preferences (`ooInetProxyType`, `ooInetHTTP(S)ProxyName`, `ooInetHTTP(S)ProxyPort`, `ooInetNoProxy`) are ignored.

2. **Scheme delimiter trap in `ucbhelper::InternetProxyDecider`:**

   When integrating `InternetProxyDecider::getProxy(rProtocol, rHost, nPort)`:

   - Callers passing `INetURLObject::GetScheme()` pass the URL **prefix** with the delimiter (`u"https://"`).

   - `InternetProxyDecider_Impl::getProxy()` expects the clean protocol name (`rProtocol.toAsciiLowerCase() == "https"`).

   - Because `"https://"` does not match `"https"`, configured HTTPS proxy settings are missed. The clean protocol name must be obtained via `INetURLObject::GetSchemeName()` (`"https"` / `"http"`).

3. **Preserving existing environment variable behavior:**

   Under LibreOffice's default "System" proxy mode (`ooInetProxyType == 1`), `InternetProxyDecider` returns an empty string on Linux. Explicitly setting `CURLOPT_PROXY` to `""` tells libcurl to disable all proxying and **suppress** `http_proxy`/`https_proxy`. Therefore, under System proxy mode on Linux, `CURLOPT_PROXY` must be left unset so libcurl's working environment variable detection remains active.

---

### **Solution**

1. **In `lingucomponent`:** Add `ucbhelper` to `Library_LanguageTool.mk` and hold a `std::unique_ptr<ucbhelper::InternetProxyDecider>` in `LanguageToolGrammarChecker`.

2. **In `makeHttpRequest_impl` (and `cryptosign.cxx`):** Check `officecfg::Inet::Settings::ooInetProxyType`:

   - **`0` (None / Direct):** Set `CURLOPT_PROXY` to `""` (strictly enforces direct connection).

   - **`2` (Manual):** Query `pProxyDecider->getProxy(INetURLObject::GetSchemeName(aUrl.GetProtocol()), ...)`. If a proxy is returned, set `CURLOPT_PROXY` and `CURLOPT_PROXYAUTH`. If empty (host in "No proxy for" exclusion list), set `CURLOPT_PROXY` to `""`.

   - **`1` (System / Default):** On Linux/Unix, leave `CURLOPT_PROXY` unset to preserve libcurl's native `http_proxy`, `https_proxy`, and `no_proxy` environment variable handling.


Reproducible: Always

Steps to Reproduce:
1. 
When an HTTP/HTTPS proxy is configured in LibreOffice preferences (`Tools` -> `Options` -> `Internet` -> `Proxy`: set manual proxy
2. use a http proxy (eg. mitmproxy)
3. make use of LanguageTool in LO (it has to be enabled in settings)
Actual Results:
the manual proxy is bypassed

Expected Results:
should use the manually set proxy in LO settings

Additional Information:
the diff is made against libreoffice-26.2.7.3-1.fc44.src.rpm, I did rebuild the package locally and tested that.

---

diff --git a/lingucomponent/Library_LanguageTool.mk b/lingucomponent/Library_LanguageTool.mk
index aa09327cd..4f1ba58bb 100644
--- a/lingucomponent/Library_LanguageTool.mk
+++ b/lingucomponent/Library_LanguageTool.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_Library_use_libraries,LanguageTool,\
 	lng \
 	sal \
 	tl \
+	ucbhelper \
 	utl \
 ))
 
diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
index d8a9da3fd..0ceb936a4 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
@@ -34,6 +34,7 @@
 #include <set>
 #include <string.h>
 
+#include <officecfg/Inet.hxx>
 #include <officecfg/Office/Linguistic.hxx>
 
 #include <curl/curl.h>
@@ -47,6 +48,9 @@
 #include <sal/log.hxx>
 #include <tools/color.hxx>
 #include <tools/long.hxx>
+#include <tools/urlobj.hxx>
+#include <ucbhelper/proxydecider.hxx>
+#include <comphelper/processfactory.hxx>
 #include <framework/interaction.hxx>
 #include <com/sun/star/task/InteractionClassification.hpp>
 #include <com/sun/star/task/InteractionHandler.hpp>
@@ -126,7 +130,8 @@ enum class HTTP_METHOD
 
 std::string makeHttpRequest_impl(std::u16string_view aURL, HTTP_METHOD method,
                                  const OString& aPostData, curl_slist* pHttpHeader,
-                                 tools::Long& nStatusCode, CURLcode& eCURLCode)
+                                 tools::Long& nStatusCode, CURLcode& eCURLCode,
+                                 const ucbhelper::InternetProxyDecider* pProxyDecider)
 {
     struct curl_cleanup_t
     {
@@ -141,6 +146,55 @@ std::string makeHttpRequest_impl(std::u16string_view aURL, HTTP_METHOD method,
 
     ::InitCurl_easy(curl.get());
 
+    if (pProxyDecider)
+    {
+        sal_Int32 nProxyType = officecfg::Inet::Settings::ooInetProxyType::get().value_or(1);
+        if (nProxyType == 0) // None / Direct connection
+        {
+            (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY, "");
+        }
+        else if (nProxyType == 2) // Manual proxy configuration
+        {
+            INetURLObject aUrl(aURL);
+            sal_Int32 nPort = aUrl.GetPort();
+            if (nPort == 0)
+                nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443 : 80;
+            const OUString sProxy = pProxyDecider->getProxy(
+                INetURLObject::GetSchemeName(aUrl.GetProtocol()), aUrl.GetHost(), nPort);
+            if (!sProxy.isEmpty())
+            {
+                OString const utf8Proxy = OUStringToOString(sProxy, RTL_TEXTENCODING_UTF8);
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY, utf8Proxy.getStr());
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+            }
+            else
+            {
+                // Host is in LibreOffice's "No proxy for" exclusion list
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY, "");
+            }
+        }
+        else // nProxyType == 1: System proxy
+        {
+#ifdef _WIN32
+            INetURLObject aUrl(aURL);
+            sal_Int32 nPort = aUrl.GetPort();
+            if (nPort == 0)
+                nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443 : 80;
+            const OUString sProxy = pProxyDecider->getProxy(
+                INetURLObject::GetSchemeName(aUrl.GetProtocol()), aUrl.GetHost(), nPort);
+            if (!sProxy.isEmpty())
+            {
+                OString const utf8Proxy = OUStringToOString(sProxy, RTL_TEXTENCODING_UTF8);
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY, utf8Proxy.getStr());
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+            }
+#else
+            // On Linux/Unix, leave CURLOPT_PROXY unset so libcurl automatically
+            // handles http_proxy, https_proxy, all_proxy, and no_proxy env vars natively.
+#endif
+        }
+    }
+
     OString aURL8 = OUStringToOString(aURL, RTL_TEXTENCODING_UTF8);
     (void)curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, pHttpHeader);
     (void)curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L);
@@ -178,7 +232,8 @@ std::string makeHttpRequest_impl(std::u16string_view aURL, HTTP_METHOD method,
 }
 
 std::string makeDudenHttpRequest(std::u16string_view aURL, const OString& aPostData,
-                                 tools::Long& nStatusCode, CURLcode& eCURLCode)
+                                 tools::Long& nStatusCode, CURLcode& eCURLCode,
+                                 const ucbhelper::InternetProxyDecider* pProxyDecider)
 {
     struct curl_slist* pList = nullptr;
     OString sAccessToken
@@ -193,11 +248,12 @@ std::string makeDudenHttpRequest(std::u16string_view aURL, const OString& aPostD
     }
 
     return makeHttpRequest_impl(aURL, HTTP_METHOD::HTTP_POST, aPostData, pList, nStatusCode,
-                                eCURLCode);
+                                eCURLCode, pProxyDecider);
 }
 
 std::string makeHttpRequest(std::u16string_view aURL, HTTP_METHOD method, const OString& aPostData,
-                            tools::Long& nStatusCode, CURLcode& eCURLCode)
+                            tools::Long& nStatusCode, CURLcode& eCURLCode,
+                            const ucbhelper::InternetProxyDecider* pProxyDecider)
 {
     OString realPostData(aPostData);
     if (method == HTTP_METHOD::HTTP_POST)
@@ -209,7 +265,8 @@ std::string makeHttpRequest(std::u16string_view aURL, HTTP_METHOD method, const
             realPostData += "&username=" + encodeTextForLT(username) + "&apiKey=" + apiKey;
     }
 
-    return makeHttpRequest_impl(aURL, method, realPostData, nullptr, nStatusCode, eCURLCode);
+    return makeHttpRequest_impl(aURL, method, realPostData, nullptr, nStatusCode, eCURLCode,
+                                pProxyDecider);
 }
 
 template <typename Func>
@@ -364,8 +421,10 @@ void lclShowCURLErrorInteraction(const css::uno::Reference<css::uno::XComponentC
 LanguageToolGrammarChecker::LanguageToolGrammarChecker(
     const css::uno::Reference<css::uno::XComponentContext>& xContext)
     : mCachedResults(10)
-    , mxContext(xContext)
+    , mxContext(xContext.is() ? xContext : comphelper::getProcessComponentContext())
 {
+    if (mxContext.is())
+        m_xProxyDecider = std::make_unique<ucbhelper::InternetProxyDecider>(mxContext);
 }
 
 LanguageToolGrammarChecker::~LanguageToolGrammarChecker() {}
@@ -514,10 +573,11 @@ ProofreadingResult SAL_CALL LanguageToolGrammarChecker::doProofreading(
     std::string response_body;
     CURLcode eCURLCode = CURLE_OK;
     if (bDudenProtocol)
-        response_body = makeDudenHttpRequest(checkerURL, postData, http_code, eCURLCode);
+        response_body = makeDudenHttpRequest(checkerURL, postData, http_code, eCURLCode,
+                                             m_xProxyDecider.get());
     else
-        response_body
-            = makeHttpRequest(checkerURL, HTTP_METHOD::HTTP_POST, postData, http_code, eCURLCode);
+        response_body = makeHttpRequest(checkerURL, HTTP_METHOD::HTTP_POST, postData, http_code,
+                                        eCURLCode, m_xProxyDecider.get());
 
     if (eCURLCode != CURLE_OK)
     {
diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
index 487d6d154..66c49fe88 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
@@ -28,9 +28,15 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <linguistic/misc.hxx>
 #include <string_view>
+#include <memory>
 #include <o3tl/lru_map.hxx>
 #include <tools/long.hxx>
 
+namespace ucbhelper
+{
+class InternetProxyDecider;
+}
+
 class LanguageToolGrammarChecker
     : public cppu::WeakImplHelper<css::linguistic2::XProofreader, css::lang::XInitialization,
                                   css::lang::XServiceInfo, css::lang::XServiceDisplayName>
@@ -39,6 +45,7 @@ class LanguageToolGrammarChecker
     o3tl::lru_map<OString, css::uno::Sequence<css::linguistic2::SingleProofreadingError>>
         mCachedResults;
     css::uno::Reference<css::uno::XComponentContext> mxContext;
+    std::unique_ptr<ucbhelper::InternetProxyDecider> m_xProxyDecider;
     OUString maLastErrorCheckerURL;
     LanguageToolGrammarChecker(const LanguageToolGrammarChecker&) = delete;
     LanguageToolGrammarChecker& operator=(const LanguageToolGrammarChecker&) = delete;
diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx
index f9e23c54d..7ce772304 100644
--- a/svl/source/crypto/cryptosign.cxx
+++ b/svl/source/crypto/cryptosign.cxx
@@ -18,7 +18,10 @@
 #include <o3tl/numeric.hxx>
 
 #if USE_CRYPTO_NSS
+#include <officecfg/Inet.hxx>
 #include <systools/curlinit.hxx>
+#include <tools/urlobj.hxx>
+#include <ucbhelper/proxydecider.hxx>
 #endif
 
 #include <rtl/character.hxx>
@@ -1129,6 +1132,56 @@ bool Signing::Sign(OStringBuffer& rCMSHexBuffer)
 
         ::InitCurl_easy(curl);
 
+        {
+            sal_Int32 nProxyType = officecfg::Inet::Settings::ooInetProxyType::get().value_or(1);
+            if (nProxyType == 0) // None / Direct connection
+            {
+                curl_easy_setopt(curl, CURLOPT_PROXY, "");
+            }
+            else if (nProxyType == 2) // Manual proxy configuration
+            {
+                ucbhelper::InternetProxyDecider aProxyDecider(comphelper::getProcessComponentContext());
+                INetURLObject aUrl(m_aSignTSA);
+                sal_Int32 nPort = aUrl.GetPort();
+                if (nPort == 0)
+                    nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443 : 80;
+                const OUString sProxy = aProxyDecider.getProxy(
+                    INetURLObject::GetSchemeName(aUrl.GetProtocol()), aUrl.GetHost(), nPort);
+                if (!sProxy.isEmpty())
+                {
+                    OString const utf8Proxy = OUStringToOString(sProxy, RTL_TEXTENCODING_UTF8);
+                    curl_easy_setopt(curl, CURLOPT_PROXY, utf8Proxy.getStr());
+                    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+                }
+                else
+                {
+                    // Host is in LibreOffice's "No proxy for" exclusion list
+                    curl_easy_setopt(curl, CURLOPT_PROXY, "");
+                }
+            }
+            else // nProxyType == 1: System proxy
+            {
+#ifdef _WIN32
+                ucbhelper::InternetProxyDecider aProxyDecider(comphelper::getProcessComponentContext());
+                INetURLObject aUrl(m_aSignTSA);
+                sal_Int32 nPort = aUrl.GetPort();
+                if (nPort == 0)
+                    nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443 : 80;
+                const OUString sProxy = aProxyDecider.getProxy(
+                    INetURLObject::GetSchemeName(aUrl.GetProtocol()), aUrl.GetHost(), nPort);
+                if (!sProxy.isEmpty())
+                {
+                    OString const utf8Proxy = OUStringToOString(sProxy, RTL_TEXTENCODING_UTF8);
+                    curl_easy_setopt(curl, CURLOPT_PROXY, utf8Proxy.getStr());
+                    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+                }
+#else
+                // On Linux/Unix, leave CURLOPT_PROXY unset so libcurl automatically
+                // handles http_proxy, https_proxy, all_proxy, and no_proxy env vars natively.
+#endif
+            }
+        }
+
         SAL_INFO("svl.crypto", "Setting curl to verbose: " << (curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) == CURLE_OK ? "OK" : "FAIL"));
 
         if ((rc = curl_easy_setopt(curl, CURLOPT_URL, OUStringToOString(m_aSignTSA, RTL_TEXTENCODING_UTF8).getStr())) != CURLE_OK)

--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -402,6 +402,19 @@
             }
         }
 
+        void testSchemeNameVsScheme()
+        {
+            INetURLObject aHttpUrl(u"http://api.languagetool.org/v2/check");
+            CPPUNIT_ASSERT_EQUAL(INetProtocol::Http, aHttpUrl.GetProtocol());
+            CPPUNIT_ASSERT_EQUAL(u"http"_ustr, INetURLObject::GetSchemeName(aHttpUrl.GetProtocol()));
+            CPPUNIT_ASSERT_EQUAL(u"http://"_ustr, INetURLObject::GetScheme(aHttpUrl.GetProtocol()));
+
+            INetURLObject aHttpsUrl(u"https://api.languagetool.org/v2/check");
+            CPPUNIT_ASSERT_EQUAL(INetProtocol::Https, aHttpsUrl.GetProtocol());
+            CPPUNIT_ASSERT_EQUAL(u"https"_ustr, INetURLObject::GetSchemeName(aHttpsUrl.GetProtocol()));
+            CPPUNIT_ASSERT_EQUAL(u"https://"_ustr, INetURLObject::GetScheme(aHttpsUrl.GetProtocol()));
+        }
+
         // Change the following lines only, if you add, remove or rename
         // member functions of the current class,
         // because these macros are need by auto register mechanism.
@@ -420,6 +433,7 @@
         CPPUNIT_TEST( testTd146382 );
         CPPUNIT_TEST( testParseSmart );
         CPPUNIT_TEST( testIsExoticProtocol );
+        CPPUNIT_TEST( testSchemeNameVsScheme );
         CPPUNIT_TEST_SUITE_END(  );
     };                          // class createPool

Comment 1 Jiri Belka 2026-11-15 10:20:06 UTC
Created attachment 2163577 [details]
0001-tdf-158352-LanguageTool-API-connections-bypass-configured-proxy.patch

Comment 2 Jiri Belka 2026-11-15 12:22:26 UTC
BTW, this issue was found during an analysis of https://bugs.documentfoundation.org/show_bug.cgi?id=174490 .