First cut at annotating 'exotic' filters.

The idea being that we can improve security by warning for these.

Change-Id: I7d993417bfb6a8fe868bc3e07ccbcfe71bf285ff
Reviewed-on: https://gerrit.libreoffice.org/50387
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
This commit is contained in:
Michael Meeks 2015-02-25 15:07:19 +00:00 committed by Andras Timar
parent 2937661f0e
commit 25e4b59b2e
27 changed files with 235 additions and 14 deletions

View File

@ -121,6 +121,7 @@
#define FLAGNAME_TEMPLATEPATH "TEMPLATEPATH"
#define FLAGNAME_COMBINED "COMBINED"
#define FLAGNAME_SUPPORTSSIGNING "SUPPORTSSIGNING"
#define FLAGNAME_EXOTIC "EXOTIC"
/** @short some uno service names.
*/

View File

@ -1843,6 +1843,7 @@ css::uno::Sequence< OUString > FilterCache::impl_convertFlagField2FlagNames(SfxF
if (nFlags & SfxFilterFlags::COMBINED ) lFlagNames.emplace_back(FLAGNAME_COMBINED );
if (nFlags & SfxFilterFlags::SUPPORTSSIGNING) lFlagNames.emplace_back(FLAGNAME_SUPPORTSSIGNING);
if (nFlags & SfxFilterFlags::GPGENCRYPTION) lFlagNames.emplace_back(FLAGNAME_GPGENCRYPTION);
if (nFlags & SfxFilterFlags::EXOTIC) lFlagNames.emplace_back(FLAGNAME_EXOTIC);
return comphelper::containerToSequence(lFlagNames);
}
@ -1883,6 +1884,11 @@ SfxFilterFlags FilterCache::impl_convertFlagNames2FlagField(const css::uno::Sequ
nField |= SfxFilterFlags::ENCRYPTION;
continue;
}
if (pNames[i] == FLAGNAME_EXOTIC)
{
nField |= SfxFilterFlags::EXOTIC;
continue;
}
if (pNames[i] == FLAGNAME_EXPORT)
{
nField |= SfxFilterFlags::EXPORT;

View File

@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="AbiWord" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER</value></prop>
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER EXOTIC</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"><value>com.sun.star.comp.Writer.AbiWordImportFilter</value></prop>
<prop oor:name="UserData"><value>ABW</value></prop>

View File

@ -9,7 +9,7 @@
<node oor:name="MWAW_Bitmap" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
</prop>
<prop oor:name="FilterService">
<value>com.sun.star.comp.Draw.MWAWDrawImportFilter</value>

View File

@ -9,7 +9,7 @@
<node oor:name="MWAW_Database" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
</prop>
<prop oor:name="FilterService">
<value>com.sun.star.comp.Calc.MWAWCalcImportFilter</value>

View File

@ -9,7 +9,7 @@
<node oor:name="MWAW_Drawing" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
</prop>
<prop oor:name="FilterService">
<value>com.sun.star.comp.Draw.MWAWDrawImportFilter</value>

View File

@ -9,7 +9,7 @@
<node oor:name="MWAW_Presentation" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
</prop>
<prop oor:name="FilterService">
<value>com.sun.star.comp.Impress.MWAWPresentationImportFilter</value>

View File

@ -9,7 +9,7 @@
<node oor:name="MWAW_Spreadsheet" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
</prop>
<prop oor:name="FilterService">
<value>com.sun.star.comp.Calc.MWAWCalcImportFilter</value>

View File

@ -9,7 +9,7 @@
<node oor:name="MWAW_Text_Document" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
</prop>
<prop oor:name="FilterService">
<value>com.sun.star.comp.Writer.MWAWImportFilter</value>

View File

@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="StarOffice XML (Base)" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT OWN DEFAULT 3RDPARTYFILTER ENCRYPTION</value></prop>
<prop oor:name="Flags"><value>IMPORT OWN DEFAULT 3RDPARTYFILTER ENCRYPTION EXOTIC</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"/>
<prop oor:name="UserData"/>

View File

@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="StarOffice XML (Writer)" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT TEMPLATE OWN ALIEN PREFERRED ENCRYPTION</value></prop>
<prop oor:name="Flags"><value>IMPORT TEMPLATE OWN ALIEN PREFERRED ENCRYPTION EXOTIC</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"/>
<prop oor:name="UserData"><value>CXML</value></prop>

View File

@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="T602Document" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop>
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"><value>com.sun.star.comp.Writer.T602ImportFilter</value></prop>
<prop oor:name="UserData"><value>602</value></prop>

View File

@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="XPM" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT ALIEN</value></prop>
<prop oor:name="Flags"><value>IMPORT ALIEN EXOTIC</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"/>
<prop oor:name="UserData"><value></value></prop>

View File

@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="writer_MIZI_Hwp_97" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER</value></prop>
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER EXOTIC</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"><value>com.sun.comp.hwpimport.HwpImportFilter</value></prop>
<prop oor:name="UserData"><value></value></prop>

View File

@ -83,6 +83,7 @@
// Preferred - preferred filter for a particular type
// 3rdPartyFilter - implemented as a UNO component
// Default - default filter for this document type
// Exotic - an unusual/legacy file-format, we don't normally see
//
// (The 3rdPartyFilter flag is here called StarONE)
//
@ -106,6 +107,7 @@ enum class SfxFilterFlags
CONSULTSERVICE = 0x00040000L,
STARONEFILTER = 0x00080000L,
PACKED = 0x00100000L,
EXOTIC = 0x00200000L,
COMBINED = 0x00800000L,
ENCRYPTION = 0x01000000L,
@ -118,7 +120,7 @@ enum class SfxFilterFlags
namespace o3tl
{
template<> struct typed_flags<SfxFilterFlags> : is_typed_flags<SfxFilterFlags, 0x779f157fL> {};
template<> struct typed_flags<SfxFilterFlags> : is_typed_flags<SfxFilterFlags, 0x77bf157fL> {};
}
#define SFX_FILTER_NOTINSTALLED (SfxFilterFlags::MUSTINSTALL | SfxFilterFlags::CONSULTSERVICE)

View File

@ -82,7 +82,10 @@ public:
bool GetSupportsSigning() const { return bool(nFormatType & SfxFilterFlags::SUPPORTSSIGNING); }
bool GetGpgEncryption() const { return bool(nFormatType & SfxFilterFlags::GPGENCRYPTION); }
bool IsOwnTemplateFormat() const { return bool(nFormatType & SfxFilterFlags::TEMPLATEPATH); }
/// not our built-in format
bool IsAlienFormat() const { return bool(nFormatType & SfxFilterFlags::ALIEN); }
/// an unusual/legacy file to be loading
bool IsExoticFormat() const { return bool(nFormatType & SfxFilterFlags::EXOTIC); }
bool CanImport() const { return bool(nFormatType & SfxFilterFlags::IMPORT); }
bool CanExport() const { return bool(nFormatType & SfxFilterFlags::EXPORT); }
SfxFilterFlags GetFilterFlags() const { return nFormatType; }

View File

@ -745,6 +745,9 @@ public:
SAL_DLLPRIVATE void ImplSign( bool bScriptingContent = false );
SAL_DLLPRIVATE bool QuerySaveSizeExceededModules_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler );
SAL_DLLPRIVATE bool QueryAllowExoticFormat_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
const OUString& rURL,
const OUString& rFilterUIName);
SAL_DLLPRIVATE void CheckOut( );
SAL_DLLPRIVATE void CancelCheckOut( );

View File

@ -2191,6 +2191,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/document,\
DocumentEvent \
EmptyUndoStackException \
EventObject \
ExoticFileLoadException \
FilterOptionsRequest \
LinkUpdateModes \
LockFileCorruptRequest \

View File

@ -0,0 +1,34 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef __com_sun_star_document_ExoticFileLoadException_idl__
#define __com_sun_star_document_ExoticFileLoadException_idl__
#include <com/sun/star/uno/Exception.idl>
module com { module sun { module star { module document {
/** An exception used to notify loading of an exotic file format
@since LibreOffice 6.1
*/
exception ExoticFileLoadException : ::com::sun::star::uno::Exception
{
/** contains the URL of the document
*/
string URL;
/** contains the UI name of the filter
*/
string FilterUIName;
};
}; }; }; };
#endif

View File

@ -2438,6 +2438,29 @@
<info>
<desc>Contains security specific Office settings.</desc>
</info>
<prop oor:name="LoadExoticFileFormats" oor:type="xs:int" oor:nillable="false">
<info>
<desc>Determines how exotic file formats should be handled.</desc>
</info>
<constraints>
<enumeration oor:value="0">
<info>
<desc>Refuse loading without question</desc>
</info>
</enumeration>
<enumeration oor:value="1">
<info>
<desc>Display a warning and let the user decide</desc>
</info>
</enumeration>
<enumeration oor:value="2">
<info>
<desc>Always load without question</desc>
</info>
</enumeration>
</constraints>
<value>2</value>
</prop>
<prop oor:name="EnableExpertConfiguration" oor:type="xs:boolean" oor:nillable="false">
<info>
<desc>Determines if the user has access to the entire

View File

@ -214,6 +214,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/doc/doctempl \
sfx2/source/doc/doctemplates \
sfx2/source/doc/doctemplateslocal \
sfx2/source/doc/exoticfileloadexception \
sfx2/source/doc/frmdescr \
sfx2/source/doc/graphhelp \
sfx2/source/doc/guisaveas \

View File

@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "exoticfileloadexception.hxx"
#include <comphelper/interaction.hxx>
#include <com/sun/star/document/ExoticFileLoadException.hpp>
using namespace com::sun::star;
ExoticFileLoadException::ExoticFileLoadException(const OUString& rURL,
const OUString& rFilterUIName)
{
document::ExoticFileLoadException aReq;
aReq.URL = rURL;
aReq.FilterUIName = rFilterUIName;
m_aRequest <<= aReq;
m_xAbort.set(uno::Reference<task::XInteractionAbort>(new comphelper::OInteractionAbort),
uno::UNO_QUERY);
m_xApprove.set(uno::Reference<task::XInteractionApprove>(new comphelper::OInteractionApprove),
uno::UNO_QUERY);
m_lContinuations.realloc(2);
m_lContinuations[0] = m_xApprove;
m_lContinuations[1] = m_xAbort;
}
bool ExoticFileLoadException::isApprove() const
{
comphelper::OInteractionApprove* pBase
= static_cast<comphelper::OInteractionApprove*>(m_xApprove.get());
return pBase->wasSelected();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SFX2_EXOTICFILELOADEXCEPTION_HXX
#define INCLUDED_SFX2_EXOTICFILELOADEXCEPTION_HXX
#include <com/sun/star/task/XInteractionHandler.hpp>
#include <cppuhelper/implbase.hxx>
class ExoticFileLoadException : public cppu::WeakImplHelper<css::task::XInteractionRequest>
{
// C++ interface
public:
ExoticFileLoadException(const OUString& rURL, const OUString& rFilterUIName);
bool isApprove() const;
// UNO interface
public:
virtual css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>>
SAL_CALL getContinuations() override
{
return m_lContinuations;
}
css::uno::Any SAL_CALL getRequest() override { return m_aRequest; }
// member
private:
css::uno::Any m_aRequest;
css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>> m_lContinuations;
css::uno::Reference<css::task::XInteractionContinuation> m_xAbort;
css::uno::Reference<css::task::XInteractionContinuation> m_xApprove;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -81,6 +81,7 @@
#include <unotools/saveopt.hxx>
#include <unotools/useroptions.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/securityoptions.hxx>
#include <tools/urlobj.hxx>
#include <tools/diagnose_ex.h>
#include <unotools/ucbhelper.hxx>
@ -130,6 +131,7 @@
#include <appbaslib.hxx>
#include <appdata.hxx>
#include "objstor.hxx"
#include "exoticfileloadexception.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::container;
@ -651,6 +653,11 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed )
SetError( ERRCODE_IO_FILTERDISABLED );
}
if ( pFilter && pFilter->IsExoticFormat() && !QueryAllowExoticFormat_Impl( getInteractionHandler(), aBaseURL, pMed->GetFilter()->GetUIName() ) )
{
SetError( ERRCODE_IO_ABORT );
}
// initialize static language table so language-related extensions are learned before the document loads
(void)SvtLanguageTable::GetLanguageEntryCount();
@ -3557,7 +3564,35 @@ bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< ta
return true;
}
// comphelper::IEmbeddedHelper
bool SfxObjectShell::QueryAllowExoticFormat_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const OUString& rURL, const OUString& rFilterUIName )
{
if ( SvtSecurityOptions().isTrustedLocationUri( rURL ) )
{
// Always load from trusted location
return true;
}
if ( officecfg::Office::Common::Security::LoadExoticFileFormats::get() == 0 )
{
// Refuse loading without question
return false;
}
else if ( officecfg::Office::Common::Security::LoadExoticFileFormats::get() == 2 )
{
// Always load without question
return true;
}
else if ( officecfg::Office::Common::Security::LoadExoticFileFormats::get() == 1 && xHandler.is() )
{
// Display a warning and let the user decide
rtl::Reference<ExoticFileLoadException> xException(new ExoticFileLoadException( rURL, rFilterUIName ));
uno::Reference< task::XInteractionRequest > xReq( xException.get() );
xHandler->handle( xReq );
return xException.get()->isApprove();
}
// No interaction handler, default is to continue to load
return true;
}
uno::Reference< task::XInteractionHandler > SfxObjectShell::getInteractionHandler() const
{
uno::Reference< task::XInteractionHandler > xRet;

View File

@ -34,6 +34,8 @@ const std::pair<const char*, ErrCode> RID_UUI_ERRHDL[] =
ERRCODE_UUI_IO_TARGETALREADYEXISTS },
{ NC_("RID_UUI_ERRHDL", "You are about to save/export a password protected basic library containing module(s) \n$(ARG1)\nwhich are too large to store in binary format. If you wish users that don't have access to the library password to be able to run macros in those module(s) you must split those modules into a number of smaller modules. Do you wish to continue to save/export this library?"),
ERRCODE_UUI_IO_MODULESIZEEXCEEDED },
{ NC_("RID_UUI_ERRHDL", "Beware!\n\nYou are about to load a very unusual sort of file ($(ARG2)) from the URL:\n\n$(ARG1)\n\nAre you certain that this file is a legacy document created many years ago?"),
ERRCODE_UUI_IO_EXOTICFILEFORMAT },
{ NC_("RID_UUI_ERRHDL", "The data from $(ARG1) has an incorrect checksum."),
ERRCODE_UUI_IO_BADCRC },
{ NC_("RID_UUI_ERRHDL", "The object $(ARG1) cannot be created in directory $(ARG2)."),

View File

@ -86,6 +86,7 @@
#define ERRCODE_UUI_LOCKING_NOT_LOCKED ErrCode(ErrCodeArea::Uui, 61)
#define ERRCODE_UUI_LOCKING_LOCK_EXPIRED ErrCode(ErrCodeArea::Uui, 62)
#define ERRCODE_UUI_CANNOT_ACTIVATE_FACTORY ErrCode(ErrCodeArea::Uui, 63)
#define ERRCODE_UUI_IO_EXOTICFILEFORMAT ErrCode(ErrCodeArea::Uui, 64)
#endif

View File

@ -26,6 +26,7 @@
#include <com/sun/star/configuration/backend/StratumCreationException.hpp>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/document/BrokenPackageRequest.hpp>
#include <com/sun/star/document/ExoticFileLoadException.hpp>
#include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
#include <com/sun/star/java/WrongJavaVersionException.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
@ -434,6 +435,30 @@ UUIInteractionHelper::handleRequest_impl(
return true;
}
document::ExoticFileLoadException aExoticFileLoadException;
if (aAnyRequest >>= aExoticFileLoadException)
{
std::vector< OUString > aArguments;
if( !aExoticFileLoadException.URL.isEmpty() )
{
aArguments.push_back( aExoticFileLoadException.URL );
}
if( !aExoticFileLoadException.FilterUIName.isEmpty() )
{
aArguments.push_back( aExoticFileLoadException.FilterUIName );
}
handleErrorHandlerRequest( task::InteractionClassification_WARNING,
ERRCODE_UUI_IO_EXOTICFILEFORMAT,
aArguments,
rRequest->getContinuations(),
bObtainErrorStringOnly,
bHasErrorString,
rErrorString);
return true;
}
ucb::NameClashException aNCException;
if (aAnyRequest >>= aNCException)
{