Is there an enviornment variable or command line option to disiable the "This document containts macros." warning dialog?

Distro: ubuntu 20.04

tldr: loading .doc files with macros in headless mode waits for us to click the “OK” on the “This document contains macros.” dialog. Is there a way to disable this?

Hi I work for a transcription service.

We’re running libreoffice in headless mode on a server so we can get the document statistics. eg: word count, line count etc.

Recently our server was upgraded from ubuntu 18.04 to 20.04.

We’re using python to connect to the libreoffice and do the magic.

With some testing I’ve discovered that we’re having an issue with files that have macros in them. The “This document contains macros” dialog is showing up and blocking all input.

Through some testing & greppery I’ve discovered that the setting appears to be located in.

registrymodifications.xcu:<item oor:path="/org.openoffice.Office.Common/Security/Scripting"><prop oor:name="MacroSecurityLevel" oor:op="fuse"><value>3</value></prop></item>

If I set that value to 0 it doesn’t show the dialog anymore. This however creates a huge security risk because we’re executing all macros because that setting is Low (not recommended) I’d prefer not to allow for this attack vector.

After running import pdb; pbd.set_trace() to see if I could access the “This document containts macros.” warning dialog and click through it.

As soon as my code hits:document = writer.desktop.loadComponentFromURL(path_uri, "_blank", 0, ())

The dialog appears and all input from the pdb stops being processed - it’s blocked a blocking dialog.

Here’s my testcase:

import sys

sys.path.append("/usr/lib/libreoffice/program")
sys.path.append("/usr/lib/python3/dist-packages")

import os
import uno

from unotools import Socket, connect, parse_argument
from unotools.component.writer import Writer
from time import sleep

def get_libreoffice_context():
    args = parse_argument(['-s', 'localhost'])
    cnt = 0
    while cnt < 10:
        cnt += 1
        res = None
        try:
            res = connect(Socket(args.host, args.port), option=args.option)
        except Exception as e:
            print("Error:{}".format(e))
            sleep(1)
        if res:
            break
    return res

def open_doc_in_libreoffice(path_and_file):
    context = get_libreoffice_context()
    writer = Writer(context)
    # By default libreoffice opens a new document.  This closes it.
    writer.close(True)
    import pdb; pdb.set_trace()
    realpath = os.path.realpath(path_and_file)
    print("opening:%s" % realpath)
    basename = os.path.basename(realpath)
    # Converts path to something like file:///path/to/file/file.doc
    path_uri = uno.systemPathToFileUrl(realpath)
    print("path_uri:%s" % path_uri)
    # This loads the file
    print("*** ABOUT TO TRY ***")
    document = writer.desktop.loadComponentFromURL(path_uri, "_blank", 0, ())
    print("*** MADE IT PAST ***") # never shows up dialog blocks.

    return context, writer, document

if __name__ == "__main__":
    open_doc_in_libreoffice("./problem-file-1.doc")

Even doing running chmod -w problem-file-1.doc
At this point I’m not able to do anything because of the blocking dialog. Any help would be appreciated.

Perhaps Chapter 5.8.5.How do I Enable Macros With LoadComponentFromURL will give you a good idea or this list of constants.