Skip to content

Commit 5b15c3a

Browse files
authored
Merge pull request #233 from autoscrape-labs/codex/find-and-fix-a-critical-bug
Validate browser path refers to file not directory
2 parents e8ba901 + ada73e7 commit 5b15c3a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pydoll/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def validate_browser_paths(paths: list[str]) -> str:
159159
InvalidBrowserPath: If the browser executable is not found at the path.
160160
"""
161161
for path in paths:
162-
if os.path.exists(path) and os.access(path, os.X_OK):
162+
if os.path.isfile(path) and os.access(path, os.X_OK):
163163
return path
164164
raise InvalidBrowserPath(f'No valid browser path found in: {paths}')
165165

tests/test_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ def test_validate_browser_paths_file_exists_but_not_executable(self):
206206
with pytest.raises(exceptions.InvalidBrowserPath):
207207
validate_browser_paths([non_executable])
208208

209+
@pytest.mark.skipif(sys.platform.startswith('win'), reason='No executable bit on NTFS on Windows')
210+
def test_validate_browser_paths_directory_instead_of_file(self):
211+
"""
212+
Test validate_browser_paths with a directory path.
213+
Verifies that directories are not treated as valid executables even if they have execute permission.
214+
"""
215+
with tempfile.TemporaryDirectory() as temp_dir:
216+
os.chmod(temp_dir, 0o755)
217+
with pytest.raises(exceptions.InvalidBrowserPath):
218+
validate_browser_paths([temp_dir])
219+
209220
def test_validate_browser_paths_empty_list(self):
210221
"""
211222
Test validate_browser_paths with empty path list.

0 commit comments

Comments
 (0)