Skip to content

[week5] Authentication#10

Open
eunseo9311 wants to merge 1 commit intomainfrom
week5/eunseo2
Open

[week5] Authentication#10
eunseo9311 wants to merge 1 commit intomainfrom
week5/eunseo2

Conversation

@eunseo9311
Copy link
Contributor

목차

  1. 왜 인증이 필요한가 - Stateless 문제
  2. Cookie
  3. Session
  4. JWT(JSON We Token)
  5. session vs JWT 비교 및 선택 기준
  6. Access Token + Refresh Token 전략
  7. 면접 단골 질문

@eunseo9311 eunseo9311 self-assigned this Mar 16, 2026
Comment on lines +301 to +312
### 5-2. 언제 세션을 쓸까?

- **강제 로그아웃이 중요한 서비스** (금융, 보안 민감 서비스)
- **서버 수가 적고 트래픽이 많지 않은 서비스**
- **사용자 상태를 실시간으로 제어해야 하는 경우** (관리자가 특정 계정 강제 종료 등)

### 5-3. 언제 JWT를 쓸까?

- **마이크로서비스 아키텍처** (여러 서버가 토큰만 검증하면 됨)
- **서버 스케일 아웃이 잦은 서비스**
- **모바일 앱** (쿠키 관리보다 토큰 관리가 편리)
- **외부 서비스와의 API 연동** (OAuth 등)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 상태 유지하기 같은 기능은 보통 세션과 JWT 중 어떤 것을 활용해서 구현하나요?

Comment on lines +265 to +271
#### 1. 강제 만료 불가
```
상황: 사용자가 로그아웃했는데 토큰이 아직 유효기간 내
→ 탈취된 토큰을 만료 전까지 사용 가능

세션 방식: 세션 삭제 → 즉시 무효화 가능
JWT 방식: 서버에 저장된 게 없음 → 만료될 때까지 막을 수 없음
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서버가 토큰 강제 만료를 할 수 없는데 JWT 방식을 사용하는 서비스에서 모든 기기 로그아웃같은 기능은 어떻게 구현할 수 있나요?

```

**해결 방법:**
- **Sticky Session**: 같은 클라이언트는 항상 같은 서버로 라우팅 → 로드밸런싱 효율 저하
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 같은 서버에 세션이 몰려 과부하가 걸린다면 어떻게 해결해야 하나요??

Comment on lines +66 to +74
```http
Set-Cookie: sessionId=abc123;
Max-Age=3600;
Domain=example.com;
Path=/;
Secure;
HttpOnly;
SameSite=Strict
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secure 옵션은 쿠키 암호화되어 전송 관련 옵션인건가요?

Comment on lines +278 to +280
#### 2. Payload 크기
- 세션: 클라이언트에 ID만 전송 (수십 바이트)
- JWT: 토큰 자체에 정보 포함 → 요청마다 수백 바이트 추가
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

세션과 비교해서 서버에 저장된 게 없으니 정보를 토큰 안에 직접 넣어야 하는데 이 정보가 추가될때마다 파일 용량이 커지는 단점이 있다고 이해했는데 이 단점을 해결하기 위한 payload 설계가 있을 것 같아요 보통 어떤 정보까지 담는 것이 좋은 best practice인가요?

@sunnny619 sunnny619 changed the title feat/Authentication [week5] Authentication Mar 17, 2026
|----|------|
| `Strict` | 같은 사이트 요청에서만 전송. 가장 보안적 |
| `Lax` | 기본값. 외부 링크로 이동 시 GET 요청에는 전송 |
| `None` | 모든 요청에 전송 (반드시 `Secure` 함께 사용) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None은 어떤 경우에 사용하나요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict / Lax: "우리 집(도메인) 안에서만 안전하게 놀자."
None: "옆집(다른 도메인)이랑도 물건(쿠키)을 주고받아야 해."

라고 예시 들 수 있을 것 같아요


**해결 방법:**
- **Sticky Session**: 같은 클라이언트는 항상 같은 서버로 라우팅 → 로드밸런싱 효율 저하
- **세션 공유 저장소**: Redis 같은 외부 저장소를 모든 서버가 공유 → 일반적인 해결책
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공유 저장소를 사용할 때 동시성 문제가 발생하는 경우를 고려해야 하는데, 주로 사용하는 방법이 무엇인가요?

@Gusionling Gusionling self-requested a review March 17, 2026 23:41
Copy link
Contributor

@Gusionling Gusionling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

급하게 올리느라 힘들었을텐데 고생하셨습니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants