Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default firebase geofire rules not allowing writes. #135

Open
cloudtamer opened this issue Jun 30, 2020 · 0 comments
Open

Default firebase geofire rules not allowing writes. #135

cloudtamer opened this issue Jun 30, 2020 · 0 comments

Comments

@cloudtamer
Copy link

I am trying to setup default GeoFire Rules on Firebase. When I turn on the rules below on the "geo" key I am getting "Permission Denied" in Xcode (SwiftUI). But other areas in firebase are getting written to. It's just geoFire that is getting denied. I want any Authed user to read/write to the entire firebase.

The "key" is an firebase random Key generator.

let firebaseStoreRef = storeRef.childByAutoId()

This link is where I am getting the default GeoFire rules (https://github.com/firebase/geofire-js/blob/master/examples/securityRules/authenticated.rules.json)

Here is my JASON structure when I turned off the rules or set the rules to just auth.

{
  "geo" : {
    "-MAsyzawTChafkDQAzpx" : {
      "g" : "9r4bb5f5h6",
      "l" : [ 39.52796273493379, -119.8798737645459 ]
    },
    "-MAtFpjYsSLA0jJ4-5Le" : {
      "g" : "9r4bbk77v5",
      "l" : [ 39.5308423, -119.8671408 ]
    }
  }
}

Here are the rules that I set up in firebase. And yes, the user is authed, and I am able to write to other areas of the firebase just fine.

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    "geo": {
       // Allow anyone to read the GeoFire index
      ".read": true,

      // Index each location's geohash for faster querying
      ".indexOn": ["g"],

      // Schema validation
      "$key": {
        // Allow any authentication user to add, update, or remove keys in the GeoFire index
        ".write": "auth !== null",

        // Key validation
        ".validate": "newData.hasChildren(['g', 'l']) && newData.getPriority().length <= 22 && newData.getPriority().length > 0",

        // Geohash validation
        "g": {
          ".validate": "newData.val() == newData.parent().getPriority()"
        },

        // Location coordinates validation
        "l": {
          "0" : {
            ".validate": "newData.isNumber() && newData.val() >= -90 && newData.val() <= 90"
          },
          "1" : {
            ".validate": "newData.isNumber() && newData.val() >= -180 && newData.val() <= 180"
          },
          "$other": {
            ".validate": false
          }
        },

        // Don't allow any other keys to be written
        "$other": {
          ".validate": false
        }
      }
    },
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

If I comment out the following areas I am able to write to the "geo" part of the firebase...

// Key validation 
// Geohash validation 
// Don't allow any other keys to be written

Thanks in advance.

@cloudtamer cloudtamer changed the title Default firebare geofire rules not allowing writes. Default firebase geofire rules not allowing writes. Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant