Skip to content

Commit

Permalink
Force read-only mode for many unsupported legacy Office formats
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Dec 17, 2024
1 parent cd44b93 commit 7b60654
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/core/wopi.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def checkFileInfo(fileid, acctok):
# populate metadata for this file
fmd = {}
fmd['BaseFileName'] = fmd['BreadcrumbDocName'] = os.path.basename(acctok['filename'])
if acctok['viewmode'] in (utils.ViewMode.VIEW_ONLY, utils.ViewMode.READ_ONLY):
fmd['BreadcrumbDocName'] += ' (read only)'
fmd['FileExtension'] = os.path.splitext(acctok['filename'])[1]
wopiSrc = 'WOPISrc=%s&access_token=%s' % (utils.generateWopiSrc(fileid, acctok['appname'] == srv.proxiedappname),
flask.request.args['access_token'])
Expand Down
16 changes: 9 additions & 7 deletions src/core/wopiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ def generateAccessToken(userid, fileid, viewmode, user, folderurl, endpoint, app
log.info(f'msg="Requested file not found or not a file" fileid="{fileid}" error="{e}"')
raise
exptime = int(time.time()) + srv.config.getint('general', 'tokenvalidity')
fext = os.path.splitext(statinfo['filepath'])[1].lower()
if srv.config.get('general', 'disablemswriteodf', fallback='False').upper() == 'TRUE' and \
fext[1:3] in ('od', 'ot') and appname != 'Collabora' and viewmode == ViewMode.READ_WRITE:
# we're opening an ODF (`.o[d|t]?`) file and the app is not Collabora
log.info(f"msg=\"Forcing read-only access to ODF file\" filename=\"{statinfo['filepath']}\"")
fname = statinfo['filepath']
fext = os.path.splitext(fname)[1].lower()
if appname != 'Collabora' and viewmode == ViewMode.READ_WRITE and (
fext in ('.doc', '.dot', '.xls', '.ppt', '.pps', '.csv') or
fext[1:3] in ('od', 'ot') and srv.config.get('general', 'disablemswriteodf', fallback='False').upper() == 'TRUE'):
# we're opening a legacy format file or an ODF (`.o[d|t]?`) and the app is not Collabora
log.info(f"msg=\"Forcing read-only access to ODF/legacy formats\" filename=\"{fname}\"")
viewmode = ViewMode.READ_ONLY
if viewmode == ViewMode.PREVIEW and statinfo['size'] == 0:
# override preview mode when a new file is being created
Expand All @@ -239,7 +241,7 @@ def generateAccessToken(userid, fileid, viewmode, user, folderurl, endpoint, app
# and instead force preview mode for external or anonymous users
viewmode = ViewMode.PREVIEW
tokmd = {
'userid': userid, 'wopiuser': wopiuser, 'usertype': usertype.value, 'filename': statinfo['filepath'], 'fileid': fileid,
'userid': userid, 'wopiuser': wopiuser, 'usertype': usertype.value, 'filename': fname, 'fileid': fileid,
'username': friendlyname, 'viewmode': viewmode.value, 'folderurl': folderurl, 'endpoint': endpoint,
'appname': appname, 'appediturl': appediturl, 'appviewurl': appviewurl, 'trace': trace,
'exp': exptime, 'iss': f'cs3org:wopiserver:{WOPIVER}' # standard claims
Expand All @@ -248,7 +250,7 @@ def generateAccessToken(userid, fileid, viewmode, user, folderurl, endpoint, app
srv.allusers.add(userid)
log.info('msg="Access token generated" trace="%s" userid="%s" wopiuser="%s" friendlyname="%s" usertype="%s" mode="%s" '
'endpoint="%s" filename="%s" inode="%s" mtime="%s" folderurl="%s" appname="%s" expiration="%d" token="%s"' %
(trace, userid[-20:], wopiuser, friendlyname, usertype, viewmode, endpoint, statinfo['filepath'],
(trace, userid[-20:], wopiuser, friendlyname, usertype, viewmode, endpoint, fname,
statinfo['inode'], statinfo['mtime'], folderurl, appname, exptime, acctok[-20:]))
return statinfo['inode'], acctok, viewmode

Expand Down

0 comments on commit 7b60654

Please sign in to comment.