Skip to content

Default firebase geofire rules not allowing writes.  #135

@cloudtamer

Description

@cloudtamer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions