api-security-best-practices
하는 일
API(프로그램들이 소통하는 ‘문’)를 더 안전하게 만드는 데 도움을 줍니다. 권한이 있는 사람만 정보에 접근하는지, 보낸 데이터가 올바른지 확인하여 흔한 공격을 막습니다.
사용하는 경우
- ✓API에 보호되는 새 기능을 만들 때.
- ✓누가 어떤 데이터에 접근할 수 있는지 검토할 때.
- ✓API가 잘못 사용된 흔적을 조사할 때.
스킬 링크
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-security-best-practices/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“이 새 API 경로를 검토해서, 인증된 사용자만 접근할 수 있고 보낸 데이터가 유효한지 확인해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
도구는 API가 요청을 보내는 사람이 누구인지(인증)와, 그 사람이 요청한 작업을 할 권한이 있는지(권한 부여)를 어떻게 확인하는지 분석합니다. 또한 받은 데이터가 안전하고 예상된 형식인지도 확인합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
API Security Best Practices
Review the request boundary from caller identity through authorization, validated input, storage and observable response. Preserve the application's actual identity provider and data model rather than introducing a second authentication system.
When to Use
Use when adding a protected endpoint, reviewing object access, replacing permissive request parsing, or investigating an API abuse path. For a concrete defect, start with the failing route and its callers; do not deploy unrelated security infrastructure.
Inputs and prerequisites
Record the routes, caller/tenant model, identity provider, token contract, runtime and locked dependency versions, database schema, proxy topology and authorized test scope. Use synthetic identities in a test environment. Existing task authorization carries forward; production scans, account writes and message sends need their own authority. The Node examples below are integration sketches for Express, jsonwebtoken and Zod; application/database adapters are deliberately named rather than presented as a full runnable service. Confirm APIs against the installed versions before integrating.
1. Authenticate the exact token contract
Prefer the established provider/session middleware. When the service owns an HMAC JWT contract, require a strong server-owned key, a fixed algorithm, exact issuer and audience, and required runtime claims. Do not infer permissions from a decoded token before signature verification. Never accept a caller-selected verification algorithm.
const jwt = require('jsonwebtoken');
// Illustrative first-party access-token contract; not a third-party OAuth adapter.
const ACCESS_POLICY = {
algorithms: ['HS256'], issuer: 'example-auth', audience: 'example-api'
};
function verifyAccessToken(token, signingKey) {
const claims = jwt.verify(token, signingKey, ACCESS_POLICY);
if (!claims || typeof claims !== 'object' ||
typeof claims.sub !== 'string' || !claims.sub ||
typeof claims.tenantId !== 'string' || !claims.tenantId ||
!Number.isSafeInteger(claims.exp) || !Number.isSafeInteger(claims.iat) ||
claims.exp <= claims.iat) {
throw new Error('Invalid access claims');
}
return { subject: claims.sub, tenantId: claims.tenantId };
}
function readBearer(header) {
if (typeof header !== 'string' || header.length > 8192) return null;
const match = /^Bearer ([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)$/i.exec(header);
return match ? match[1] : null;
}
Issue access tokens with the same issuer/audience/algorithm and a short application- approved expiration. Handle verification failure as a generic 401 without echoing the token or exception. Expiration alone does not revoke a token; define revocation or short-lived sessions according to the actual threat model. A service using asymmetric provider keys needs the provider's discovery/JWKS validation and key-rotation policy, not this HMAC example. Never reuse an access token as a refresh token.
Refresh sessions
Use the provider's supported session flow or a server-side opaque refresh design: store only a digest, expiry, user/session family and revocation state. In one atomic transaction consume the old active token and create the replacement. Concurrent reuse must not issue two successors; defined reuse handling revokes the affected family. Check current user status and permissions when issuing new access tokens. Bind refresh to the intended client/session and protect cookie-based requests against CSRF. Do not log tokens, store them plaintext in a database, or return a refresh token through a URL. Test simultaneous refresh, expiry, replay, revocation and transaction failure before calling the flow complete. No database transaction adapter is bundled here.
2. Authorize the resource and operation
Authentication identifies the caller; authorization decides the exact operation on an object and tenant. A role name does not automatically grant cross-tenant access. Apply the owner/tenant predicate in the database mutation to avoid a check-then-write race, and allowlist writable properties. Use 404/403 consistently with the product's resource-disclosure policy.
// Prisma-style sketch; id and tenant types must match your actual schema.
async function deleteOwnedPost(prisma, postId, principal) {
const result = await prisma.post.deleteMany({
…
자주 묻는 질문
인증이란 무엇인가요?
사용자나 프로그램이 자신이 주장하는 사람인지 확인하는 과정입니다. 보통 비밀번호, 토큰, 키를 사용합니다.
권한 부여란 무엇인가요?
인증된 사용자나 프로그램이 특정 작업을 하거나 자원에 접근할 권한이 있는지 확인하는 과정입니다.
입력 데이터를 검증하는 이유는 무엇인가요?
안전하고 예상된 데이터 형식만 처리하도록 보장해, 잘못된 데이터를 악용하는 오류와 공격을 막기 위해서입니다.
상세 정보
작성자의 원본 설명
Implement secure API design patterns including authentication, authorization, input validation, rate limiting, and protection against common API vulnerabilities
인기도
- GitHub 스타
- 48k
- 순위
- #3779
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
00-andruia-consultant
48k에이전트가 AI 프로젝트를 시작하거나 개선할 수 있도록 코드를 분석하고 스페인어로 실행 계획을 세워 줍니다.
007
48k에이전트가 보안 감사와 위협 모델링을 수행해 공격과 취약점으로부터 프로젝트를 보호하도록 돕습니다.
10-andruia-skill-smith
48k에이전트가 AI 도구의 작동 방식을 정의하고 문서를 쓰며 구조를 검증하도록 돕습니다.
20-andruia-niche-intelligence
48k에이전트가 신뢰할 수 있는 자료를 바탕으로 특정 산업의 맥락, 규칙, 사용 패턴, 위험을 정리한 요약을 만들도록 돕습니다.