Skip to content

Commit

Permalink
Merge pull request #36 from wordfence/gh-25
Browse files Browse the repository at this point in the history
Added detection for recursive symlinks
  • Loading branch information
akenion authored Aug 31, 2023
2 parents 3d1f49c + 9fc0da9 commit 6410716
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions wordfence/scanning/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,29 @@ def __init__(self, path: str,
self.file_filter = file_filter
self.located_count = 0

def search_directory(self, path: str):
def _is_loop(self, path: str, parents: list):
realpath = os.path.realpath(path)
for parent in parents:
if realpath == parent:
log.warning(
f'Recursive symlink detected at {path}'
)
return True
return False

def search_directory(self, path: str, parents: Optional[list] = None):
try:
if parents is None:
parents = [path]
contents = os.scandir(path)
for item in contents:
if item.is_symlink() and self._is_loop(item.path, parents):
continue
if item.is_dir():
yield from self.search_directory(item.path)
yield from self.search_directory(
item.path,
parents + [item.path]
)
elif item.is_file():
if not self.file_filter.filter(item.path):
continue
Expand Down

0 comments on commit 6410716

Please sign in to comment.