피드로 돌아가기
Dev.toSecurity
원문 읽기
Client-to-Backend 직접 통신 구조의 보안 취약점을 해결하는 Server-side Access Control 설계
The Complete Guide to Firebase Security Rules: Why They Matter and how to Write Them
AI 요약
Context
전통적인 Backend Middleware 계층을 제거하고 Client가 Database에 직접 접근하는 Firebase 아키텍처 채택으로 개발 속도 향상. 그러나 Client-side 코드 디컴파일을 통한 API Key 탈취 및 직접 쿼리 실행으로 인한 데이터 무결성 훼손과 Billing 비용 폭증 위험 존재.
Technical Solution
- Request Interception 구조: 모든 Read/Write 요청을 Server-side에서 가로채어 정의된 Rule과 대조하는 구조적 Shield 계층 구축
- Path-based Access Control: request.auth.uid와 Document Path 변수를 매칭하여 User-owned Data에 대한 CRUD Isolation 구현
- Schema Validation 로직: request.resource.data를 활용하여 데이터 타입, 필드 길이, 필수 값 존재 여부를 검증하는 무결성 보장 설계
- Immutable Record 패턴: !data.exists() 조건 설정을 통해 최초 생성 후 수정 및 삭제가 불가능한 Write-once 감사 로그 구조 설계
- Asset Constraint 설정: Cloud Storage의 MIME Type 및 파일 크기 제한을 통한 DoS 공격 방어 및 비용 최적화
- Role-based Access Control: Custom Claims를 활용하여 Client-side 문서 수정 없이 권한을 제어하는 Least Privilege 원칙 적용
실천 포인트
- Deny-by-Default 원칙에 따라 모든 접근을 기본 차단 후 명시적 허용 설정 - UI 단의 Validation을 무시하고 Security Rules 내에서 최종 데이터 무결성 검증 수행 - Firebase Emulator Suite를 활용하여 Deployment 전 Rule 작동 여부 사전 검증 - Security Rules를 애플리케이션 코드와 동일하게 Git Version Control로 관리