Skip to content

AAK-POLICY-IMPORT-FAILOPEN-001: A failed import of a policy module leaves the gate open

Severity
HIGH
Category
Trust Boundaries (trust-boundary)
Scanner
agent_audit_kit/scanners/policy_failopen.py
Auto-fixable
No.
SARIF name
PolicyImportFailOpen

What it detects

An except ImportError or except ModuleNotFoundError around a policy, auth, validator or guard import allows when the import fails: its handler returns True or an allow value, turns an enforce flag off, binds a stub that allows, or does nothing while the code goes on to act; or a later test of the missing name goes ahead. A PreToolUse guard shaped like this allowed every mcp__* call for a policy module that did not exist, and its allow-path tests kept passing. A handler that raises, exits non-zero or denies does not fire, and neither does an optional import that is no policy (a YAML speedup, rich).

How to fix

Deny on the ImportError: raise, or exit with the code your gate reads as a refusal (2 for a Claude Code PreToolUse hook), and add a test that the policy module being missing denies, not only that the module being present allows correctly.

To confirm the finding is gone, report only this rule:

agent-audit-kit scan . --rules AAK-POLICY-IMPORT-FAILOPEN-001

Limitations

Reads Python source for a try that imports a module or a name with a policy word in it (policy, auth, valid*, guard*, permission*, acl, rbac, enforc*, secur*, sandbox*, allowlist*, firewall*, gate), word by word of a dotted or snake_case name, so a policy module named for something else (from checks import run) is not read, and a validator library imported for an unrelated purpose is. Only ImportError and ModuleNotFoundError handlers are read, so a bare except: or except Exception: is not. A name left as None or False is followed through later if tests in the same file; a test of it in another file is not, and with no later test nothing is reported, since calling None raises. A handler that passes counts only when the try itself calls the check and a call follows it in the same function. A source file over 512 KB is not read.

References

  • OWASP Agentic Top 10: ASI02 (Tool Misuse and Exploitation)
  • Adversa AI MCP Top 25 (AAK-defined ids): ADV-AUTH-01 (Missing Authentication)

All rules. This page is generated from the rule registry when the documentation is built; to change it, change the rule in agent_audit_kit/rules/builtin.py. To give the rule a hand-written write-up, add docs/rules/AAK-POLICY-IMPORT-FAILOPEN-001.md: the page then shows that text, with the registry reference appended under it.