Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added detection for recursive symlinks #36

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions wordfence/scanning/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,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