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(loader): preserve class identity in module imports and isolate reload eviction

Mafifrizia52bc2099ea0
diff --git a/ares/api/server.py b/ares/api/server.py
index 0e9ccde..8060be3 100644
--- a/ares/api/server.py
+++ b/ares/api/server.py
@@ -2239,6 +2239,12 @@ async def reload_modules(
detail="Insufficient permissions for module reload.",
) from exc
+ import sys
+
+ for mod_name in list(sys.modules.keys()):
+ if mod_name.startswith("ares.modules.") and not mod_name.endswith(".base"):
+ sys.modules.pop(mod_name, None)
+
importlib.invalidate_caches()
count = engine.load_modules()
logger.info("engine_modules_reloaded", total_modules=count, client=client_host)
diff --git a/ares/core/plugin/loader.py b/ares/core/plugin/loader.py
index 1c9360c..c07d617 100644
--- a/ares/core/plugin/loader.py
+++ b/ares/core/plugin/loader.py
@@ -355,13 +355,7 @@ class PluginLoader:
def _import_and_register(self, module_path: str, source: str) -> None:
try:
- if module_path in sys.modules:
- try:
- mod = importlib.reload(sys.modules[module_path])
- except Exception:
- mod = importlib.import_module(module_path)
- else:
- mod = importlib.import_module(module_path)
+ mod = importlib.import_module(module_path)
for _, cls in inspect.getmembers(mod, inspect.isclass):
if self._is_valid_module_class(cls):
self.registry.register(cls, source=source)