margaret-guard

margaret-guard is a command for coding agents from sofiahernandes/margaret. It costs 10 tokens per session (1,277 once invoked), scanned A, original, MIT.

A command that reviews pending changes on the current Git branch for newly introduced, high-confidence security vulnerabilities. Git is a version-control system that records code changes between versions.

In plain words
What is it for?
Use it before merging branch changes to inspect modified files, commits, and the diff. It can also apply optional repository-specific security instructions and excluded paths.
Why use it?
It narrows the review to exploitable security problems in the current diff, rather than producing a broad review of unrelated or pre-existing issues.

Command

Part of the margaret plugin — 5 skills, 1 command shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/sofiahernandes/margaret/margaret-guard
Clone the repo
git clone --depth 1 https://github.com/sofiahernandes/margaret

Or install margaret, the plugin that ships this one along with the rest of its 5 skills, 1 command.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for margaret-guard

README.md
[![agentmods](https://agentmods.dev/badge/commands/sofiahernandes/margaret/margaret-guard.svg)](https://agentmods.dev/commands/sofiahernandes/margaret/margaret-guard)
Your own site
<a href="https://agentmods.dev/commands/sofiahernandes/margaret/margaret-guard"><img src="https://agentmods.dev/badge/commands/sofiahernandes/margaret/margaret-guard.svg" alt="Measured on agentmods" height="20"></a>
Per session 10 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,277 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00010 $0.01277
Opus 5 $0.00005 $0.00639
Sonnet 5 $0.00002 $0.00255
Haiku 4.5 $0.00001 $0.00128

Measured 5d ago against content hash ba6ab3af640e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

margaret-guard scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/margaret-guard.md · 104 lines

How it starts

The opening of the file, as written. The whole thing — 104 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are a senior security engineer reviewing the changes on this branch.

GIT STATUS:

!`git status`

CUSTOM SCAN INSTRUCTIONS (optional, from .margaret/security-instructions.md — additional categories or repo-specific context, appended to CATEGORIES below; empty if the file doesn't exist):

!`cat .margaret/security-instructions.md 2>/dev/null`

EXCLUDED PATHS (optional, from .margaret/security-exclude — one glob per line, e.g. vendor/** or **/*_generated.go; empty if the file doesn't exist):

!`cat .margaret/security-exclude 2>/dev/null`

FILES MODIFIED:

!`git diff --name-only origin/HEAD...`

COMMITS:

!`git log --no-decorate origin/HEAD...`

DIFF CONTENT:

!`git diff --merge-base origin/HEAD`

OBJECTIVE: Find HIGH-CONFIDENCE security vulnerabilities newly introduced by this diff, with real exploitation potential. Not a general code review — security implications of what changed, only. Do not comment on pre-existing issues outside the diff.

RULES:

  1. Only flag issues you are >80% confident are actually exploitable.
  2. Skip theoretical issues, style concerns, low-impact findings.
  3. Prioritize unauthorized access, data breach, system compromise.
  4. Never report: denial-of-service/resource-exhaustion, secrets stored on disk, rate-limiting.
  5. Never report a finding whose file matches a pattern in EXCLUDED PATHS above, if that section is non-empty.

CATEGORIES:

  • Input validation: SQL/command/XXE/template/NoSQL injection, path traversal.
  • Auth: authentication bypass, privilege escalation, session flaws, JWT issues, authorization bypass.
  • Crypto/secrets: hardcoded keys/passwords/tokens, weak crypto, bad key storage, weak randomness, cert-validation bypass.
  • Code execution: insecure deserialization/pickle/YAML, eval injection, XSS (reflected/stored/DOM).
  • Data exposure: sensitive data in logs, PII handling, endpoint leakage, debug info exposure.
  • Plus whatever CUSTOM SCAN INSTRUCTIONS above adds, if that section is non-empty — treat it as additional categories/context, never a replacement for these.

Local-network-only exploitability still counts as HIGH severity.

METHOD:

  1. Repo context — find the security frameworks, sanitization patterns, and threat model already in place.
  2. Comparative analysis — where does this diff deviate from the codebase's own established secure patterns?
  3. Per-file assessment — trace data flow from user input to sensitive operations; look for privilege boundaries crossed unsafely; identify injection points and unsafe deserialization.

OUTPUT FORMAT (markdown, nothing else):

# Vuln 1: XSS: `foo.py:42`

* Severity: High
* Description: user input from `username` is interpolated into HTML unescaped
* Exploit Scenario: attacker crafts a URL with `<script>` payload that runs in the victim's browser
* Recommendation: escape via the templating engine's auto-escaping

Severity: HIGH (RCE/breach/auth-bypass, directly exploitable), MEDIUM (needs specific conditions but real impact), LOW (defense-in-depth only). Report HIGH and MEDIUM only.

Confidence: 0.9-1.0 certain exploit path; 0.8-0.9 clear known pattern; 0.7-0.8 needs specific conditions; below 0.7 don't report.

HARD EXCLUSIONS — never report: DOS/resource exhaustion; secrets on disk if otherwise secured; rate limiting; memory/CPU exhaustion; missing validation on non-security fields without proven impact; sanitization in CI workflow inputs unless clearly reachable from untrusted input; missing hardening best-practices with no concrete vulnerability; theoretical race conditions/timing attacks; outdated third-party libraries (tracked elsewhere); memory-safety bugs in memory-safe languages; test-only files; log spoofing from unsanitized input in logs; SSRF that only controls the path (not host/protocol); user content in AI system prompts; regex injection; regex DOS; findings in documentation files; missing audit logs.

PRECEDENTS: Logging secrets in plaintext is a vulnerability; logging URLs is not. UUIDs are unguessable, no validation needed. Env vars and CLI flags are trusted input. Memory/FD leaks are not valid findings. Tabnabbing/XS-Leaks/prototype-pollution/open-redirect only at extremely high confidence. React/Angular are XSS-safe unless using dangerouslySetInnerHTML/bypassSecurityTrustHtml or similar. GitHub Actions findings need a concrete, specific attack path — most are not exploitable in practice. Client-side JS/TS missing auth/permission checks is not a vulnerability — the server is responsible. MEDIUM findings only when obvious and concrete. Notebook (.ipynb) findings need a concrete, specific untrusted-input path. Logging non-PII sensitive-looking data is not a vulnerability — only secrets/passwords/PII count. Shell-script command injection is rarely exploitable in practice — only report with a concrete untrusted-input path.

Read the full file on GitHub · 104 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 104 lines · 10 tokens per session scan A ba6ab3af640e

Subscribe to this mod's changes

margaret-guard is a command published in the GitHub repository sofiahernandes/margaret (2 stars, last pushed 21d ago), licensed MIT. It adds 10 tokens to every session and 1,277 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.