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/plugins/waf_detector/metadata.json b/plugins/waf_detector/metadata.json index 6bd96a48a..b642dcda5 100644 --- a/plugins/waf_detector/metadata.json +++ b/plugins/waf_detector/metadata.json @@ -54,6 +54,5 @@ "python_packages": [], "system_packages": [] }, - "capabilities": ["network"], - "checksum": "ac518fd15fe9a14f9327812178fd244ebaa2ee95d29d04b93ee928fa3fda7ffa" + "checksum": "60b54af15ff7bad498a02cdbf08ee8611622e117944a3a65301cb3cae1582bb2" } diff --git a/testing/backend/unit/test_capabilities.py b/testing/backend/unit/test_capabilities.py index ff99e36e1..4815e9dd6 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 90dfac850..16e6e3c5b 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. """ import pytest @@ -22,6 +22,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") @@ -55,9 +60,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 8be61ef7a..4906f7a01 100644 --- a/testing/backend/unit/test_plugin_capabilities_inventory.py +++ b/testing/backend/unit/test_plugin_capabilities_inventory.py @@ -234,11 +234,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