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

Properties with only read/write false rules are omitted - even if sibling to wildcard property. #97

Closed
fabiozaffani opened this issue Dec 30, 2015 · 10 comments
Labels

Comments

@fabiozaffani
Copy link

Firebase work in a permissive mode by default (everyone allowed to read and write anything) I always set the paths and objects to read and write to false. However doing that inside a *.bolt file will translate to nothing. Let's use the following rules as an example:

path / {
    read() = false;
    write() = false;
}

Nothing get's generated in the resulting json file, the desired effect, however, should be

{
  "rules": {
    ".read": "false",
    ".write": "false"
  }
}
@fabiozaffani
Copy link
Author

Just an update with a temporary workaround, for now i'm using the following statement to emulate the "false".

path / {
    read() = 1 == 0;
    write() = 1 == 0;
}

which will translate to

{
  "rules": {
    ".read": "1==0",
    ".write": "1==0"
  }
}

Since firebase will parse the value inside the ".read" and ".write" attributes, the statement "1==0" will be falsy.

@fabiozaffani fabiozaffani changed the title If read() and write() are set to false, no rules are generated If read() and/or write() return false, no rules are generated Dec 30, 2015
@mckoss
Copy link
Contributor

mckoss commented Dec 31, 2015

Firebase is read==false and write==false by default, so there is no need for this.

@mckoss mckoss closed this as completed Dec 31, 2015
@jacob-israel-turner
Copy link

There is a need for this. I want to make only one key un-readable and un-writable, but every sibling key readable and writable when authed. @fabiozaffani's workaround makes this possible, but compiling write() = false should be an option.

@mckoss
Copy link
Contributor

mckoss commented Jan 10, 2016

write() = false is a NO-OP in Firebase (JSON) rules. This is because all write rules are OR-ed together in the hierarchy - there is no way to make a child property unwritable when it has already been made writable by a parent rule.

@jacob-israel-turner
Copy link

I'm not talking about parent keys, but siblings.

path /parent {
  read() = auth !== null;
  /someKey {
    write() = false; 
  }
  /$all_other_keys {
    write() = auth !== null;
  }
}

I want to make someKey unwritable, but every other key writable if you're authed. This compiles to:

"parent": {
  "someKey": {
    "$all_other_keys": {
      ".write": "auth != null"
    }
  },
  ".read": "auth != null"
}

Which makes every key (including someKey) writable with auth.

I've realized that our model was actually different, so this doesn't affect me now. But it could certainly match a future use-case.

The best solution I can see would be to correctly compile write() = false. The write() = 0 == 1 workaround should work as well. Correct me if there is currently another, better way to do this.

@mckoss
Copy link
Contributor

mckoss commented Jan 10, 2016

Ah! Now I see - thanks for the example.

Since someKey is omitted (by Bolt), it is shadowed by a sibling WILDCARD rule! You current example compiles to:

{
  "rules": {
    "parent": {
      "$all_other_keys": {
        ".write": "auth != null"
      },
      ".read": "auth != null"
    }
  }
}

What is wanted is:

{
  "rules": {
    "parent": {
      "someKey": {
         ".write": "false"
      }
      "$all_other_keys": {
        ".write": "auth != null"
      },
      ".read": "auth != null"
    }
  }
}

@jacob-israel-turner
Copy link

Uh, then I'm confused.

From my understanding, $all_other_keys is an alias for every key under parent, meaning, if I have the data:

{
  "parent": {
    "this_is_a_key": "foo",
    "someKey": "bar",
    "this_is_another_key": "baz"
  }
}

then all three keys (this_is_a_key, someKey, and this_is_another_key) will now be writable (if authed), given the rules that you just posted.

Am I missing something?

@mckoss
Copy link
Contributor

mckoss commented Jan 10, 2016

(I edited my last response - I get it now!)

@jacob-israel-turner
Copy link

Ah yes, exactly. :)

@mckoss mckoss reopened this Jan 10, 2016
@mckoss
Copy link
Contributor

mckoss commented Jan 10, 2016

Another work-around is to apply a type to someKey - which will emit a node for it in the JSON tree:

path /parent {
  read() = auth !== null;
  /someKey is String;
  /$all_other_keys {
    write() = auth != null;
  }
}

Generates

{
  "rules": {
    "parent": {
      "someKey": {
        ".validate": "newData.isString()"
      },
      "$all_other_keys": {
        ".write": "auth != null"
      },
      ".read": "auth != null"
    }
  }
}

@mckoss mckoss changed the title If read() and/or write() return false, no rules are generated Properties with only read/write false rules are omitted - even if sibling to wildcard property. Jan 10, 2016
@mckoss mckoss added the bug label Jan 10, 2016
mckoss added a commit that referenced this issue Aug 4, 2016
Enable generating .read/.write false rules for case where property is sibling of wildcard.  Fixes issue #97.
@mckoss mckoss closed this as completed Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants