Back to Skills

security-audit-codebase

pjt222
Updated Yesterday
6 views
17
2
17
View on GitHub
Developmentapi

About

This skill performs a comprehensive security audit of a codebase, scanning for exposed secrets, vulnerable dependencies, injection flaws, and OWASP Top 10 issues. It's designed for use before deployment, during periodic reviews, or when preparing for compliance audits. Developers can run it to automatically identify critical security vulnerabilities and misconfigurations.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/security-audit-codebase

Copy and paste this command in Claude Code to install this skill

Documentation

安全審碼庫

行系統之安審於碼庫,以識其患與洩之密。

用時

  • 發布或展項目之前乃用
  • 既有項目之周期安審乃用
  • 加認證、API 集、或用入處理之後乃用
  • 私庫開源之前乃用
  • 備合規之安審乃用

  • 必要:所審之碼庫
  • 可選:特察之處(密、依、注入、認證)
  • 可選:合規之框(OWASP、ISO 27001、SOC 2)
  • 可選:前審之得以比

第一步:掃洩之密

搜硬編密之模:

# API keys and tokens
grep -rn "sk-\|ghp_\|gho_\|github_pat_\|hf_\|AKIA" --include="*.{md,js,ts,py,R,json,yml,yaml}" .

# Generic secret patterns
grep -rn "password\s*=\s*['\"]" --include="*.{js,ts,py,R,json}" .
grep -rn "api[_-]key\s*[=:]\s*['\"]" --include="*.{js,ts,py,R,json}" .
grep -rn "secret\s*[=:]\s*['\"]" --include="*.{js,ts,py,R,json}" .

# Connection strings
grep -rn "postgresql://\|mysql://\|mongodb://" .

# Private keys
grep -rn "BEGIN.*PRIVATE KEY" .

得:未得實密——唯占位如 YOUR_TOKEN_HERE[email protected]

敗則:得實密,立刪之,輪換洩之憑據,以 git filter-branchgit-filter-repo 清史。視所洩之密為已破。

第二步:察 .gitignore 之覆

驗敏文件已排:

# Check that these are git-ignored
git check-ignore .env .Renviron credentials.json node_modules/

# Look for tracked sensitive files
git ls-files | grep -i "\.env\|\.renviron\|credentials\|secret"

得:諸敏文件(.env.Renvironcredentials.json)皆列於 .gitignoregit ls-files 返無敏之追蹤文件。

敗則:敏文件已追,行 git rm --cached <file> 以解,加入 .gitignore,提交。文件留於盤而不再受版控。

第三步:審依

Node.js

npm audit
npx audit-ci --moderate

Python

pip-audit
safety check

R

# Check for known vulnerabilities in packages
# No built-in tool, but verify package sources
renv::status()

得:依無高或要患。中與低之患書以審。

敗則:得要患,立以 npm audit fixpip install --upgrade 更受影之包。更若引破,書其患而立修之計。

第四步:察注入之患

SQL 注入

# Look for string concatenation in queries
grep -rn "paste.*SELECT\|paste.*INSERT\|paste.*UPDATE\|paste.*DELETE" --include="*.R" .
grep -rn "query.*\+.*\|query.*\$\{" --include="*.{js,ts}" .

諸庫之查皆宜用參查,非串拼。

命注入

# Look for shell execution with user input
grep -rn "system\(.*paste\|exec(\|spawn(" --include="*.{R,js,ts,py}" .

XSS(跨站本)

# Look for unescaped user content in HTML
grep -rn "innerHTML\|dangerouslySetInnerHTML\|v-html" --include="*.{js,ts,jsx,tsx,vue}" .

得:無 SQL、命、XSS 注入之路。諸庫查用參、殼命避用控之入、HTML 出皆轉義。

敗則:得注入,以參查代查中之串拼,殼行前淨或轉用之入,以框安之渲法代 innerHTMLdangerouslySetInnerHTML

第五步:審認證與授權

清單:

  • 密以 bcrypt/argon2 散(非 MD5/SHA1)
  • 會話令隨機而足長
  • 認證令有期
  • API 端察授權
  • CORS 嚴配
  • 變態之操啟 CSRF 之護

得:諸項皆過:密用強散、令隨機有期、端強授權、CORS 嚴、CSRF 護活。

敗則:依重排修:弱散與缺授權為要,CORS 與 CSRF 為高。書諸得附其重等。

第六步:察配之安

# Debug mode in production configs
grep -rn "debug\s*[=:]\s*[Tt]rue\|DEBUG\s*=\s*1" --include="*.{json,yml,yaml,toml,cfg}" .

# Permissive CORS
grep -rn "Access-Control-Allow-Origin.*\*\|cors.*origin.*\*" --include="*.{js,ts}" .

# HTTP instead of HTTPS
grep -rn "http://" --include="*.{js,ts,py,R}" . | grep -v "localhost\|127.0.0.1\|http://"

得:生產配中 debug 模已禁,CORS 不用通配,諸外網址用 HTTPS。

敗則:生產配 debug 模啟,立禁之。以明域代通配 CORS。將 http:// 之網址更為 https://,若端支之。

第七步:書其得

立審報:

# Security Audit Report

**Date**: YYYY-MM-DD
**Auditor**: [Name]
**Scope**: [Repository/Project]
**Status**: [PASS/FAIL/CONDITIONAL]

## Findings Summary

| Category | Status | Details |
|----------|--------|---------|
| Exposed secrets | PASS | No secrets found |
| .gitignore | PASS | Sensitive files excluded |
| Dependencies | WARN | 2 moderate vulnerabilities |
| Injection | PASS | Parameterized queries used |
| Auth/AuthZ | N/A | No authentication in scope |
| Configuration | PASS | Debug mode disabled |

## Detailed Findings

### Finding 1: [Title]
- **Severity**: Low / Medium / High / Critical
- **Location**: `path/to/file:line`
- **Description**: What was found
- **Recommendation**: How to fix
- **Status**: Open / Resolved

## Recommendations
1. Update dependencies to fix moderate vulnerabilities
2. [Additional recommendations]

得:完備之 SECURITY_AUDIT_REPORT.md 存於項目根,諸得依重分,各附特位、述、議。

敗則:得繁難一一書,依類聚而先要/高之得。無論結,皆生報以立基線。

  • 源無硬編之密
  • .gitignore 覆諸敏文件
  • 依無高/要之患
  • 無注入之患
  • 認證已正施(若適)
  • 審報完備,諸得已處

  • 唯察當前之文件:git 史中之密仍洩。以 git log -p --all -S 'secret_pattern'
  • 忽開發之依:開發之依仍可引供應鏈之險
  • .gitignore 之假安.gitignore 唯阻後追。已提交之文件需 git rm --cached
  • 忽配文件docker-compose.yml、CI 配、展本常含密
  • 不輪換已破之憑據:得而刪密不足。憑據必廢而再生

  • configure-git-repository — 正之 .gitignore 設
  • write-claude-md — 書安之求
  • setup-gxp-r-project — 受規之境之安

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan/skills/security-audit-codebase
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

qmd

Development

qmd is a local search and indexing CLI tool that enables developers to index and search through local files using hybrid search combining BM25, vector embeddings, and reranking. It supports both command-line usage and MCP (Model Context Protocol) mode for integration with Claude. The tool uses Ollama for embeddings and stores indexes locally, making it ideal for searching documentation or codebases directly from the terminal.

View skill

subagent-driven-development

Development

This skill executes implementation plans by dispatching a fresh subagent for each independent task, with code review between tasks. It enables fast iteration while maintaining quality gates through this review process. Use it when working on mostly independent tasks within the same session to ensure continuous progress with built-in quality checks.

View skill

mcporter

Development

The mcporter skill enables developers to manage and call Model Context Protocol (MCP) servers directly from Claude. It provides commands to list available servers, call their tools with arguments, and handle authentication and daemon lifecycle. Use this skill for integrating and testing MCP server functionality in your development workflow.

View skill

adk-deployment-specialist

Development

This skill deploys and orchestrates Vertex AI ADK agents using A2A protocol, managing AgentCard discovery, task submission, and supporting tools like Code Execution Sandbox and Memory Bank. It enables building multi-agent systems with sequential, parallel, or loop orchestration patterns in Python, Java, or Go. Use it when asked to deploy ADK agents or orchestrate agent workflows on Google Cloud.

View skill