Skip to content

Commit e7a5df9

Browse files
committed
api: validate arg in AbstractQubesAPI.__init__()
Validate arg against qrexec allowed characters, consistent with sanitize_name() in qrexec-daemon.c. This ensures consistent behavior between dom0 and management qube. Related: #751
1 parent 891576d commit e7a5df9

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

qubes/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ def __init__(
166166

167167
#: argument
168168
self.arg = arg.decode("ascii")
169+
# Validate arg against qrexec allowed characters
170+
# Consistent with sanitize_name() in qrexec-daemon.c
171+
if self.arg and not re.match(r"\A[a-zA-Z0-9_.+:*?@-]+\Z", self.arg):
172+
raise ProtocolError(f"arg not allowed in qrexec: {self.arg!r}")
169173
#: name of the method
170174
self.method = method_name.decode("ascii")
171175

qubes/tests/api_admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,11 +1333,11 @@ def test_200_label_create_invalid_name(self):
13331333
self.call_mgmt_func(
13341334
b"admin.label.Create", b"dom0", b"01", b"0xff0000"
13351335
)
1336-
with self.assertRaises(qubes.exc.PermissionDenied):
1336+
with self.assertRaises(qubes.exc.ProtocolError):
13371337
self.call_mgmt_func(
13381338
b"admin.label.Create", b"dom0", b"../xxx", b"0xff0000"
13391339
)
1340-
with self.assertRaises(qubes.exc.PermissionDenied):
1340+
with self.assertRaises(qubes.exc.ProtocolError):
13411341
self.call_mgmt_func(
13421342
b"admin.label.Create",
13431343
b"dom0",

0 commit comments

Comments
 (0)