Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix: expand wildcard grants in generated inspection cases (#249)

Rudy Mizrahi Celekli5c9ccd3eebdd
diff --git a/ifixai/core/discovery.py b/ifixai/core/discovery.py
index 7da97a6..c3ba4c0 100644
--- a/ifixai/core/discovery.py
+++ b/ifixai/core/discovery.py
@@ -188,6 +188,8 @@ def generate_test_cases(
# stable role id used by their permission matrix and user identities.
role_key = role.role_id if role.role_id and role.role_id in perm_map else role.name
allowed = perm_map.get(role_key, set())
+ if "*" in allowed:
+ allowed = all_tool_ids
denied = all_tool_ids - allowed
# Set iteration depends on PYTHONHASHSEED. Sort before assigning case
diff --git a/ifixai/inspections/b01_tool_governance/runner.py b/ifixai/inspections/b01_tool_governance/runner.py
index 01feffb..5b4201c 100644
--- a/ifixai/inspections/b01_tool_governance/runner.py
+++ b/ifixai/inspections/b01_tool_governance/runner.py
@@ -518,8 +518,9 @@ def _build_capability_missing_evidence() -> EvidenceItem:
def _build_role_tool_map(fixture: Fixture) -> dict[str, set[str]]:
"""Return mapping of role → set of permitted tool_ids from fixture permissions."""
role_tools: dict[str, set[str]] = {}
+ known_tools = {tool.tool_id for tool in fixture.tools}
for perm in fixture.permissions:
- role_tools.setdefault(perm.role, set()).update(perm.tools)
+ role_tools.setdefault(perm.role, set()).update(known_tools if "*" in perm.tools else perm.tools)
return role_tools
diff --git a/ifixai/inspections/b08_privilege_escalation/runner.py b/ifixai/inspections/b08_privilege_escalation/runner.py
index 321ed3c..ac83428 100644
--- a/ifixai/inspections/b08_privilege_escalation/runner.py
+++ b/ifixai/inspections/b08_privilege_escalation/runner.py
@@ -255,8 +255,9 @@ async def _holdout_escalation_inspections(
def build_allowed_tools(fixture: Fixture) -> dict[str, set[str]]:
role_tools: dict[str, set[str]] = {}
+ known_tools = {tool.tool_id for tool in fixture.tools}
for perm in fixture.permissions:
- role_tools.setdefault(perm.role, set()).update(perm.tools)
+ role_tools.setdefault(perm.role, set()).update(known_tools if "*" in perm.tools else perm.tools)
user_tools: dict[str, set[str]] = {}
for user in fixture.users:
diff --git a/ifixai/tests/test_discovery_wildcard_cases.py b/ifixai/tests/test_discovery_wildcard_cases.py
new file mode 100644
index 0000000..d2cd810
--- /dev/null
+++ b/ifixai/tests/test_discovery_wildcard_cases.py
@@ -0,0 +1,53 @@
+import pytest
+
+from ifixai.core.discovery import generate_test_cases
+from ifixai.core.types import Permission, Role, Tool
+
+
+def test_wildcard_permissions_generate_real_allow_cases():
+ cases = generate_test_cases(
+ [Role(name="admin")],
+ [Permission(role="admin", tools=["*"])],
+ [Tool(tool_id="read", name="Read"), Tool(tool_id="delete", name="Delete")],
+ )
+ assert {(case.tool_id, case.expected_result) for case in cases} == {
+ ("read", "allow"),
+ ("delete", "allow"),
+ }
+ assert all(case.test == "B01" for case in cases)
+
+
[email protected]("test_id", ["B01", "B08"])
+async def test_b01_and_b08_probe_actual_tools_granted_by_wildcard(test_id):
+ from ifixai.core.types import (
+ Fixture,
+ ProviderCapabilities,
+ ProviderConfig,
+ ToolInvocationResult,
+ User,
+ )
+ from ifixai.inspections.b01_tool_governance.runner import B01ToolGovernance
+ from ifixai.inspections.b08_privilege_escalation.runner import (
+ B08PrivilegeEscalation,
+ )
+ from ifixai.providers.base import ChatProvider
+
+ class OwnedWildcardProvider(ChatProvider):
+ async def send_message(self, messages, config):
+ return "owned reply"
+ async def authorize_tool(self, tool_id, user_role, config):
+ return ToolInvocationResult(authorized=user_role == "ci_pipeline", executed=False, policy_rule="owned wildcard policy")
+ async def invoke_tool(self, tool_id, user_role, params, config):
+ return ToolInvocationResult(authorized=user_role == "ci_pipeline", executed=user_role == "ci_pipeline", policy_rule="owned wildcard policy")
+
+ fixture = Fixture.model_construct(users=[User(user_id="ci", name="ci", roles=["ci_pipeline"])],
+ permissions=[Permission(role="ci_pipeline", tools=["*"])],
+ tools=[Tool(tool_id=f"tool_{i}", name=f"Tool {i}") for i in range(24)])
+ for inspection in [B01ToolGovernance() if test_id == "B01" else B08PrivilegeEscalation()]:
+ inspection.capabilities = ProviderCapabilities(has_authorization=True, has_tool_calling=True)
+ evidence = await inspection.run(OwnedWildcardProvider(), ProviderConfig(provider="owned"), fixture)
+ probes = [e for e in evidence if e.test_case_id.startswith(("B01-auth-ci-", "B08-struct-ci-"))]
+ assert len(probes) == (24 if test_id == "B01" else 0)
+ assert all(e.passed for e in probes)
+ # B08 only probes attempts to escalate into tools outside the grant.
+ # A wildcard user must have no ordinary unauthorized-tool probes.