Skip to content

Commit a478003

Browse files
committed
Add node label validation to prevent command injection (#251)
1 parent 3b6756b commit a478003

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

mkconcore.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@
200200
node_label_tag = data.find('y:NodeLabel')
201201
if node_label_tag:
202202
node_label = prefixedgenode + node_label_tag.text
203-
nodes_dict[node['id']] = re.sub(r'(\s+|\n)', ' ', node_label)
203+
node_label = re.sub(r'(\s+|\n)', ' ', node_label)
204+
if not re.match(r'^[a-zA-Z0-9_\-.:]+$', node_label):
205+
logging.error(f"node label '{node_label}' has unsupported characters")
206+
quit()
207+
nodes_dict[node['id']] = node_label
204208
node_id_to_label_map[node['id']] = node_label.split(':')[0]
205209
except (IndexError, AttributeError):
206210
logging.debug('A node with no valid properties encountered and ignored')

0 commit comments

Comments
 (0)