diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 9c76e73eb..a3244abe1 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2470,6 +2470,7 @@ class PasswordArgumentParser(YunoHostArgumentFormatParser): hide_user_input_in_prompt = True argument_type = "password" default_value = "" + forbidden_chars = "{}" def parse_question(self, question, user_answers): question = super(PasswordArgumentParser, self).parse_question(question, user_answers) @@ -2479,6 +2480,12 @@ class PasswordArgumentParser(YunoHostArgumentFormatParser): return question + def _post_parse_value(self, question): + if any(char in question.value for char in self.forbidden_chars): + raise YunohostError('pattern_password_app', forbidden_chars=self.forbidden_chars) + + return super(PasswordArgumentParser, self)._post_parse_value(question) + class PathArgumentParser(YunoHostArgumentFormatParser): argument_type = "path" diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 1ea73cc0a..9576ce0bf 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -8,7 +8,7 @@ from collections import OrderedDict from moulinette import msignals from yunohost import domain, user, app -from yunohost.app import _parse_args_in_yunohost_format +from yunohost.app import _parse_args_in_yunohost_format, PasswordArgumentParser from yunohost.utils.error import YunohostError @@ -359,6 +359,21 @@ def test_parse_args_in_yunohost_format_password_input_test_ask_with_help(): assert help_text in prompt.call_args[0][0] +def test_parse_args_in_yunohost_format_password_bad_chars(): + questions = [ + { + "name": "some_password", + "type": "password", + "ask": "some question", + "example": "some_value", + } + ] + + for i in PasswordArgumentParser.forbidden_chars: + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format({"some_password": i * 8}, questions) + + def test_parse_args_in_yunohost_format_path(): questions = [{"name": "some_path", "type": "path",}] answers = {"some_path": "some_value"}