eslint-plugin-secure-coding 시작하기

발행: (2026년 1월 1일 오전 06:31 GMT+9)
3 min read
원문: Dev.to

Source: Dev.to

eslint-plugin-secure-coding 시작하기를 위한 표지 이미지

빠른 설치

npm install --save-dev eslint-plugin-secure-coding

플랫 구성 (ESLint 9+)

// eslint.config.js
import secureCoding from 'eslint-plugin-secure-coding';

export default [secureCoding.configs.recommended];

ESLint 실행

npx eslint .

일반적인 출력:

src/auth.ts
  15:3  error  🔒 CWE-798 OWASP:A02 CVSS:7.5 | Hardcoded credential detected
               Fix: Use environment variable: process.env.DATABASE_PASSWORD

src/utils.ts
  42:5  error  🔒 CWE-95 OWASP:A03 CVSS:9.8 | Dangerous eval() with expression
               Fix: Replace eval() with safer alternatives like JSON.parse()

사용 가능한 프리셋

// Balanced for most projects
secureCoding.configs.recommended;

// Maximum security (all 75 rules as errors)
secureCoding.configs.strict;

// Web application compliance
secureCoding.configs['owasp-top-10'];

// Mobile apps (React Native)
secureCoding.configs['owasp-mobile-top-10'];

규칙 개요

카테고리규칙예시
인젝션 방지11eval(), 명령어 인젝션, GraphQL
암호학6약한 해시, 난수, 타이밍 공격
인증3하드코딩된 자격 증명, 약한 비밀번호
세션/쿠키3보안이 취약한 쿠키, 세션 고정
데이터 노출5로그에 포함된 개인 식별 정보(PII), 디버그 코드, 비밀
입력 검증8XSS, 경로 탐색, 프로토타입 오염
OWASP 모바일30보안이 취약한 저장소, 인증서 검증

규칙 맞춤 설정

// eslint.config.js
import secureCoding from 'eslint-plugin-secure-coding';

export default [
  secureCoding.configs.recommended,

  // Override specific rules
  {
    rules: {
      // Downgrade to warning
      'secure-coding/no-pii-in-logs': 'warn',

      // Disable if not applicable
      'secure-coding/detect-non-literal-fs-filename': 'off',

      // Configure options
      'secure-coding/no-hardcoded-credentials': [
        'error',
        {
          allowTestFiles: true,
        },
      ],
    },
  },
];

거짓 양성 무시

// eslint-disable-next-line secure-coding/no-hardcoded-credentials
const EXAMPLE_KEY = 'pk_test_example'; // Test fixture

또는 설정 파일에서:

{
  "files": ["**/*.test.ts"],
  "rules": {
    "secure-coding/no-hardcoded-credentials": "off"
  }
}

Source:

CI/CD 통합

GitHub Actions

# .github/workflows/security.yml
name: Security Lint

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npx eslint . --max-warnings 0

Pre‑commit 훅

npm install --save-dev husky lint-staged
npx husky init
// package.json
{
  "lint-staged": {
    "*.{js,ts}": "eslint --max-warnings 0"
  }
}

IDE 통합

VS Code

ESLint 확장 프로그램은 인라인으로 오류를 표시합니다, 예:

🔒 CWE-798 | Hardcoded credential detected

Cursor / Copilot

AI 어시스턴트는 구조화된 오류를 읽고 자동 수정 제안을 할 수 있습니다:

CWE-89 → Parameterized query fix
CWE-798 → Environment variable fix

빠른 참고

# Install
npm install --save-dev eslint-plugin-secure-coding

# Config (eslint.config.js)
import secureCoding from 'eslint-plugin-secure-coding';
export default [secureCoding.configs.recommended];

# Run
npx eslint .

# Fix auto‑fixable issues
npx eslint . --fix

다음 단계

  • 규칙 읽기 – 각 규칙에는 예제가 포함된 자세한 문서가 있습니다.
  • 엄격 모드 사용해 보기secureCoding.configs.strict.
  • CI에 추가 – 보안 문제가 있는 PR을 차단합니다.
  • 플러그인 결합 – 특화된 커버리지를 위해 eslint-plugin-pg, eslint-plugin-jwt를 추가합니다.

📦 npm: eslint-plugin-secure-coding
📖 Full Rule List
Star on GitHub
📖 OWASP Coverage Matrix

🚀 질문이 있나요? GitHub에 이슈를 열어 주세요!

Back to Blog

관련 글

더 보기 »

eslint-plugin-pg 시작하기

빠른 설치 bash npm install --save-dev eslint-plugin-pg Flat Config js // eslint.config.js import pg from 'eslint-plugin-pg'; export default pg.configs.reco...