Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions backend/secuscan/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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)


Expand Down
3 changes: 1 addition & 2 deletions plugins/waf_detector/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@
"python_packages": [],
"system_packages": []
},
"capabilities": ["network"],
"checksum": "ac518fd15fe9a14f9327812178fd244ebaa2ee95d29d04b93ee928fa3fda7ffa"
"checksum": "60b54af15ff7bad498a02cdbf08ee8611622e117944a3a65301cb3cae1582bb2"
}
10 changes: 5 additions & 5 deletions testing/backend/unit/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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"])
Expand Down
15 changes: 10 additions & 5 deletions testing/backend/unit/test_capabilities_effective.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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."""
Expand Down
7 changes: 3 additions & 4 deletions testing/backend/unit/test_plugin_capabilities_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading