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 64624d225c71229acce4f889d4863d7c29c52658 Author: Szymon Kłos <[email protected]> AuthorDate: Mon Dec 4 18:36:29 2023 +0100 Commit: Szymon Kłos <[email protected]> CommitDate: Thu Dec 7 14:58:33 2023 +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 <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 6df7e0cdc341..24a508859fa1 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 c2414d858802..d0d00a9ecc29 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 8ace83445ae0..0d3843632f13 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -34,6 +34,7 @@ #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> #include <sfx2/msgpool.hxx> +#include <tools/json_writer.hxx> #include <boost/property_tree/json_parser.hpp> @@ -1067,4 +1068,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.extractAsStdString().c_str()); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 840a80962293..1967b93c1ea3 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> @@ -68,6 +70,7 @@ #include <frameformats.hxx> #include <vcl/graphicfilter.hxx> +#include <tools/hostfilter.hxx> #include <tools/urlobj.hxx> #include <unotools/securityoptions.hxx> @@ -508,6 +511,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))
