oox/source/core/xmlfilterbase.cxx | 43 +++++++++++++++----- sw/CppunitTest_sw_ooxmlexport21.mk | 4 + sw/qa/extras/ooxmlexport/data/personalmetadata.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport21.cxx | 39 ++++++++++++++++++ 4 files changed, 77 insertions(+), 9 deletions(-)
New commits: commit 1e49f469afcbf3d1abec25451117f5f10d3ba825 Author: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> AuthorDate: Mon Jan 29 11:25:17 2024 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Mon Jan 29 13:18:04 2024 +0100 Don't export personal metadata to OOXML in privacy mode Change-Id: Iac0985783a0c7334bd6ee3cfcaf37c135ac452ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162682 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 2e7ce9a75cbc..7afb84cad2c6 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -33,6 +33,7 @@ #include <o3tl/any.hxx> #include <unotools/mediadescriptor.hxx> #include <unotools/docinfohelper.hxx> +#include <unotools/securityoptions.hxx> #include <sax/fshelper.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> @@ -622,6 +623,12 @@ writeElement( const FSHelperPtr& pDoc, sal_Int32 nXmlElement, const LanguageTag& static void writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties >& xProperties ) { + bool bRemovePersonalInfo + = SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo); + bool bRemoveUserInfo + = bRemovePersonalInfo + && !SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo); + OUString sValue; if( rSelf.getVersion() == oox::core::ISOIEC_29500_2008 ) { @@ -670,8 +677,11 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties if (it->second >>= aValue) writeElement( pCoreProps, FSNS( XML_cp, XML_contentType ), aValue ); } - writeElement( pCoreProps, FSNS( XML_dcterms, XML_created ), xProperties->getCreationDate() ); - writeElement( pCoreProps, FSNS( XML_dc, XML_creator ), xProperties->getAuthor() ); + if (!bRemoveUserInfo) + { + writeElement(pCoreProps, FSNS(XML_dcterms, XML_created), xProperties->getCreationDate()); + writeElement(pCoreProps, FSNS(XML_dc, XML_creator), xProperties->getAuthor()); + } writeElement( pCoreProps, FSNS( XML_dc, XML_description ), xProperties->getDescription() ); it = aUserDefinedProperties.find("OOXMLCorePropertyIdentifier"); @@ -683,10 +693,18 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties } writeElement( pCoreProps, FSNS( XML_cp, XML_keywords ), xProperties->getKeywords() ); writeElement( pCoreProps, FSNS( XML_dc, XML_language ), LanguageTag( xProperties->getLanguage()) ); - writeElement( pCoreProps, FSNS( XML_cp, XML_lastModifiedBy ), xProperties->getModifiedBy() ); - writeElement( pCoreProps, FSNS( XML_cp, XML_lastPrinted ), xProperties->getPrintDate() ); - writeElement( pCoreProps, FSNS( XML_dcterms, XML_modified ), xProperties->getModificationDate() ); - writeElement( pCoreProps, FSNS( XML_cp, XML_revision ), xProperties->getEditingCycles() ); + + if (!bRemoveUserInfo) + { + writeElement(pCoreProps, FSNS(XML_cp, XML_lastModifiedBy), xProperties->getModifiedBy()); + writeElement(pCoreProps, FSNS(XML_cp, XML_lastPrinted), xProperties->getPrintDate()); + writeElement(pCoreProps, FSNS(XML_dcterms, XML_modified), + xProperties->getModificationDate()); + } + if (!bRemovePersonalInfo) + { + writeElement(pCoreProps, FSNS(XML_cp, XML_revision), xProperties->getEditingCycles()); + } writeElement( pCoreProps, FSNS( XML_dc, XML_subject ), xProperties->getSubject() ); writeElement( pCoreProps, FSNS( XML_dc, XML_title ), xProperties->getTitle() ); @@ -706,6 +724,11 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties static void writeAppProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties >& xProperties ) { + bool bRemovePersonalInfo + = SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo); + bool bRemoveUserInfo + = bRemovePersonalInfo + && !SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo); rSelf.addRelation( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", u"docProps/app.xml" ); @@ -720,7 +743,8 @@ writeAppProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties > comphelper::SequenceAsHashMap aUserDefinedProperties(xUserDefinedProperties->getPropertyValues()); comphelper::SequenceAsHashMap::iterator it; - writeElement( pAppProps, XML_Template, xProperties->getTemplateName() ); + if (!bRemovePersonalInfo) + writeElement(pAppProps, XML_Template, xProperties->getTemplateName()); it = aUserDefinedProperties.find("Manager"); if (it != aUserDefinedProperties.end()) @@ -737,7 +761,8 @@ writeAppProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties > writeElement( pAppProps, XML_Notes, "notes" ); #endif /* def OOXTODO */ // EditingDuration is in seconds, TotalTime is in minutes. - writeElement( pAppProps, XML_TotalTime, xProperties->getEditingDuration() / 60 ); + if (!bRemovePersonalInfo) + writeElement(pAppProps, XML_TotalTime, xProperties->getEditingDuration() / 60); #ifdef OOXTODO writeElement( pAppProps, XML_HiddenSlides, "hidden slides" ); writeElement( pAppProps, XML_MMClips, "mm clips" ); @@ -815,7 +840,7 @@ writeAppProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties > } it = aUserDefinedProperties.find("Company"); - if (it != aUserDefinedProperties.end()) + if (it != aUserDefinedProperties.end() && !bRemoveUserInfo) { OUString aValue; if (it->second >>= aValue) diff --git a/sw/CppunitTest_sw_ooxmlexport21.mk b/sw/CppunitTest_sw_ooxmlexport21.mk index 999314b9c6c4..ba3d2c441f17 100644 --- a/sw/CppunitTest_sw_ooxmlexport21.mk +++ b/sw/CppunitTest_sw_ooxmlexport21.mk @@ -11,4 +11,8 @@ $(eval $(call sw_ooxmlexport_test,21)) +$(eval $(call gb_CppunitTest_use_custom_headers,sw_ooxmlexport21,\ + officecfg/registry \ +)) + # vim: set noet sw=4 ts=4: diff --git a/sw/qa/extras/ooxmlexport/data/personalmetadata.docx b/sw/qa/extras/ooxmlexport/data/personalmetadata.docx new file mode 100644 index 000000000000..704b339c5843 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/personalmetadata.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx index c912046c0bb7..cb008645adaf 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -15,6 +15,9 @@ #include <com/sun/star/style/LineSpacing.hpp> #include <com/sun/star/style/LineSpacingMode.hpp> +#include <comphelper/configuration.hxx> +#include <officecfg/Office/Common.hxx> + #include <pam.hxx> #include <unotxdoc.hxx> #include <docsh.hxx> @@ -70,6 +73,42 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf159207_footerFramePrBorder) // TODO: there SHOULD BE a top border, and even if loaded, it would be lost on re-import... } +CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData) +{ + // 1. Remove all personal info + auto pBatch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true, pBatch); + pBatch->commit(); + loadAndSave("personalmetadata.docx"); + + xmlDocUniquePtr pAppDoc = parseExport("docProps/app.xml"); + assertXPath(pAppDoc, "/extended-properties:Properties/extended-properties:Template"_ostr, 0); + assertXPath(pAppDoc, "/extended-properties:Properties/extended-properties:TotalTime"_ostr, 0); + xmlDocUniquePtr pCoreDoc = parseExport("docProps/core.xml"); + assertXPath(pCoreDoc, "/cp:coreProperties/dcterms:created"_ostr, 0); + assertXPath(pCoreDoc, "/cp:coreProperties/dcterms:modified"_ostr, 0); + assertXPath(pCoreDoc, "/cp:coreProperties/dc:creator"_ostr, 0); + assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastModifiedBy"_ostr, 0); + assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastPrinted"_ostr, 0); + assertXPath(pCoreDoc, "/cp:coreProperties/cp:revision"_ostr, 0); + + // 2. Remove personal information, keep user information + officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(true, pBatch); + pBatch->commit(); + loadAndSave("personalmetadata.docx"); + + pAppDoc = parseExport("docProps/app.xml"); + assertXPath(pAppDoc, "/extended-properties:Properties/extended-properties:Template"_ostr, 0); + assertXPath(pAppDoc, "/extended-properties:Properties/extended-properties:TotalTime"_ostr, 0); + pCoreDoc = parseExport("docProps/core.xml"); + assertXPath(pCoreDoc, "/cp:coreProperties/dcterms:created"_ostr, 1); + assertXPath(pCoreDoc, "/cp:coreProperties/dcterms:modified"_ostr, 1); + assertXPath(pCoreDoc, "/cp:coreProperties/dc:creator"_ostr, 1); + assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastModifiedBy"_ostr, 1); + assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastPrinted"_ostr, 1); + assertXPath(pCoreDoc, "/cp:coreProperties/cp:revision"_ostr, 0); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT();