-
Notifications
You must be signed in to change notification settings - Fork 133
fix(security): 2 improvements across 2 files #1201
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| import importlib | ||
| import re | ||
| from secator.loader import discover_tasks | ||
|
|
||
| TASKS = discover_tasks() | ||
| __all__ = [ | ||
| cls.__name__ | ||
| for cls in TASKS | ||
| ] | ||
| for cls in TASKS: | ||
| exec(f'from .{cls.__name__} import {cls.__name__}') | ||
| name = cls.__name__ | ||
| if not re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', name): | ||
| raise ValueError(f'Invalid task class name: {name}') | ||
| importlib.import_module(f'.{name}', __package__) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||
| import shlex | ||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||
| import yaml | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # from secator.decorators import task | ||||||||||||||||||||||||||
|
|
@@ -75,6 +76,12 @@ def on_init(self): | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||
| def on_cmd_done(self): | ||||||||||||||||||||||||||
| output_path = Path(self.output_path).resolve() | ||||||||||||||||||||||||||
| reports_folder = Path(self.reports_folder).resolve() | ||||||||||||||||||||||||||
| if not str(output_path).startswith(str(reports_folder)): | ||||||||||||||||||||||||||
| yield Error(message=f'Output path {output_path} is not within reports folder {reports_folder}') | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
|
Comment on lines
+79
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check Python version requirements to determine which fix to use
fd -t f -e toml -e cfg -e txt 'pyproject|setup|requirements' --exec cat {}
# Also check for existing usage of is_relative_to in the codebase
rg -n 'is_relative_to|relative_to' --type pyRepository: freelabz/secator Length of output: 2347 🏁 Script executed: # Check the actual code in dirsearch.py at lines 79-83
head -85 secator/tasks/dirsearch.py | tail -10Repository: freelabz/secator Length of output: 416 🏁 Script executed: # Search for how paths are validated elsewhere in the codebase
rg -n 'startswith.*/' --type py -A 2 -B 2 | head -50Repository: freelabz/secator Length of output: 3135 🏁 Script executed: # Check if dirsearch.py exists and verify its structure
wc -l secator/tasks/dirsearch.py
head -100 secator/tasks/dirsearch.py | tail -40Repository: freelabz/secator Length of output: 1433 String-based The containment check using Since the project requires Python 3.8+ support, use the 🔒 Proposed fix for Python 3.8+ compatibility `@staticmethod`
def on_cmd_done(self):
output_path = Path(self.output_path).resolve()
reports_folder = Path(self.reports_folder).resolve()
- if not str(output_path).startswith(str(reports_folder)):
+ try:
+ output_path.relative_to(reports_folder)
+ except ValueError:
yield Error(message=f'Output path {output_path} is not within reports folder {reports_folder}')
return📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if not os.path.exists(self.output_path): | ||||||||||||||||||||||||||
| yield Error(message=f'Could not find JSON results in {self.output_path}') | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: freelabz/secator
Length of output: 6970
🏁 Script executed:
Repository: freelabz/secator
Length of output: 496
🏁 Script executed:
rg -n "def discover_tasks" --type py -A 20Repository: freelabz/secator
Length of output: 1230
🏁 Script executed:
rg -n "def discover_internal_tasks" --type py -A 30Repository: freelabz/secator
Length of output: 1746
🏁 Script executed:
rg -n "__getattr__" secator/tasks/__init__.pyRepository: freelabz/secator
Length of output: 42
🏁 Script executed:
Repository: freelabz/secator
Length of output: 113
🏁 Script executed:
Repository: freelabz/secator
Length of output: 968
🏁 Script executed:
Repository: freelabz/secator
Length of output: 515
🏁 Script executed:
Repository: freelabz/secator
Length of output: 80
🏁 Script executed:
git log --all --oneline -- secator/tasks/__init__.py | head -5Repository: freelabz/secator
Length of output: 397
🏁 Script executed:
Repository: freelabz/secator
Length of output: 244
🏁 Script executed:
rg -n "import sys" secator/tasks/__init__.pyRepository: freelabz/secator
Length of output: 42
🏁 Script executed:
Repository: freelabz/secator
Length of output: 588
🏁 Script executed:
Repository: freelabz/secator
Length of output: 282
Task classes not exported to package namespace — breaks
from secator.tasks import <task>imports.The refactor from
exec(f'from .{cls.__name__} import {cls.__name__}')toimportlib.import_module()introduced a critical flaw. The old approach both imported the module AND bound the class to the package namespace. The new code only loads the module intosys.modulesbut discards the return value, leaving the class unbound.Additionally,
__all__is defined but irrelevant—it only controlsfrom secator.tasks import *behavior. Direct imports likefrom secator.tasks import nmap(as used throughout tests) require the class to exist in the module's__dict__, which it currently does not.🐛 Proposed fix to bind the class to the package namespace
for cls in TASKS: name = cls.__name__ if not re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', name): raise ValueError(f'Invalid task class name: {name}') - importlib.import_module(f'.{name}', __package__) + module = importlib.import_module(f'.{name}', __package__) + globals()[name] = getattr(module, name)🤖 Prompt for AI Agents