Skip to content

armgit / ARES

Public Imported from GitHub
0

ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.

fix: enforce plugin loader path containment

Mafifrizie166a7545fab
diff --git a/ares/core/plugin/loader.py b/ares/core/plugin/loader.py
index d443a57..06a617d 100644
--- a/ares/core/plugin/loader.py
+++ b/ares/core/plugin/loader.py
@@ -65,6 +65,10 @@ def _get_signing_policy():
return None
+def _is_path_within_base(path: Path, base: Path) -> bool:
+ return path == base or path.is_relative_to(base)
+
+
def _enforce_capabilities(cls: Any, source: str) -> list[str]:
"""
Check a module's declared CAPABILITIES against its trust level.
@@ -309,7 +313,9 @@ class PluginLoader:
Path.home().resolve(),
Path("/tmp").resolve(), # noqa: S108 — sandbox staging area
]
- if not any(str(plugin_dir).startswith(str(base)) for base in _allowed_bases):
+ if not any(
+ _is_path_within_base(plugin_dir, base) for base in _allowed_bases
+ ):
logger.error(
f"[plugin_loader] Rejected plugin dir outside allowed locations: {plugin_dir}. "
f"Must be under home directory or /tmp."
diff --git a/tests/unit/db/test_database.py b/tests/unit/db/test_database.py
index 4ff941b..a590106 100644
--- a/tests/unit/db/test_database.py
+++ b/tests/unit/db/test_database.py
@@ -14,6 +14,7 @@ from unittest.mock import AsyncMock, patch
import pytest
+import ares.core.plugin.loader as plugin_loader_module
from ares.core.campaign import Campaign, Finding, NoiseProfile, Severity, ScopeEntry
from ares.core.config import AresSettings
from ares.core.engine import AresEngine, ExecutionPlan, ModuleStatus
@@ -97,6 +98,22 @@ class TestPluginLoader:
loader._load_external(str(tmp_path)) # Should not raise
assert loader.errors == []
+ def test_external_dir_containment_rejects_same_prefix_sibling(
+ self, tmp_path: Path
+ ) -> None:
+ allowed_base = (tmp_path / "plugins").resolve()
+ child_dir = (allowed_base / "child").resolve()
+ sibling_dir = (tmp_path / "plugins_evil").resolve()
+
+ child_dir.mkdir(parents=True)
+ sibling_dir.mkdir()
+
+ assert plugin_loader_module._is_path_within_base(allowed_base, allowed_base)
+ assert plugin_loader_module._is_path_within_base(child_dir, allowed_base)
+ assert not plugin_loader_module._is_path_within_base(
+ sibling_dir, allowed_base
+ )
+
def test_external_plugin_loaded(self, tmp_path: Path) -> None:
"""Write a valid external plugin and verify it's discovered."""
plugin_code = '''