New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

firebase_rpg

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firebase_rpg

utility library to write firebase security rules easier

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

Firebase RPG (rules, paths, generators)

Just a simpler way to write security rules

npm install firebase_rpg
coffee examples/simple.coffee
  • Rule

Init:

  • using string
  • using object which responds to val() method (rule or path)

Methods:

  • and(string or rule, isolate=false) => returns rule
  • or(string or rule, isolate=false) => returns rule
  • exists() => returns rule
  • val() => returns string

isolate - specify if we want to wrap the condition in a section (see the tests)

  • Path

Init:

  • using string
  • using object which responds to val() method (rule or path)

Methods:

  • child(string or path) => returns path
  • val() => returns string
  • Generator

Init:

  • rules hash containing rules
  • rules hash item should be hash with write / read optional attributes

E.g.

rules = 
  'test/all':
    read: true
    write: false

will result in:

{
  "rules": {
    "test": {
      "all": {
        ".read": true,
        ".write": false
      }
    }
  }
}

4. Usage

  • require module
  • use the R, P, G and in the end export the JSON

E.g.

RPG = require "firebase_rpg"
R = RPG.R
P = RPG.P

isLoggedIn = ->
  R('auth.username !== null')
isCurrentUser = (userId) ->
  R("#{userId} === auth.username")
isAdmin = (userId) ->
  R(P("root").child("'admin'").child("#{userId}")).exists()

rules =
  'test/$user_id': 
    read :  isLoggedIn()
    write:  isLoggedIn()
            .and(
              isCurrentUser("$user_id").or(isAdmin("$user_id"))
            , true)

generatedRules = RPG.G(rules).generate()
console.info(JSON.stringify(generatedRules, null, '  '));

Output:

{
  "rules": {
    "test": {
      "$user_id": {
        ".read": "(auth.username !== null)",
        ".write": "(auth.username !== null&&($user_id === auth.username||root.child('admin').child($user_id).exists()))"
      }
    }
  }
}

Keywords

firebase

FAQs

Package last updated on 08 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts