Skip to content

Commit 5d43071

Browse files
ikelos616c696365
authored andcommitted
Core: Add (optional) sanitization to the FileHandler class
1 parent f2f412d commit 5d43071

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

volatility3/framework/interfaces/plugins.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def preferred_filename(self):
4343
return self._preferred_filename
4444

4545
@preferred_filename.setter
46-
def preferred_filename(self, filename):
46+
def preferred_filename(self, filename: str):
4747
"""Sets the preferred filename"""
4848
if self.closed:
4949
raise IOError("FileHandler name cannot be changed once closed")
@@ -57,6 +57,18 @@ def preferred_filename(self, filename):
5757
def close(self):
5858
"""Method that commits the file and fixes the final filename for use"""
5959

60+
@staticmethod
61+
def sanitize_filename(filename: str) -> str:
62+
"""Sanititizes the filename to ensure only a specific whitelist of characters is allowed through"""
63+
allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ()[]\{\}!$%^:#~?<>,|"
64+
result = ""
65+
for char in filename:
66+
if char in allowed:
67+
result += char
68+
else:
69+
result += "?"
70+
return result
71+
6072
def __enter__(self):
6173
return self
6274

0 commit comments

Comments
 (0)