Address code review feedback: improve function naming and consolidate patterns
Co-authored-by: kingassune <6126851+kingassune@users.noreply.github.com>
This commit is contained in:
parent
cbb99c64e5
commit
56d301de3e
@ -5,7 +5,7 @@
|
||||
If you discover a security vulnerability in nanobot, please report it by:
|
||||
|
||||
1. **DO NOT** open a public GitHub issue
|
||||
2. Email the maintainers at [security@nanobot.ai] or create a private security advisory on GitHub
|
||||
2. Create a private security advisory on GitHub or contact the repository maintainers
|
||||
3. Include:
|
||||
- Description of the vulnerability
|
||||
- Steps to reproduce
|
||||
|
||||
@ -10,8 +10,7 @@ from nanobot.agent.tools.base import Tool
|
||||
|
||||
# List of potentially dangerous command patterns
|
||||
DANGEROUS_PATTERNS = [
|
||||
r'rm\s+-rf\s+/\s*$', # rm -rf / (at root only)
|
||||
r'rm\s+-rf\s+/(?![\w/])', # rm -rf / followed by whitespace or end
|
||||
r'rm\s+-rf\s+/(?:\s|$)', # rm -rf / (at root, followed by space or end)
|
||||
r':\(\)\{\s*:\|:&\s*\};:', # fork bomb
|
||||
r'mkfs\.', # format filesystem
|
||||
r'dd\s+if=.*\s+of=/dev/(sd|hd)', # overwrite disk
|
||||
@ -19,7 +18,7 @@ DANGEROUS_PATTERNS = [
|
||||
]
|
||||
|
||||
|
||||
def _is_dangerous_command(command: str) -> tuple[bool, str | None]:
|
||||
def validate_command_safety(command: str) -> tuple[bool, str | None]:
|
||||
"""
|
||||
Check if a command contains dangerous patterns.
|
||||
|
||||
@ -66,7 +65,7 @@ class ExecTool(Tool):
|
||||
|
||||
async def execute(self, command: str, working_dir: str | None = None, **kwargs: Any) -> str:
|
||||
# Check for dangerous command patterns
|
||||
is_dangerous, warning = _is_dangerous_command(command)
|
||||
is_dangerous, warning = validate_command_safety(command)
|
||||
if is_dangerous:
|
||||
return f"Error: Refusing to execute dangerous command. {warning}"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user