|
24 | 24 | import contextlib
|
25 | 25 | import fcntl
|
26 | 26 | import os
|
| 27 | +import re |
27 | 28 | import hashlib
|
28 | 29 |
|
29 | 30 | from .parser import ValidateParser, FilePolicy, get_invalid_characters
|
@@ -87,7 +88,11 @@ def handle_request(
|
87 | 88 | Throws PolicyAdminException in case of user error.
|
88 | 89 | """
|
89 | 90 |
|
90 |
| - assert all(char in RPCNAME_ALLOWED_CHARSET for char in arg) |
| 91 | + if not all(char in RPCNAME_ALLOWED_CHARSET for char in arg): |
| 92 | + raise PolicyAdminException( |
| 93 | + "Invalid argument: \"{}\"\n" |
| 94 | + "Valid characters are letters, numbers, dot, plus, hyphen and " |
| 95 | + "underline".format(arg)) |
91 | 96 |
|
92 | 97 | func = self._find_method(service_name)
|
93 | 98 | if not func:
|
@@ -266,7 +271,12 @@ def policy_get_files(self, arg):
|
266 | 271 |
|
267 | 272 | # helpers
|
268 | 273 |
|
269 |
| - def _get_path(self, arg: str, dir_path, suffix: str) -> Path: |
| 274 | + def _get_path(self, arg: str, dir_path: str , suffix: str) -> Path: |
| 275 | + if not re.compile(r'^[\w-]+$').match(arg): |
| 276 | + raise PolicyAdminException( |
| 277 | + f"Invalid policy file name: {arg}\n" |
| 278 | + "Names must contain only alphanumeric characters, " |
| 279 | + "underscore and hyphen.") |
270 | 280 | path = dir_path / (arg + suffix)
|
271 | 281 | path = path.resolve()
|
272 | 282 | if path.parent != dir_path:
|
|
0 commit comments