Skip to content

Commit

Permalink
add is_valid_name
Browse files Browse the repository at this point in the history
  • Loading branch information
lijiejie committed Jun 16, 2022
1 parent 7276b28 commit 15ca25f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ds_store_exp.py
Expand Up @@ -22,6 +22,19 @@ def __init__(self, start_url):
self.processed_url = set()
self.lock = threading.Lock()
self.working_thread = 0
self.dest_dir = os.path.abspath('.')

def is_valid_name(self, entry_name):
if entry_name.find('..') >= 0 or \
entry_name.startswith('/') or \
entry_name.startswith('\\') or \
not os.path.abspath(entry_name).startswith(self.dest_dir):
try:
print('[ERROR] Invalid entry name: %s' % entry_name)
except Exception as e:
pass
return False
return True

def process(self):
while True:
Expand All @@ -45,7 +58,7 @@ def process(self):
url = 'http://%s' % url
schema, netloc, path, _, _, _ = urlparse(url, 'http')
try:
response = requests.get(url)
response = requests.get(url, allow_redirects=False)
except Exception as e:
self.lock.acquire()
print('[ERROR] %s' % str(e))
Expand All @@ -68,7 +81,8 @@ def process(self):

dirs_files = set()
for x in d._traverse(None):
dirs_files.add(x.filename)
if self.is_valid_name(x.filename):
dirs_files.add(x.filename)
for name in dirs_files:
if name != '.':
self.queue.put(base_url + name)
Expand Down

0 comments on commit 15ca25f

Please sign in to comment.