mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-08-30 11:49:42 +02:00
Core: Add (optional) sanitization to the FileHandler class
This commit is contained in:
@@ -43,7 +43,7 @@ class FileHandlerInterface(io.RawIOBase):
|
||||
return self._preferred_filename
|
||||
|
||||
@preferred_filename.setter
|
||||
def preferred_filename(self, filename):
|
||||
def preferred_filename(self, filename: str):
|
||||
"""Sets the preferred filename"""
|
||||
if self.closed:
|
||||
raise IOError("FileHandler name cannot be changed once closed")
|
||||
@@ -57,6 +57,18 @@ class FileHandlerInterface(io.RawIOBase):
|
||||
def close(self):
|
||||
"""Method that commits the file and fixes the final filename for use"""
|
||||
|
||||
@staticmethod
|
||||
def sanitize_filename(filename: str) -> str:
|
||||
"""Sanititizes the filename to ensure only a specific whitelist of characters is allowed through"""
|
||||
allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ()[]\{\}!$%^:#~?<>,|"
|
||||
result = ""
|
||||
for char in filename:
|
||||
if char in allowed:
|
||||
result += char
|
||||
else:
|
||||
result += "?"
|
||||
return result
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user