include/sfx2/lokhelper.hxx | 3 +++ sc/source/filter/html/htmlpars.cxx | 10 ++++++++++ sfx2/source/view/lokhelper.cxx | 17 +++++++++++++++++ sw/source/filter/html/htmlgrin.cxx | 6 ++++++ 4 files changed, 36 insertions(+)
New commits: commit 0f8ef44c919a59755a5b8cb2f9bd95b4ad538f82 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Mon Dec 4 18:36:29 2023 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Thu Jan 11 09:09:17 2024 +0100 lok: send error on access denied in image import - when we paste HTML with references to external images and host filter is configured then we have empty graphics - inform client about that so we can show an error to the user Change-Id: I7d584c256d8d004955c970056341ab42864d1dd3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160319 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161773 Tested-by: Jenkins diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index dc144503b8dd..338dda192b8c 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -226,6 +226,9 @@ public: static VclPtr<vcl::Window> getInPlaceDocWindow(SfxViewShell* pViewShell); + /// Sends Network Access error to LOK + static void sendNetworkAccessError(); + static void notifyLog(const std::ostringstream& stream); private: diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index f5f890081592..10d31fc84cd4 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -20,6 +20,7 @@ #include <memory> #include <sal/config.h> +#include <comphelper/lok.hxx> #include <comphelper/string.hxx> #include <scitems.hxx> @@ -37,6 +38,7 @@ #include <editeng/justifyitem.hxx> #include <sal/log.hxx> #include <sfx2/objsh.hxx> +#include <sfx2/lokhelper.hxx> #include <svl/numformat.hxx> #include <svl/intitem.hxx> #include <utility> @@ -47,6 +49,7 @@ #include <vcl/outdev.hxx> #include <vcl/svapp.hxx> +#include <tools/hostfilter.hxx> #include <tools/urlobj.hxx> #include <osl/diagnose.h> #include <o3tl/string_view.hxx> @@ -1318,6 +1321,13 @@ void ScHTMLLayoutParser::Image( HtmlImportInfo* pInfo ) return ; } + if (comphelper::LibreOfficeKit::isActive()) + { + INetURLObject aURL(pImage->aURL); + if (HostFilter::isForbidden(aURL.GetHost())) + SfxLokHelper::sendNetworkAccessError(); + } + sal_uInt16 nFormat; std::optional<Graphic> oGraphic(std::in_place); GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 4bebd7d1dc50..7cfe51426bce 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -37,6 +37,7 @@ #include <comphelper/lok.hxx> #include <sfx2/msgpool.hxx> #include <comphelper/scopeguard.hxx> +#include <tools/json_writer.hxx> #include <boost/property_tree/json_parser.hpp> @@ -1077,4 +1078,20 @@ VclPtr<vcl::Window> SfxLokHelper::getInPlaceDocWindow(SfxViewShell* pViewShell) return {}; } +void SfxLokHelper::sendNetworkAccessError() +{ + tools::JsonWriter aWriter; + aWriter.put("code", static_cast<sal_uInt32>( + ErrCode(ErrCodeArea::Inet, sal_uInt16(ErrCodeClass::Access)))); + aWriter.put("kind", "network"); + aWriter.put("cmd", "paste"); + + SfxViewShell* pViewShell = SfxViewShell::Current(); + if (pViewShell) + { + pViewShell->libreOfficeKitViewCallback( + LOK_CALLBACK_ERROR, aWriter.finishAndGetAsOString()); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 2b30c167bfe0..8304fa3002f3 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -19,6 +19,7 @@ #include <memory> #include <hintids.hxx> +#include <comphelper/lok.hxx> #include <comphelper/string.hxx> #include <comphelper/documentinfo.hxx> #include <vcl/svapp.hxx> @@ -34,6 +35,7 @@ #include <editeng/langitem.hxx> #include <sfx2/docfile.hxx> #include <sfx2/event.hxx> +#include <sfx2/lokhelper.hxx> #include <vcl/imap.hxx> #include <svtools/htmltokn.h> #include <svtools/htmlkywd.hxx> @@ -69,6 +71,7 @@ #include <vcl/graphicfilter.hxx> #include <tools/UnitConversion.hxx> +#include <tools/hostfilter.hxx> #include <tools/urlobj.hxx> #include <unotools/securityoptions.hxx> @@ -509,6 +512,9 @@ IMAGE_SETEVENT: } else if (m_sBaseURL.isEmpty() || !aGraphicData.isEmpty()) { + if (comphelper::LibreOfficeKit::isActive() && HostFilter::isForbidden(aGraphicURL.GetHost())) + SfxLokHelper::sendNetworkAccessError(); + // sBaseURL is empty if the source is clipboard // aGraphicData is non-empty for <object data="..."> -> not a linked graphic. if (ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aGraphicURL))