Skip to content

Commit ee025cd

Browse files
Merge branch 'master' of https://github.com/johnsamuelwrites/ShExStatements into dreamy-wilson
2 parents c0c07be + 67a6c3a commit ee025cd

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

shexstatements/shexfromcsv.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
from shexstatements.shexstatementsparser import ShExStatementLexerParser
1010
from io import StringIO
11+
import os
1112

1213

1314
class CSV:
@@ -69,7 +70,17 @@ def generate_shex_from_csv(filepath, delim=",", skip_header=False, filename=True
6970
pattern = r'^\s*$'
7071
data = ""
7172
if filename:
72-
csvfile = open(filepath, 'r')
73+
# Validate and normalize the file path to avoid path traversal
74+
normalized_path = os.path.normpath(filepath)
75+
# Reject absolute paths
76+
if os.path.isabs(normalized_path):
77+
raise ValueError("Absolute paths are not allowed")
78+
# Only allow simple filenames without directory components
79+
if os.path.sep in normalized_path or (os.path.altsep and os.path.altsep in normalized_path):
80+
raise ValueError("Directory separators are not allowed in filename")
81+
if not normalized_path:
82+
raise ValueError("Empty filename is not allowed")
83+
csvfile = open(normalized_path, 'r')
7384
csvreader = csv.reader(csvfile, delimiter=delim)
7485
else:
7586
# It's a multi-line string

0 commit comments

Comments
 (0)