Fireship · @fireship

Firestore Security Rules - How to Hack a Firebase App

Uploaded March 8, 2018 · Length 10:05

Firestore Security Rules - How to Hack a Firebase App

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.

  1. 0:00

    I can hack into your firebase app in

  2. 0:04

    about 10 seconds then steal and delete

  3. 0:06

    all your data assuming you fail to set

  4. 0:08

    up back-end security rules allow me to

  5. 0:10

    show you all I have to do is pull up an

  6. 0:12

    app and go into the chrome developer

  7. 0:14

    tools under the network tab then find a

  8. 0:16

    request coming from firebase open up the

  9. 0:18

    headers and find the corresponding

  10. 0:20

    project ID from there I can just go to

  11. 0:22

    the command line and run a curl delete

  12. 0:25

    request to the firebase REST API and

  13. 0:27

    start wiping out this app's database if

  14. 0:29

    you deploy a firebase app without

  15. 0:31

    backend rules anybody can do this to

  16. 0:33

    your app as well today I'm going to show

  17. 0:35

    you how to keep your firestore database

  18. 0:36

    secure by writing expressive

  19. 0:38

    easy-to-understand back-end security

  20. 0:40

    rules if you're new here like and

  21. 0:42

    subscribe and grab the source code from

  22. 0:44

    angular firebase comm to get started

  23. 0:47

    you'll want to go to the firestore

  24. 0:48

    database and then open up the rules tab

  25. 0:51

    rules are defined in their own special

  26. 0:53

    language that somewhat resembles

  27. 0:54

    JavaScript currently the arrows pointing

  28. 0:57

    to the root of our database and all of

  29. 0:59

    our rules logic will be defined inside

  30. 1:01

    this block then we use the match keyword

  31. 1:03

    to point two paths in our database where

  32. 1:06

    we want to apply rules in this case

  33. 1:08

    we're using that equals star star to

  34. 1:10

    match every single document in the

  35. 1:12

    database then we use the allow keyword

  36. 1:14

    followed by the operation that we want

  37. 1:16

    to set a rule for in this case reader

  38. 1:18

    right if we leave it blank it's going to

  39. 1:20

    allow those operations or we can write

  40. 1:22

    an expression that returns true or false

  41. 1:24

    to apply some actual rule logic to this

  42. 1:27

    route for example if we wanted to

  43. 1:29

    completely lock down all documents we

  44. 1:31

    could say if false and then nobody could

  45. 1:33

    read or write from the client-side if I

  46. 1:36

    try to query a collection from my

  47. 1:38

    front-end app I'm going to get an error

  48. 1:39

    in the browser console so cool now our

  49. 1:42

    apps 100% secure but that's a little too

  50. 1:44

    secure now we're going to write some

  51. 1:47

    rules that perform logic based on user

  52. 1:49

    authentication the underlying data the

  53. 1:51

    incoming request time etc first let's

  54. 1:54

    look at the various types of requests

  55. 1:55

    that we can lock down first we have get

  56. 1:58

    which would apply to reading a specific