Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure configured paths have no trailing slash #151

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/wopiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def init(cls):
except OSError:
cls.log.error('msg="Failed to open the provided certificate or key to start in https mode"')
raise
cls.wopiurl = cls.config.get('general', 'wopiurl')
cls.homepath = cls.config.get('general', 'homepath', fallback='/home/username')
cls.recoverypath = cls.config.get('io', 'recoverypath', fallback='/var/spool/wopirecovery')
cls.wopiurl = cls.config.get('general', 'wopiurl').strip('/')
cls.homepath = cls.config.get('general', 'homepath', fallback='/home/username').strip('/')
cls.recoverypath = cls.config.get('io', 'recoverypath', fallback='/var/spool/wopirecovery').strip('/')
Comment on lines +149 to +151
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glpatcern are you sure that strip does the right thing?

According to https://www.w3schools.com/python/ref_string_strip.asp, it removes trailing and leading slashes in our case. Which makes the path relative instead of absolute. I noticed it because I have a readonly filesystem in our Kubernetes setup and it tries to write somewhere it should not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, sorry for that! Let's not over-engineer this, I will simply revert the change for the OS-level paths (where extra slashes are irrelevant anyway) and leave it for URLs (where the protocol prefix MUST be present)

try:
os.makedirs(cls.recoverypath)
except FileExistsError:
pass
# WOPI proxy configuration (optional)
cls.wopiproxy = cls.config.get('general', 'wopiproxy', fallback='')
cls.wopiproxy = cls.config.get('general', 'wopiproxy', fallback='').strip('/')
cls.wopiproxykey = None
proxykeyfile = cls.config.get('general', 'wopiproxysecretfile', fallback='')
if proxykeyfile:
Expand Down
Loading