Skip to content

Commit 7bd955a

Browse files
committed
Add UnixDomainSocketDirectory token plugin
1 parent 6d48b15 commit 7bd955a

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

websockify/token_plugins.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def lookup(self, token):
102102
import json
103103

104104
key = jwt.JWK()
105-
105+
106106
try:
107107
with open(self.source, 'rb') as key_file:
108108
key_data = key_file.read()
@@ -158,3 +158,31 @@ def lookup(self, token):
158158
(host, port) = combo["host"].split(':')
159159
port = port.encode('ascii','ignore')
160160
return [ host, port ]
161+
162+
163+
class UnixDomainSocketDirectory(BasePlugin):
164+
def __init__(self, *args, **kwargs):
165+
super(UnixDomainSocketDirectory, self).__init__(*args, **kwargs)
166+
self._dir_path = os.path.abspath(self.source)
167+
168+
def lookup(self, token):
169+
try:
170+
import stat
171+
172+
if not os.path.isdir(self._dir_path):
173+
return None
174+
175+
uds_path = os.path.abspath(os.path.join(self._dir_path, token))
176+
if not uds_path.startswith(self._dir_path):
177+
return None
178+
179+
if not os.path.exists(uds_path):
180+
return None
181+
182+
if not stat.S_ISSOCK(os.stat(uds_path).st_mode):
183+
return None
184+
185+
return [ 'unix_socket', uds_path ]
186+
except Exception as e:
187+
print("Error finding unix domain socket: %s" % str(e), file=sys.stderr)
188+
return None

0 commit comments

Comments
 (0)