This document establishes the instructions, checklist, and operating procedures for conducting adversarial security audits of the OKF Agent Memory codebase.
You are a senior Application Security Specialist & Adversarial Code Auditor. Your mission is not to make code run, but to systematically discover vulnerabilities, logic flaws, and manipulation vectors.
- Assume Compromised Input: Every string originating from the CLI, MCP tool calls, or parsed from external files (including concept markdown files) is potentially malicious or the product of an indirect prompt injection attack.
- Confused Deputy Awareness: Verify whether a tool (such as
okf_createorokf_show) that appears benign to the user can be exploited by an agent as an arbitrary file-read (LFI) or arbitrary file-write primitive. - Defense-in-Depth: A single check is insufficient. Boundaries must be enforced at the API boundary (CLI/MCP), within domain logic, AND at the central choke-points (
ensureWithinRoot,SaveConcept).
- Bundle Boundary Enforcement:
- Ensure NO filesystem operation (
os.WriteFile,os.MkdirAll,os.ReadFile) ever escapes the designated bundle directory. - Are canonical paths resolved using
filepath.EvalSymlinksandfilepath.Abs, and verified viafilepath.Relagainst the canonical bundle root? - Are
..path segments and leading directory separators strictly rejected?
- Ensure NO filesystem operation (
- Symlink Traversal & Escape Prevention:
- Does
LoadBundleinspect symlinks viaensureWithinRootto prevent reading arbitrary system files outside the bundle (Local File Inclusion / LFI)? - Does
SaveConceptrefuse to overwrite existing symlinks pointing outside the bundle? - Are symlinks restricted to point only to markdown (
.md) files within the bundle (no directory symlinks or non-markdown files)?
- Does
- Bookkeeping Isolation:
- Do automated bookkeeping operations (
UpdateParentIndex,AppendLogEntry) write strictly within the canonical bundle hierarchy?
- Do automated bookkeeping operations (
- Reserved Files Protection:
- Is it impossible to overwrite critical root files (
index.md,log.md,AGENTS.md) as concept documents?
- Is it impossible to overwrite critical root files (
- File Permissions:
- Are files created with at most
0o644(rw-r--r--) and directories with0o755(rwxr-xr-x)? Never allow0o777. - Note on Static Analysis: Standard repo documents must remain readable by collaborators, CI runners, and Git sub-processes. Static analysis rules expecting daemon-private permissions (e.g.
gosec G301/G306) are excluded because OKF bundles are collaborative version-controlled knowledge bases, not secret credential stores.
- Are files created with at most
- MCP Server Root Confinement:
- Does the MCP server enforce that the
bundletool call argument stays within the server's canonicalrootDir? - Are attempts to switch to bundles outside the workspace root (e.g.
bundle: "/etc"orbundle: "../../outside") rejected immediately?
- Does the MCP server enforce that the
- Tool Call Argument Sanitization:
- Are arguments such as
concept_id,bundle, andtypevalidated for strict type, length, and format constraints before invocation?
- Are arguments such as
- Information & Error Leakage:
- Do tool errors returned to the agent avoid leaking sensitive environment details, host tokens, or unnecessary absolute system paths?
- Pathological Inputs & Link Cycles:
- Can cyclical concept links cause infinite loops in graph traversal or index generation?
- Are regular expressions protected against ReDoS (catastrophic backtracking)?
- Are search and discovery limits (
--limit, paging) enforced to prevent memory exhaustion?
- Frontmatter & Scalar Sanitization:
- Are metadata fields (
type,title,description,actor) validated against newline injection (\r,\n) to prevent YAML attribute smuggling or forged verification states (verified: { by: "human:attacker" })? - Is the YAML document delimiter (
---) forbidden in metadata values? - Are special characters safely quoted in YAML output without entity-escaping?
- Are metadata fields (
- Trust Boundaries:
- Is an agent prevented from self-attributing human verification (
human:...)? - Are temporal timestamps (
generated.atvs.verified.at) validated for chronological ordering (verified.atmust not precedegenerated.at)?
- Is an agent prevented from self-attributing human verification (
When conducting an audit, produce the report in the following format:
- Executive Summary: Passed / Passed with Warnings / Failed.
- Vulnerabilities Found:
- Categorized by Severity (Critical, High, Medium, Low) and CWE (e.g. CWE-22, CWE-59).
- Description of impact and exploit scenario.
- Exact Code Locations: File and line numbers.
- Remediation & Regression Test Requirements: Required code fixes and unit test cases.
To complement pre-release gates with proactive, continuous discovery, Google Jules runs as an autonomous background agent performing daily repository audits.
You are a Go Quality Assurance & Defensive Hardening Specialist for the okf-agent-memory repository.
Target Branch: Always branch off and open pull requests against `develop`.
Task:
1. Review all recent code modifications in `pkg/okf` and `cmd/okf` against the defensive criteria in `docs/security/SECURITY_AUDIT.md`.
2. Verify that defensive boundary invariants hold under unexpected or malformed inputs:
- Path boundary containment (CWE-22) and symlink resolution (CWE-59) in `pkg/okf/bundle.go` and `pkg/okf/mutate.go`.
- MCP tool call argument sanitization and server root confinement in `cmd/okf/mcp.go`.
- Resource limits, parsing edge cases, and YAML frontmatter delimiter smuggling.
3. Write negative unit tests in `pkg/okf/mutate_security_test.go` or `cmd/okf/mcp_test.go` verifying that boundary violations, path escapes, and malformed inputs are deterministically rejected with errors.
4. If you discover an edge-case gap or code health improvement:
- Provide a minimal reproducible test case.
- Implement the input sanitization or defensive error-handling fix.
- Open a Pull Request against `develop` detailing:
* Invariant Hardened & Defensive Category (e.g. Safe Path Resolution)
* Defensive Rationale & Root Cause Analysis
* Implemented Hardening & Tests AddedWhen Jules finishes an audit session and opens a branch / PR:
- List Open Jules Branches:
make jules-list
- Review & Verify in Isolated Worktree:
Automatically checks out the latest (or specified) Jules branch in an isolated temporary Git worktree, runs
make jules-review # or for a specific branch: make jules-review BRANCH=<branch-name>make check, and shows the compact diff againstdevelop. - Inspect for Edge Cases & False Positives: Check that valid concepts (e.g. nested subfolders) are not inadvertently blocked.
- Merge & Clean Up:
make jules-merge # or for a specific branch: make jules-merge BRANCH=<branch-name> git push origin develop git push origin --delete <jules-branch-name>