From 0965f629fbccd613a00c2e885daf5a66da656cd8 Mon Sep 17 00:00:00 2001 From: HitanshiThakar Date: Wed, 20 May 2026 00:01:46 +0530 Subject: [PATCH 1/2] test(plugins): add duplicate metadata validation --- plugins/waf_detector/metadata.json | 6 +-- testing/backend/unit/test_plugin_integrity.py | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/plugins/waf_detector/metadata.json b/plugins/waf_detector/metadata.json index 88906996a..b642dcda5 100644 --- a/plugins/waf_detector/metadata.json +++ b/plugins/waf_detector/metadata.json @@ -1,6 +1,6 @@ { "id": "waf_detector", - "name": "WAF Detector", + "name": "WAF Detection Scanner", "version": "1.0.0", "description": "Automatically identify Web Application Firewalls protecting targets.", "long_description": "Automatically identify Web Application Firewalls protecting targets.", @@ -10,7 +10,7 @@ "email": "dev@secuscan.local" }, "license": "MIT", - "icon": "\ud83d\udee0\ufe0f", + "icon": "🛠️", "engine": { "type": "cli", "binary": "wafw00f" @@ -54,5 +54,5 @@ "python_packages": [], "system_packages": [] }, - "checksum": "1e3dfcf6d4ba7847e398b9d9a4709dc275092f52a5f405e63d65cea0f8389cc0" + "checksum": "60b54af15ff7bad498a02cdbf08ee8611622e117944a3a65301cb3cae1582bb2" } diff --git a/testing/backend/unit/test_plugin_integrity.py b/testing/backend/unit/test_plugin_integrity.py index 3907d026a..89d94a6e3 100644 --- a/testing/backend/unit/test_plugin_integrity.py +++ b/testing/backend/unit/test_plugin_integrity.py @@ -1,7 +1,10 @@ import asyncio import json +from collections import defaultdict from pathlib import Path +import pytest + from backend.secuscan.plugins import PluginManager from backend.secuscan.config import settings @@ -18,3 +21,37 @@ def test_plugins_have_checksums(): for path in metadata_files: data = json.loads(path.read_text(encoding="utf-8")) assert data.get("checksum"), f"Missing checksum in {path}" + + +def test_plugin_metadata_ids_and_names_are_unique(): + metadata_files = list(Path(settings.plugins_dir).glob("*/metadata.json")) + assert metadata_files, "Expected plugin metadata files" + + ids = defaultdict(list) + names = defaultdict(list) + + for path in metadata_files: + data = json.loads(path.read_text(encoding="utf-8")) + plugin_id = data.get("id") + plugin_name = data.get("name") + assert plugin_id, f"Missing plugin id in {path}" + assert plugin_name, f"Missing plugin name in {path}" + + ids[plugin_id].append(path.parent.name) + names[plugin_name].append(path.parent.name) + + duplicate_ids = {plugin_id: folders for plugin_id, folders in ids.items() if len(folders) > 1} + duplicate_names = {plugin_name: folders for plugin_name, folders in names.items() if len(folders) > 1} + + if duplicate_ids or duplicate_names: + messages = [] + if duplicate_ids: + messages.append("Duplicate plugin IDs found:") + for plugin_id, folders in sorted(duplicate_ids.items()): + messages.append(f" {plugin_id}: {', '.join(sorted(folders))}") + if duplicate_names: + messages.append("Duplicate plugin display names found:") + for plugin_name, folders in sorted(duplicate_names.items()): + messages.append(f" {plugin_name}: {', '.join(sorted(folders))}") + + pytest.fail("\n".join(messages)) From fe11009192ee23ceafc5abf3f9ff78667deae974 Mon Sep 17 00:00:00 2001 From: HitanshiThakar Date: Fri, 31 Jul 2026 16:59:14 +0530 Subject: [PATCH 2/2] fix: union declared and implied plugin capabilities --- backend/secuscan/capabilities.py | 18 ++++++++---------- testing/backend/unit/test_capabilities.py | 10 +++++----- .../unit/test_capabilities_effective.py | 15 ++++++++++----- .../unit/test_plugin_capabilities_inventory.py | 7 +++---- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/backend/secuscan/capabilities.py b/backend/secuscan/capabilities.py index ffcabbe35..55bf84880 100644 --- a/backend/secuscan/capabilities.py +++ b/backend/secuscan/capabilities.py @@ -62,9 +62,9 @@ class Capability(str, Enum): ALL_CAPABILITIES: FrozenSet[str] = frozenset(c.value for c in Capability) -# Capabilities that are implicitly required by a plugin's safety level when the -# plugin has not declared them explicitly. This lets older plugins without a -# ``capabilities`` field degrade gracefully while still being enforceable. +# Capabilities that are implicitly required by a plugin's safety level. This +# lets older plugins without a ``capabilities`` field degrade gracefully while +# still being enforceable. _SAFETY_LEVEL_IMPLIED: dict[str, List[str]] = { "safe": ["network"], "intrusive": ["network", "intrusive"], @@ -107,17 +107,15 @@ def effective_capabilities( ) -> Set[str]: """Combine explicitly declared capabilities with safety-level implied ones. - If the plugin declares an explicit capability list, that list is the source - of truth (implied capabilities are *not* added on top — they were already - considered by the plugin author). If no capabilities are declared at all the - implied set for the plugin's safety level is used so that legacy plugins - remain enforceable. + Explicit capabilities are additive to the set implied by the plugin's + safety level. If no capabilities are declared at all, the implied set is + used so that legacy plugins remain enforceable. """ + implied = _SAFETY_LEVEL_IMPLIED.get(safety_level, ["network"]) if declared is not None and len(declared) > 0: validated = validate_capability_list(declared, plugin_id) - return set(validated) + return set(validated) | set(implied) - implied = _SAFETY_LEVEL_IMPLIED.get(safety_level, ["network"]) return set(implied) diff --git a/testing/backend/unit/test_capabilities.py b/testing/backend/unit/test_capabilities.py index de838562d..74ff8dc9f 100644 --- a/testing/backend/unit/test_capabilities.py +++ b/testing/backend/unit/test_capabilities.py @@ -88,11 +88,10 @@ def test_explicit_empty_list_falls_back_to_implied(self): caps = effective_capabilities([], "intrusive", "plugin") assert "intrusive" in caps - def test_explicit_list_overrides_implied(self): - # Plugin explicitly declares only "filesystem" even though it's intrusive + def test_explicit_list_is_additive_to_implied(self): + # Plugin explicitly declares "filesystem" and is also intrusive caps = effective_capabilities(["filesystem"], "intrusive", "plugin") - assert caps == {"filesystem"} - assert "network" not in caps + assert caps == {"filesystem", "network", "intrusive"} # --------------------------------------------------------------------------- @@ -199,7 +198,8 @@ def test_uppercase_denied_capability_normalised(self): def test_empty_strings_in_denied_list_ignored(self): enforcer = CapabilityEnforcer(denied_capabilities=["", " ", "network"]) - enforcer.check("nmap", ["filesystem"], "safe") + with pytest.raises(CapabilityDeniedError): + enforcer.check("nmap", ["filesystem"], "safe") def test_denied_property_is_frozenset(self): enforcer = CapabilityEnforcer(denied_capabilities=["network", "exploit"]) diff --git a/testing/backend/unit/test_capabilities_effective.py b/testing/backend/unit/test_capabilities_effective.py index adec4c87d..eb3d207a0 100644 --- a/testing/backend/unit/test_capabilities_effective.py +++ b/testing/backend/unit/test_capabilities_effective.py @@ -1,9 +1,9 @@ """ Unit tests for effective_capabilities in backend/secuscan/capabilities.py. -Verifies the plugin capability resolution logic: explicit declarations take -precedence, and legacy plugins without declarations get implied capabilities -based on their safety level. +Verifies the plugin capability resolution logic: explicit declarations are +additive, and legacy plugins without declarations get implied capabilities based +on their safety level. """ from backend.secuscan.capabilities import effective_capabilities @@ -20,6 +20,11 @@ def test_declared_order_ignored(self): result = effective_capabilities(["filesystem", "network"], "safe", "plugin-y") assert result == {"network", "filesystem"} + def test_declared_capabilities_include_exploit_safety_implication(self): + """Explicit capabilities cannot remove the exploit safety capability.""" + result = effective_capabilities(["network"], "exploit", "plugin-exploit") + assert result == {"network", "intrusive", "exploit"} + def test_declared_empty_treated_as_none(self): """Empty declared list is treated the same as None (uses implied).""" result = effective_capabilities([], "intrusive", "plugin-z") @@ -53,9 +58,9 @@ def test_none_declared_uses_implied_for_safe(self): assert "network" in result def test_declared_single_capability(self): - """Single declared capability is preserved.""" + """Single declared capability is preserved alongside implications.""" result = effective_capabilities(["docker"], "safe", "docker-plugin") - assert result == {"docker"} + assert result == {"docker", "network"} def test_declared_deduplicates(self): """Duplicate entries in declared list are deduplicated.""" diff --git a/testing/backend/unit/test_plugin_capabilities_inventory.py b/testing/backend/unit/test_plugin_capabilities_inventory.py index 72c5a38d4..1e5cb8cd4 100644 --- a/testing/backend/unit/test_plugin_capabilities_inventory.py +++ b/testing/backend/unit/test_plugin_capabilities_inventory.py @@ -222,11 +222,10 @@ def test_explicit_empty_list_falls_back_to_implied(self): caps = effective_capabilities([], "intrusive", "plugin") assert "intrusive" in caps - def test_explicit_nonempty_list_overrides_implied(self): - # Plugin explicitly declares only filesystem; implied intrusive set is NOT added. + def test_explicit_nonempty_list_is_additive_to_implied(self): + # Plugin explicitly declares filesystem; intrusive implications remain. caps = effective_capabilities(["filesystem"], "intrusive", "plugin") - assert caps == {"filesystem"} - assert "intrusive" not in caps + assert caps == {"filesystem", "network", "intrusive"} def test_all_shipped_plugins_have_enforceable_effective_capabilities(self): """Every plugin in the plugins/ directory must produce a non-empty