CClaude Code Catalog
전체 가이드

보안 모범 사례

중급 7 min

Claude Code는 파일 시스템에 광범위하게 접근하고 명령을 실행할 수 있어 보안 설정이 필수적입니다. 이 가이드에서는 API 키와 자격 증명 같은 민감한 데이터 보호, 적절한 권한 경계 설정, AI 생성 코드의 취약점 감사, Hooks를 활용한 보안 정책 자동 적용 방법을 다룹니다. 이 방법론을 따르면 프로젝트의 보안 수준을 저하시키지 않으면서 Claude Code의 기능을 최대한 활용할 수 있습니다.

보안시크릿권한감사Hooks

시크릿 및 자격 증명 보호

The first rule of using Claude Code securely is ensuring that secrets never enter the conversation context. API keys, database passwords, authentication tokens, and other credentials should be stored in .env files that are excluded from Claude's reach. Add .env and similar files to your .claudeignore to prevent accidental reads. Beyond file-level exclusion, be mindful of secrets that might appear in unexpected places: hardcoded values in configuration files, credentials in docker-compose.yml, tokens in CI configuration, or passwords in database seed files. A comprehensive .claudeignore should cover all these patterns. When Claude needs to work with services that require authentication, use environment variable references rather than actual values. Instruct Claude to write code that reads from process.env rather than embedding credentials. Add this as an explicit rule in your CLAUDE.md so Claude never suggests inline secrets.
# .claudeignore - exclude all secret-containing files .env .env.* *.pem *.key credentials.json service-account.json docker-compose.override.yml # CLAUDE.md security section # Security Rules - NEVER read or output .env file contents - NEVER hardcode API keys, tokens, or passwords - Always use environment variables: process.env.API_KEY - Never log sensitive data (tokens, passwords, PII) - Use parameterized queries for all database operations

권한 경계 설정

Claude Code can read files, write files, and execute shell commands. Configuring appropriate boundaries for these capabilities is crucial. Use the permission system to restrict which directories Claude can modify and which commands it can execute without approval. For most projects, a sensible default is to allow reads broadly but restrict writes to source directories only. Prevent writes to configuration files, CI pipelines, and infrastructure code unless explicitly approved. This prevents accidental changes to critical operational files during routine coding tasks. For shell command execution, maintain an allowlist of safe commands. Build tools, test runners, and linters are generally safe. Commands that modify system configuration, access the network, or manage infrastructure should require explicit confirmation. This layered approach lets Claude be productive while maintaining human oversight for high-impact operations.
# Configure permission boundaries in settings # Allow file reads everywhere except secrets claude config set permissions.read "src/**,tests/**,docs/**" # Restrict writes to source code only claude config set permissions.write "src/**,tests/**" # Safe commands that can run without confirmation claude config set permissions.allowedCommands \ "npm test,npm run lint,npm run build,npx tsc --noEmit" # Commands that always require confirmation # (default behavior for destructive operations) # rm, git push, docker, kubectl, etc.

AI 생성 코드 감사

AI-generated code can introduce subtle security vulnerabilities that are easy to miss in review. Common issues include insufficient input validation, improper error handling that leaks internal details, SQL injection through string concatenation, and missing authentication checks on new endpoints. Establish an audit checklist specifically for AI-generated code. Check that all user inputs are validated and sanitized, that error messages do not expose stack traces or internal paths, that database queries use parameterized statements, and that new API endpoints include proper authentication and authorization middleware. Automate what you can. Run static analysis tools like ESLint security plugins, Semgrep, or Snyk on every PR that includes AI-generated code. Add these checks to your CI pipeline so they catch common vulnerability patterns before code reaches production. Claude Code can even help set up these checks as part of your security workflow.
# Add security-focused ESLint rules npm install --save-dev eslint-plugin-security # .eslintrc.js module.exports = { plugins: ['security'], rules: { 'security/detect-object-injection': 'warn', 'security/detect-non-literal-regexp': 'warn', 'security/detect-unsafe-regex': 'error', 'security/detect-eval-with-expression': 'error', 'security/detect-no-csrf-before-method-override': 'error', } }; # Run security audit as part of CI npx semgrep --config=p/javascript-security src/

보안 Hooks 및 자동화

Claude Code hooks let you run custom scripts before or after specific events, making them perfect for automated security enforcement. A PreToolUse hook can inspect commands before execution, blocking dangerous operations. A PostToolUse hook can scan generated code for security issues immediately after creation. A practical PreToolUse hook checks shell commands against a blocklist of dangerous patterns: commands that delete files outside the project, commands that access network resources without approval, or commands that modify system configuration. This acts as a safety net even if permission boundaries are misconfigured. Combine hooks with your CLAUDE.md security rules for defense in depth. The CLAUDE.md tells Claude what it should do, while hooks enforce what it must do. This dual-layer approach ensures security even when prompts are ambiguous or when Claude misinterprets instructions.
# .claude/hooks/pre-command.sh #!/bin/bash # Block dangerous command patterns BLOCKED_PATTERNS=( "rm -rf /" "curl.*|.*sh" "chmod 777" "git push.*--force.*main" "DROP TABLE" "DROP DATABASE" ) for pattern in "${BLOCKED_PATTERNS[@]}"; do if echo "$1" | grep -qE "$pattern"; then echo "BLOCKED: Command matches dangerous pattern: $pattern" exit 1 fi done exit 0 # Register the hook # claude config add hooks.PreToolUse ".claude/hooks/pre-command.sh"

실행 미리보기

보안 모범 사례

보안 모범 사례에 대해

Claude Code 가이드는 Claude Code의 특정 측면을 마스터하기 위한 심층적인 단계별 안내를 제공합니다. 보안 모범 사례은(는) 중급 수준의 가이드로, 일상 워크플로우에서 Claude Code를 최대한 활용하기 위한 베스트 프랙티스, 실전 기법, 실용적인 팁을 안내합니다.

관련 가이드