Fireship · @fireship
Firestore Security Rules - How to Hack a Firebase App
Uploaded March 8, 2018 · Length 10:05
Summary
Learn how to secure a Firebase app by setting up Firestore security rules, including user authentication, data validation, and custom functions.
- firebase security rules
- firestore security rules
- firebase authentication
- firestore data validation
- custom functions in firestore rules
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
I can hack into your firebase app in
- 0:04
about 10 seconds then steal and delete
- 0:06
all your data assuming you fail to set
- 0:08
up back-end security rules allow me to
- 0:10
show you all I have to do is pull up an
- 0:12
app and go into the chrome developer
- 0:14
tools under the network tab then find a
- 0:16
request coming from firebase open up the
- 0:18
headers and find the corresponding
- 0:20
project ID from there I can just go to
- 0:22
the command line and run a curl delete
- 0:25
request to the firebase REST API and
- 0:27
start wiping out this app's database if
- 0:29
you deploy a firebase app without
- 0:31
backend rules anybody can do this to
- 0:33
your app as well today I'm going to show
- 0:35
you how to keep your firestore database
- 0:36
secure by writing expressive
- 0:38
easy-to-understand back-end security
- 0:40
rules if you're new here like and
- 0:42
subscribe and grab the source code from
- 0:44
angular firebase comm to get started
- 0:47
you'll want to go to the firestore
- 0:48
database and then open up the rules tab
- 0:51
rules are defined in their own special
- 0:53
language that somewhat resembles
- 0:54
JavaScript currently the arrows pointing
- 0:57
to the root of our database and all of
- 0:59
our rules logic will be defined inside
- 1:01
this block then we use the match keyword
- 1:03
to point two paths in our database where
- 1:06
we want to apply rules in this case
- 1:08
we're using that equals star star to
- 1:10
match every single document in the
- 1:12
database then we use the allow keyword
- 1:14
followed by the operation that we want
- 1:16
to set a rule for in this case reader
- 1:18
right if we leave it blank it's going to
- 1:20
allow those operations or we can write
- 1:22
an expression that returns true or false
- 1:24
to apply some actual rule logic to this
- 1:27
route for example if we wanted to
- 1:29
completely lock down all documents we
- 1:31
could say if false and then nobody could
- 1:33
read or write from the client-side if I
- 1:36
try to query a collection from my
- 1:38
front-end app I'm going to get an error
- 1:39
in the browser console so cool now our
- 1:42
apps 100% secure but that's a little too
- 1:44
secure now we're going to write some
- 1:47
rules that perform logic based on user
- 1:49
authentication the underlying data the
- 1:51
incoming request time etc first let's
- 1:54
look at the various types of requests
- 1:55
that we can lock down first we have get
- 1:58
which would apply to reading a specific


