Communitygithub.com

YepAPI/skills

RBAC 인가 — 미들웨어 가드, 기본 거부, 리소스 수준 권한 확인.

skills란 무엇인가요?

이 스킬은 AI 에이전트(Claude Code, Cursor, Codex 등)가 애플리케이션에 RBAC(역할 기반 접근 제어) 인가 시스템을 구현할 수 있도록 설계된 상세한 규칙과 코드 예제를 제공합니다. 기본 거부 원칙을 강화하여 명시적 권한이 없는 모든 접근을 차단하며, UI 요소 숨기기만으로는 보안이 유지되지 않는다는 점을 강조하여 서버 측에서 권한 검사를 수행해야 합니다. 리소스 소유권에 기반한 세분화된 권한 검사(`can(user, 'edit', resource)`)를 포함하여 '편집자' 역할이라도 다른 사용자의 콘텐츠를 수정할 수 없도록 합니다. Express.js 미들웨어 가드와 TypeScript 도우미 함수를 제공하여 개발자가 일관되고 안전한 인가 로직을 쉽게 적용할 수 있도록 돕습니다. 또한 모든 권한 검사 결과를 감사 로그로 기록하여 관리자 작업을 추적하고 보안 위반을 신속히 탐지할 수 있도록 합니다.

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

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

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

문서

RBAC 인가

규칙

  • 모든 라우트에 미들웨어를 사용하여 권한 확인 — 인가를 선택 사항으로 만들지 마세요
  • 기본적으로 거부: 명시적 권한이 부여되지 않은 경우 접근이 거부됩니다
  • 서버 측 강제: UI 요소 숨기기는 보안이 아닙니다. 서버에서 확인하세요
  • 역할 계층 정의: admin > editor > viewer — 상위 역할은 하위 권한을 상속받습니다
  • 리소스 수준 확인: can(user, "edit", resource) 확인 — 역할 기반 접근만으로는 충분하지 않습니다
  • 모든 권한 확인 감사 — 누가, 언제, 무엇에 접근했는지 기록하고, 특히 관리자 작업에 대해 기록하세요
  • 인증(당신은 누구인가?)과 인가(무엇을 할 수 있는가?)를 분리하세요
// 권한 확인 도우미
type Action = "read" | "create" | "update" | "delete";
type Resource = { ownerId: string; [key: string]: any };

function can(user: { id: string; role: string }, action: Action, resource?: Resource): boolean {
  const permissions: Record<string, Action[]> = {
    admin: ["read", "create", "update", "delete"],
    editor: ["read", "create", "update"],
    viewer: ["read"],
  };
  const allowed = permissions[user.role];
  if (!allowed?.includes(action)) return false;
  // 리소스 수준 확인: 편집자는 자신의 리소스만 수정할 수 있습니다
  if (resource && action !== "read" && user.role !== "admin") {
    return resource.ownerId === user.id;
  }
  return true;
}
// Express 미들웨어 가드
function requirePermission(action: Action) {
  return (req, res, next) => {
    if (!req.user) return res.status(401).json({ error: "인증되지 않음" });
    if (!can(req.user, action, req.resource)) {
      return res.status(403).json({ error: "금지됨" });
    }
    next();
  };
}

app.put("/api/posts/:id", loadResource, requirePermission("update"), updatePost);

피해야 할 사항

  • UI에서만 권한 확인 — 공격자가 API를 직접 호출합니다
  • 명시적으로 거부되지 않으면 접근 허용 — 항상 기본적으로 거부하세요
  • 단일 isAdmin 부울 값 사용 — 역할은 세분화되고 확장 가능해야 합니다
  • 리소스 수준 확인 누락 — "편집자"가 "모든 사람의 콘텐츠를 편집할 수 있음"을 의미해서는 안 됩니다
  • "내부" 엔드포인트에서 인가 생략 — 결국 공개됩니다

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.

관련 스킬