Leak Shield: Data Leak & PII Protection Skill
This skill guides you through checking a workspace or directory for credentials, secrets, PII (Personally Identifiable Information), and GDPR vulnerabilities, and interactive remediation.
Step-by-Step Execution Guide
1. Verification of Runtime Environment
- Check if Node.js is installed in the environment by executing:
node --version - If Node.js is available, proceed to Step 2A (Fast Programmatic Scan).
- If Node.js is NOT available, proceed to Step 2B (Agent Fallback Search).
2A. Fast Programmatic Scan (Recommended)
- Run the scanning script, pointing it at the workspace you want to scan. The script
lives inside this skill's own directory (e.g.
~/.agents/skills/leak-shield/), which is usually not the project being scanned, so pass the target directory explicitly:node "<path-to-this-skill>/scripts/detect.js" "<path-to-workspace>"<path-to-this-skill>is the directory containing this SKILL.md. If you have alreadycd'd into the workspace, you can omit the second argument and it defaults to the current directory:node "<path-to-this-skill>/scripts/detect.js" - Parse the JSON output from the command. The output will contain a structured array of findings:
[ { "file": "path/to/file.js", "line": 42, "category": "Secrets/Credentials", "leakType": "Generic API Key", "matchedText": "const apiKey = 'AIzaSyExampleKey123';", "obfuscated": "const apiKey = 'AIzaSy...xxxx';" } ] - Skip to Step 3 (Analysis & De-duplication).
2B. Agent Fallback Search (Manual Regex)
- If the scanner script cannot run, read the reference pattern library to load the search patterns:
Read references/leak-patterns.md - Execute a search using your search tools (e.g.,
grep_searchor systemripgrep) across the workspace using the regexes fromreferences/leak-patterns.md. - Filter out directories to avoid performance hangs:
- Exclude
node_modules/,.git/,build/,dist/,.next/,.nuxt/. - Honor exclusions in
.gitignore,.npmignore,.aiignore, and.cursorignorefiles if present.
- Exclude
3. Analysis & De-duplication
- Analyze the matched lines. Filter out:
- Obvious standard system port numbers (e.g.,
3000,8080). - Explicitly documented testing placeholders (e.g.,
placeholder@example.com,your-api-key-here). - Read-only test files (e.g., mock data in
__tests__/or*.test.js), unless they contain actual live credentials.
- Obvious standard system port numbers (e.g.,
- Group the remaining findings by file and line number.
4. Interactive Remediation Prompt
- Present the filtered findings to the user as a clean markdown table.
- CRITICAL: Do NOT show full API keys or private credentials in the chat. Use the obfuscated string (e.g., show
AIzaSy...xxxxinstead of the full key) to prevent secondary leaks in agent logs. - For each finding, prompt the user with a numbered list of choices:
- [1] Delete/Remove Line/Value: Safely delete the hardcoded value or remove the line if it is obsolete.
- [2] Extract to Environment Variable: Replace the hardcoded string with a dynamic reference (e.g.,
process.env.MY_SECRET) and append the key-value pair to a local.envfile. - [3] Hide from Future Scanning / Git:
- Option A: Add the file path to
.gitignore(ignores from Git commits). - Option B: Add the file path to
.aiignore(specifically shields it from future AI agent indexing and scans).
- Option A: Add the file path to
- [4] Whitelist/Keep: Ignore the finding as a false positive or acceptable mock data (either just for this run, or permanently append the matched raw string to
.leakwhitelistin the workspace root to skip it in all future scans).
- DO NOT modify any files automatically. Wait for the user to specify their choices (e.g., "Do Option 2 for finding 1, Option 4 (permanent) for finding 2").
5. Executing Remediations
- Based on the user's choices, modify files carefully:
- To replace a secret, use exact line edits (
replace_file_content). - To append to
.gitignore,.aiignore, or.leakwhitelist, use a file edit/write tool, ensuring each entry is on a new line. When adding a permanent whitelist value, append the exact matched raw string (e.g.,BE68 5390 0754 7034) to.leakwhitelist.
- To replace a secret, use exact line edits (
- Ensure you do not introduce syntax errors during line deletions or variable replacements.
6. Post-Remediation Verification
- Re-run the scan script (same invocation as Step 2A) or native regex search to verify that the active leaks have been fully addressed:
node "<path-to-this-skill>/scripts/detect.js" "<path-to-workspace>" - Confirm to the user that the project is now safe from accidental leaks before they execute git commits or pushes.
Pattern-Matching Examples
Example 1: Credential Leak in Configuration File
Scan Input:
File: src/config/database.js
Line: 12
Matched Text: const dbUri = "mongodb+srv://admin:P@ssw0rd123!@cluster0.mongodb.net/prod";
Agent Output to User:
### ⚠️ 1 Potential Leak Found in your Workspace!
| File | Line | Category | Description | Matched String (Obfuscated) |
| :--- | :--- | :--- | :--- | :--- |
| `src/config/database.js` | 12 | Secrets/Credentials | MongoDB Connection String | `const dbUri = "mongodb+srv://admin:******@cluster0.mongodb.net/prod";` |
How would you like to handle this finding?
* **[1]** Delete/Remove the connection string.
* **[2]** Extract to Environment Variable (`process.env.DB_URI`) and append to `.env`.
* **[3]** Add `src/config/database.js` to `.gitignore` / `.aiignore`.
* **[4]** Ignore (false positive).
Troubleshooting
| Error / Failure | Root Cause | Fix |
|---|---|---|
SyntaxError: Unexpected token |
Running scanner on a file with unsupported syntax. | The scanner script handles file parsing safely with regex; if a custom tool errors, exclude the directory or file extension. |
Node command fails with MODULE_NOT_FOUND or Cannot find module |
The script path is wrong — the skill is installed outside the project, so a relative leak-shield/scripts/detect.js won't resolve. |
Use the absolute path to this skill's scripts/detect.js and pass the workspace as the argument (see Step 2A). |
| Scanner reports zero findings on a project you expect to have leaks | Likely scanning the wrong directory (default is the current working directory). | Pass the target workspace explicitly as the second argument: node "<skill>/scripts/detect.js" "<workspace>". |
| Scan returns hundreds of mock credentials | Scanning third-party dependencies or build files. | Exclude folders like node_modules/ or build folders using .aiignore or .gitignore. |
| Script execution permission denied | Shell sandbox blocking node process. | Ask the user to run the script or execute it using the agent's explicit shell command run tool. |