Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions concore_cli/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def validate_workflow(workflow_file, console):
label = label_tag.text.strip()
node_labels.append(label)

# reject shell metacharacters to prevent command injection (#251)
if re.search(r'[;&|`$\'"()\\]', label):
errors.append(f"Node '{label}' contains unsafe shell characters")
continue

if ':' not in label:
warnings.append(f"Node '{label}' missing format 'ID:filename'")
else:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ def test_validate_node_missing_filename(self):
self.assertIn('Validation failed', result.output)
self.assertIn('has no filename', result.output)

def test_validate_unsafe_node_label(self):
content = '''
<graphml xmlns:y="http://www.yworks.com/xml/graphml">
<graph id="G" edgedefault="directed">
<node id="n0">
<data key="d0"><y:NodeLabel>n0;rm -rf /:script.py</y:NodeLabel></data>
</node>
</graph>
</graphml>
'''
filepath = self.create_graph_file('injection.graphml', content)

result = self.runner.invoke(cli, ['validate', filepath])

self.assertIn('Validation failed', result.output)
self.assertIn('unsafe shell characters', result.output)

def test_validate_valid_graph(self):
content = '''
<graphml xmlns:y="http://www.yworks.com/xml/graphml">
Expand Down