Skip to content

Commit 9e37de6

Browse files
committed
obs_cr/websocket_proxy: Improve validation of inputSettings variable
1 parent 65bd78e commit 9e37de6

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

obs_cr/websocket_proxy.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import functools
33
import json
44
import os
5+
from pathlib import Path
56
import ssl
67
import textwrap
78

@@ -109,10 +110,30 @@ def filter_forwarded(message):
109110
request = data['d']
110111
requestType = request['requestType']
111112
if requestType == 'SetInputSettings':
113+
# Carefully validate inputSettings
112114
inputSettings = request['requestData']['inputSettings']
113-
if len(set(inputSettings) - set('local_file overlay text font'.split())) == 0:
114-
return message
115-
print(message)
115+
# Verify all other inputSettings arguments ane in this allowed list.
116+
if len(set(inputSettings) - set('local_file overlay text font'.split())) > 0:
117+
print('denied message:', message)
118+
return
119+
# Verify the local_file argument is a safe path.
120+
if 'local_file' in inputSettings:
121+
local_file = Path(inputSettings['local_file']).expanduser().resolve()
122+
# If it starts with /home/rkdarst/, change to ~/ for this computer
123+
if local_file.is_relative_to('/home/rkdarst/'):
124+
local_file = ('~/' / local_file.relative_to('/home/rkdarst/')).expanduser().resolve()
125+
# Check the path, ensure it's in ~/git/coderefinery-artwork.
126+
# Symlinks, '..', etc. should have been expanded above.
127+
if not local_file.is_relative_to(Path('~/git/coderefinery-artwork').expanduser()):
128+
# If it's not in this git repo, exclude
129+
print('denied message:', message)
130+
print(f'exclude suspicious local_file={local_file}')
131+
return
132+
# Take our normalized local_file
133+
inputSettings['local_file'] = str(local_file)
134+
message = json.dumps(data)
135+
# Now fully validated
136+
return(message)
116137
return None
117138
if requestType in ALLOWED_REQUESTS:
118139
return message

0 commit comments

Comments
 (0)