From: delacruzramo Date: Fri, 3 May 2019 12:52:37 +0000 (+0200) Subject: Bug 667: NBI not validating that hyphens are not allowed in Jinja2 X-Git-Tag: v6.0.0~50 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=36ffe5594a6f5ce262147c066bfadd438952acc1;p=osm%2FNBI.git Bug 667: NBI not validating that hyphens are not allowed in Jinja2 Change-Id: Ie70da179757808b7e7cfecb7f66c257fb347dcd0 Signed-off-by: delacruzramo --- diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index e14590b..55845d6 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -23,6 +23,7 @@ from base_topic import BaseTopic, EngineException, get_iterable from descriptor_topics import DescriptorTopic from yaml import safe_dump from osm_common.dbbase import DbException +from re import match # For checking that additional parameter names are valid Jinja2 identifiers __author__ = "Alfonso Tierno " @@ -115,6 +116,12 @@ class NsrTopic(BaseTopic): break if additional_params: for k, v in additional_params.items(): + # BEGIN Check that additional parameter names are valid Jinja2 identifiers + if not match('^[a-zA-Z_][a-zA-Z0-9_]*$', k): + raise EngineException("Invalid param name at {}:{}. Must contain only alphanumeric characters " + "and underscores, and cannot start with a digit" + .format(where_, k)) + # END Check that additional parameter names are valid Jinja2 identifiers if not isinstance(k, str): raise EngineException("Invalid param at {}:{}. Only string keys are allowed".format(where_, k)) if "." in k or "$" in k: