Communitygithub.com

YepAPI/skills

오류 보안 — 안전한 오류 응답, 상관관계 ID, 프로덕션 환경에서 스택 트레이스 누출 방지.

skills란 무엇인가요?

이 스킬은 프로덕션 환경에서 API 오류 처리를 안전하게 구성하는 방법을 설명합니다. 주요 목표는 스택 트레이스, 데이터베이스 오류, 파일 경로 등 민감한 정보가 클라이언트에 노출되지 않도록 방지하는 것입니다. 대신 고유한 오류 ID와 일반적인 오류 메시지를 반환하고, 전체 오류 상세 정보는 서버 측에 상관관계 ID와 함께 기록하여 디버깅을 지원합니다. Express 및 Next.js와 같은 Node.js 기반 프레임워크를 위한 구체적인 코드 예제(미들웨어 및 오류 경계 컴포넌트)를 제공하며, 개발 환경과 프로덕션 환경에서 각각 다른 상세 수준(개발: 전체 스택 트레이스, 프로덕션: 안전한 메시지 + ID)을 사용하도록 권장합니다. 또한 적절한 HTTP 상태 코드 사용과 타사 서비스 오류 메시지 정화의 중요성을 강조합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/error-security

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

오류 보안

규칙

  • 프로덕션 환경에서 클라이언트로 스택 트레이스, 데이터베이스 오류 또는 파일 경로를 절대 누출하지 않음
  • 고유한 오류 ID와 함께 일반적인 오류 메시지 반환: { error: "문제가 발생했습니다", errorId: "abc123" }
  • 디버깅을 위해 동일한 상관관계 ID로 서버 측에 전체 오류 상세 정보 기록
  • 오류 상세 수준 구분: 개발 환경(전체 스택 트레이스) vs 프로덕션 환경(안전한 메시지 + ID)
  • 전역 오류 핸들러로 처리되지 않은 모든 오류를 포착 — 절대 원시 오류가 클라이언트에 도달하지 않도록 함
  • 클라이언트로 전달하기 전에 타사 서비스의 오류 메시지를 정화
  • 적절한 HTTP 상태 코드 반환: 400 (잘못된 입력), 401 (인증되지 않음), 403 (금지됨), 404 (찾을 수 없음), 500 (서버 오류)
// Express 오류 핸들러 미들웨어
import { randomUUID } from "node:crypto";

app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
  const errorId = randomUUID();

  // 서버 측에 전체 상세 정보 기록
  console.error({ errorId, message: err.message, stack: err.stack, url: req.url });

  // 클라이언트에 안전한 응답 반환
  const statusCode = (err as any).statusCode || 500;
  res.status(statusCode).json({
    error: statusCode >= 500 ? "내부 서버 오류" : err.message,
    errorId,
    ...(process.env.NODE_ENV === "development" && { stack: err.stack }),
  });
});
// Next.js 오류 경계 — 안전한 프로덕션 오류
import { useEffect } from 'react';

export default function GlobalError({ error, reset }) {
  useEffect(() => {
    console.error(error);
  }, [error]);

  return (
    <div>
      <h2>문제가 발생했습니다</h2>
      <p>오류 ID: {error.digest}</p>
      <button onClick={reset}>다시 시도</button>
    </div>
  );
}

피해야 할 사항

  • err.message를 직접 반환 — 데이터베이스 오류는 테이블 이름, 열 이름 및 쿼리 구조를 누출함
  • 프로덕션 응답에 스택 트레이스 포함 — 파일 경로, 종속성 및 내부 아키텍처를 드러냄
  • 모든 것에 일반적인 500 사용 — 클라이언트가 오류를 적절히 처리할 수 있도록 적절한 상태 코드 사용
  • 상관관계 ID 없이 오류 기록 — 프로덕션 디버깅을 거의 불가능하게 만듦
  • 오류를 조용히 무시 — 응답이 일반적이더라도 항상 기록

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

관련 스킬