EYEN 2024. 5. 20. 23:39

# 참고 자료

https://firebase.google.com/docs/rules/insecure-rules?hl=ko

 

안전하지 않은 규칙 차단  |  Firebase 보안 규칙

Google I/O 2023에서 Firebase의 주요 소식을 확인하세요. 자세히 알아보기 의견 보내기 안전하지 않은 규칙 차단 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.

firebase.google.com

 

 


Firebase 보안 규칙

 

firebase의 보안 규칙은 firebase console의 실시간 데이터베이스, cloud firestore, storage/ firebase CLI에서 firebase.json파일에서 볼 수 있다.

 

Firebase Console에서 데이터베이스 인스턴스 또는 Cloud Storage 버킷을 만들 때 모든 사용자에 대한 액세스를 거부하거나 허용하도록 선택할 수 있다. 

 

안전하지 않은 규칙의 일반적인 시나리오

1. 오픈 액세스: 앱을 배포했을 때 프로젝트 ID를 추측한 다른 사람이 데이터를 도용, 수정 또는 삭제할 수 있다.

 

Cloud Firestore

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }

 

실시간 데이터베이스

"rules": {
    ".read": true,
    ".write": true
  }

 

Cloud Storage

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

 

 

2. 인증된 사용자 액세스

Cloud Firestore

service cloud.firestore {
  match /databases/{database}/documents {
    match /some_collection/{document} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

 

실시간 데이터베이스

{
  "rules": {
    ".read": "auth.uid !== null",
    ".write": "auth.uid !== null"
  }
}

 

Cloud Storage

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

 

 

3. 잘못 상속된 규칙

{
  "rules": {
     "foo": {
        // allows read to /foo/*
        ".read": "data.child('baz').val() === true",
        "bar": {
          /* ignored, since read was allowed already */
          ".read": false
        }
     }
  }
}