본문으로 건너뛰기
Skillpedia
보안75k · #3059

token-storage-security

하는 일

이 스킬은 웹 앱이 로그인 토큰을 어떻게 저장하는지, 스크립트가 토큰을 훔칠 수 있는지 확인합니다. 로그인 시스템을 만들거나 검토하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓웹 앱이 로그인 토큰을 localStorage나 sessionStorage에 저장할 때.
  • ✓웹사이트에 새 로그인 시스템을 구축할 때.
  • ✓삽입된 스크립트가 로그인 토큰을 훔칠 수 있는지 보안 검토에서 물을 때.

스킬 링크

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/token-storage-security/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/token-storage-security/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“우리 앱은 사용자의 로그인 토큰을 localStorage에 저장합니다. 이것이 안전한가요? 어떻게 바꿔야 하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 토큰이 어디에 저장되는지, 변경 요청이 위조로부터 보호되는지 확인합니다. 그다음 JavaScript가 읽을 수 없는 보안 쿠키로 토큰을 옮기라고 제안합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Store authentication tokens securely

localStorage is accessible to any JavaScript running on the page. A single XSS vulnerability — including one in a third-party script — can exfiltrate all tokens silently. httpOnly cookies are completely invisible to JavaScript; even if an attacker executes arbitrary code on the page, they cannot read the cookie. This single architectural choice eliminates the most common token theft vector.

Quick Reference

  • Store session tokens and JWTs in httpOnly cookies — not localStorage
  • localStorage is readable by any JavaScript on the page, including injected XSS code
  • Combine httpOnly with Secure and SameSite=Strict (or Lax) cookie flags
  • Use short-lived access tokens and rotate refresh tokens on each use
  • Protect every state-changing request with CSRF defenses, not cookie flags alone

Check

Check whether authentication tokens are stored in httpOnly cookies or in JavaScript-accessible storage like localStorage. Verify that POST, PUT, PATCH, and DELETE requests also require a CSRF token or an equivalent anti-forgery control.

Fix

Move token storage from localStorage/sessionStorage to httpOnly cookies set by the server, and ensure the cookies have Secure and SameSite flags. Add CSRF protection to every state-changing route that relies on browser-sent credentials.

Explain

Explain why localStorage is vulnerable to XSS token theft and how httpOnly cookies mitigate this attack vector.

Code Review

Review authentication flows, token storage calls, and API client code. Flag any use of localStorage.setItem, sessionStorage.setItem, or document.cookie for storing access tokens, JWTs, or session identifiers. Also flag credentialed mutations that lack a CSRF token, Origin check, or same-site enforcement.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/security/token-storage-security

자주 묻는 질문

localStorage에 토큰을 두는 것이 왜 위험한가요?

페이지의 모든 JavaScript가 읽을 수 있으므로, 삽입된 스크립트 하나가 모든 토큰을 가져갈 수 있습니다.

이 스킬은 어떤 쿠키 설정을 권장하나요?

httpOnly와 Secure를 권장하고, SameSite는 Strict나 Lax로 설정하라고 합니다.

보안 쿠키만으로 충분한가요?

아니요. 데이터를 바꾸는 요청에는 CSRF 보호라고 불리는 위조 요청 방지가 여전히 필요하다고 이 스킬은 설명합니다.

상세 정보

작성자의 원본 설명

Use when reviewing authentication implementation, setting up a new auth system, or evaluating whether the current token storage approach exposes the application to XSS-based token theft.

repo: thedaviddias/Front-End-Checklist

인기도

GitHub 스타
75k
순위
#3059
라이선스
MIT
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬