How to Build a Secure App in Firebase (Firebase Pro Series)

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2018
  • The Firebase Pro Series is back to teach you how to build a secure app in Firebase! This week, Mike McDonald dives deep into Firebase Security Rules, because he’s secured more apps than he can count. Mike walks you through making a chatroom app that is secure for individuals and groups. Learn how to protect data in Cloud Storage and Cloud Firestore through defining resource types and validating inputs. Stay safe, Firebase developers, and don’t forget to let us know all your burning security questions in the comments below!
    Firebase Security Rules documentation → bit.ly/2MRUIUA
    Subscribe to the Firebase channel → bit.ly/firebase2
    Firebase Pro Series playlist → bit.ly/2OX98nH
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 69

  • @olivermiller1905
    @olivermiller1905 6 ปีที่แล้ว +73

    "Because this is Google, we're going to build a new chat app" 😂
    1:04

    • @MohdAkmalZakiIO
      @MohdAkmalZakiIO 6 ปีที่แล้ว

      Indedd it's happening, with the latest one, Duo to "replace" Hangout.

    • @klawdyo_
      @klawdyo_ 6 ปีที่แล้ว

      Yeah!!! New chat app every day is sooooooooooo Google 😂😂😂😂

    • @dhiyaulhaq8369
      @dhiyaulhaq8369 6 ปีที่แล้ว

      Lol 🤣

    • @ramitdour
      @ramitdour 3 ปีที่แล้ว

      now meet 😂😂

    • @harmanmax
      @harmanmax 3 ปีที่แล้ว

      Google Talk -> Google Hangout -> Duo -> Meet 🤣🤣

  • @mateja176
    @mateja176 6 ปีที่แล้ว +15

    This video is a must watch if you're a firebase user!

  • @Lindauson
    @Lindauson 6 ปีที่แล้ว +2

    Awesome post! I was waiting for a really good video of implementing role-based security.

  • @kld0093
    @kld0093 5 ปีที่แล้ว +1

    This is exactly what I wanted to see! Thank you 🔥

  • @eriktorres1745
    @eriktorres1745 6 ปีที่แล้ว +1

    I usually stayed away from building logic in the rules but this is clear on how I can do so. This is good stuff, thx!

  • @DanBorgia
    @DanBorgia 4 ปีที่แล้ว

    This was awesome! Please do make more videos like these. Security rules is taking me a while to understand but these real world examples help.

  • @rammalvarez2664
    @rammalvarez2664 6 ปีที่แล้ว +1

    Wow! Super useful video, thank you guys, great great work!

  • @AndresVillanuevand
    @AndresVillanuevand 6 ปีที่แล้ว +1

    Great video folks!

  • @smartcontxlimited5658
    @smartcontxlimited5658 6 ปีที่แล้ว

    Really helpful instruction - thank you!

  • @artursponchiado7265
    @artursponchiado7265 5 ปีที่แล้ว

    Really good video, thanks!!

  • @haythamabdulla3321
    @haythamabdulla3321 6 ปีที่แล้ว

    This is really great video!!! Thanks

  • @robertshawnmitchell
    @robertshawnmitchell 6 ปีที่แล้ว

    This is great, thanks!

  • @AbhishekKumar-mq1tt
    @AbhishekKumar-mq1tt 6 ปีที่แล้ว

    Thank you for this awesome video

  • @DenisTRUFFAUT
    @DenisTRUFFAUT 6 ปีที่แล้ว +1

    Great video. Creating Firestore rules helps to reduce code overhead !
    Questions :
    - Can I do crazy things in functions, like fetch ? (not an actual use case, just to know the limit)
    - Is there a performance impact, when accessing data, to check data with functions ?
    - Are ES6 functions supported ? const fn = param => { /* something */ }

  • @MarkValenzia
    @MarkValenzia 6 ปีที่แล้ว +2

    Awesome series guys, just found an error at 7:29 shouldn't the `isUser` and `isAdminUser` functions param be used in the function body? So pass in say `userDoc` then check `userDoc.size() == 1` and not `message.size() == 1`.
    I would also love to see some advanced data modelling tips using Firestore and how to use references to other docs.

  • @IljaDidDevs2
    @IljaDidDevs2 6 ปีที่แล้ว +7

    How did you guys manage to get syntax highlighting on .rules file? :O

  • @manassengudia1854
    @manassengudia1854 6 ปีที่แล้ว

    This is great !!

  • @robertotomas
    @robertotomas 5 ปีที่แล้ว +1

    best intro ever :)

  • @elevatetechai2024
    @elevatetechai2024 5 ปีที่แล้ว

    freaking awesome

  • @danieljimenezG
    @danieljimenezG 6 ปีที่แล้ว +1

    Great video! [ 5:33 and 7:27 ]There is an error inside these functions, the parameter is called user, and instead message is used.

  • @FidelGuajardo
    @FidelGuajardo 6 ปีที่แล้ว

    Good stuff

  • @amarendradeo816
    @amarendradeo816 6 ปีที่แล้ว

    Security is First.....Good Video

  • @adetayogisanrin8957
    @adetayogisanrin8957 4 ปีที่แล้ว

    I love this. Can you do a video on how to secure an e-commerce website?

  • @gofudgeyourselves9024
    @gofudgeyourselves9024 6 ปีที่แล้ว

    Now that's the guy I want to see in a firebase video

  • @guruprasath8263
    @guruprasath8263 6 ปีที่แล้ว +1

    The ```isUser()``` function is with the parameter ```user``` and ```message``` is used inside the definition. And in Firestore it became ```userDoc```.
    Not to be like nitpicking, but please get the demo right because we trust you guys to be "Pros"

  • @DarlantenCaten
    @DarlantenCaten 5 ปีที่แล้ว +1

    Can we get a similar video with advanced security rules for Realtime Database please?

  • @MechyBang
    @MechyBang 6 ปีที่แล้ว

    Great tutorial!
    But wouldn’t it be easier to integrate schemas for Firestore?
    Also, the “Authentication and User-Document” design pattern seems to be a desirable feature? So why not allowing custom meta data for Auth objects?

  • @indrajitsaha253
    @indrajitsaha253 6 ปีที่แล้ว +2

    What about the code on the console for real-time database?

  • @mika2666
    @mika2666 6 ปีที่แล้ว

    in your /match/{userId} you're checking if the the request.auth.uid is both equal AND not equal to userId so it will not work?

  • @dalemoncayo
    @dalemoncayo 6 ปีที่แล้ว

    Just wow.

  • @mikemagss
    @mikemagss 6 ปีที่แล้ว

    Is there any way to secure the contents of an array using firestore rules?

  • @zacharytelschow4088
    @zacharytelschow4088 6 ปีที่แล้ว

    Awesome video - very timely for me. Is the code available anywhere?

  • @MechyBang
    @MechyBang 6 ปีที่แล้ว +1

    How can you achieve syntax highlighting?
    I've found this plugin for VS Code (github.com/toba/vsfire), but is there one for WebStorm?

  • @dishantmahajan8238
    @dishantmahajan8238 6 ปีที่แล้ว

    @5:37 the isUser function must be using user ref or it has to use message ref
    According to me that's an error here 😅😅😅

  • @Lindauson
    @Lindauson 6 ปีที่แล้ว

    Could you elaborate on User/Role initialization. That is, what would be the best way to initialize the first Admin role User?

    • @robertshawnmitchell
      @robertshawnmitchell 6 ปีที่แล้ว +1

      I'd probably just do that through the console manually

  • @milindkpatil
    @milindkpatil 6 ปีที่แล้ว

    Hi, Nice and helpful Video -Thanks.
    Question- In an app if/where we wish to limit the 'read, write' for any user to limit to just the records created by that user - how do I define the rule on server?
    The document field that has the user info (uid) is author_id - I tried this
    [service cloud.firestore {
    match /databases/{database}/documents {
    match /{document=**} {
    allow read, write: if request.auth.uid == resource.data.author_id;
    ...]
    and also tried various other combinations - it did not work.
    Important - I do NOT wish to specify this filter on the client side - because anyone can change the client JavaScript and remove the filter thereby seeing ALL the records.
    [this.db.collection('mytable', ref => ref.where('author_id', '==', this.authService.getUser().uid)).snapshotChanges().map(docArray => ...
    and hacker may replace the above example code with this on client JavaScript before the post command.
    this.db.collection('mytable').snapshotChanges().map(docArray => ...] (where clause removed)
    ]
    Please help!

  • @albertogomez9574
    @albertogomez9574 6 ปีที่แล้ว +2

    Great video! I would like to know how to avoid someone from making too many requests, even if it’s an authenticated user they could make thousands of requests per second. Is there a way to prevent this? Otherwise this would cost a lot since firebase charges per use

    • @blessing7695
      @blessing7695 6 ปีที่แล้ว

      I have seen looking for the answer to this very question, hopefully someone replies with some good leads.

    • @martinngregersen
      @martinngregersen 5 ปีที่แล้ว

      stackoverflow.com/questions/47050240/firebase-cloud-function-how-to-deal-with-continuous-request

    • @urbaniv
      @urbaniv 4 ปีที่แล้ว +2

      If you have authenticated users you could add a document where you store the timestamp of the last request. In your security rules, you can compare the timestamp of the request and the timestamp of the last request. The most important thing is, firestore can't be your cms system for let's say your public website. you should only use firestore with authenticated users. Any public data can be misused. Another possibility would be to create anonymous users for every visitor - at least that gives you a little bit of restriction. And of course, disable localhost as allowed domains for creating users so that users can't be created from any localhost. I know one year later but perhaps still useful.

  • @utsavmangla8552
    @utsavmangla8552 6 ปีที่แล้ว

    Can we similarly apply these roles to Firebase Realtime DB too? 😋

  • @mikemagss
    @mikemagss 6 ปีที่แล้ว

    Both isUser and isAdminUser have a 'user' parameter but make use of a 'message' object. Am I not following or is that a mistake?

  • @Albertmars32
    @Albertmars32 6 ปีที่แล้ว +6

    how to integrate stripe with firebase cloud funtions

    • @bensonmwaura9494
      @bensonmwaura9494 6 ปีที่แล้ว

      Hi! Here's a great resource for handling stripe integration by AngularFirebase th-cam.com/video/Lb-Pnytoi-8/w-d-xo.html

    • @ruissantos2737
      @ruissantos2737 6 ปีที่แล้ว

      See if it's what you are looking for: th-cam.com/video/_lZc2O2oUJk/w-d-xo.html. Angular Firebase channel(th-cam.com/channels/sBjURrPoezykLs9EqgamOA.html) has some awesome videos.

    • @MechyBang
      @MechyBang 6 ปีที่แล้ว

      th-cam.com/video/NsPGRIVOg0U/w-d-xo.html

  • @BenHayat
    @BenHayat 5 ปีที่แล้ว

    Why hasn't these series (The pro series) grown at all? We really need advance and pro videos from Google engineers than someone trying to make sales pitch to buy into Firebase.

  • @michaelscofield2652
    @michaelscofield2652 6 ปีที่แล้ว

    Can't wait to see all the pwned apps build in Firebase.

  • @pnadmin7927
    @pnadmin7927 6 ปีที่แล้ว

    The isUser function have a issue, the function parm is user, but in the function you're using message.

  • @chrissimmons1168
    @chrissimmons1168 6 ปีที่แล้ว

    Can the next video be how to deploy a React Nodejs Firebase web app?

  • @admiralman895
    @admiralman895 5 ปีที่แล้ว

    Hey Mike, I have followed your approach by using the RoomExists check and have found that it doesn't work as expected. If you actually perform a SET and the document exists the SET performs an UPDATE and as such bypasses your !roomexists check. Granted, since there is no UPDATE rule any update would fail. So my question is why have the check in the first place? Watching the video it seems like you are trying to convey that the roomExists check actually stops a create if TRUE...well, it does but not really so its a little misleading.

  • @nipunmadan1989
    @nipunmadan1989 5 ปีที่แล้ว

    I think this approach is not solving bootstrapping problem. How can i give user the admin role? @Mike McDonald

  • @makemypetgamedevprocess6475
    @makemypetgamedevprocess6475 2 ปีที่แล้ว

    👍

  • @ecsyntric
    @ecsyntric 5 ปีที่แล้ว

    firebase is touted to be extremely easy. the rules system hopefully allays all those misconceptions

  • @JoseVibar
    @JoseVibar 5 ปีที่แล้ว

    Firebase & Elasticsearch ?

  • @robertshawnmitchell
    @robertshawnmitchell 6 ปีที่แล้ว

    Repo for this example? I want to steal it!

  • @lsd22252
    @lsd22252 6 ปีที่แล้ว

    I would appreciate a focus on locking down a vanilla JS PWA to ensure that only authenticated users can run the app.

  • @mika2666
    @mika2666 6 ปีที่แล้ว +1

    because this is google we're gonna build a new group chat app LOOOOOL

  • @MohdAkmalZakiIO
    @MohdAkmalZakiIO 6 ปีที่แล้ว

    It should be, "How to Build Secure Chat App in Firebase". I thought it's a general video on security in Firebase.

  • @michaeloosthuizen2383
    @michaeloosthuizen2383 5 ปีที่แล้ว

    request.resource.data.size() does not work in the wild. The simulator will pass the rule, but in the wild it will fail.
    Edit: I discovered why! request.resource.data will add fields that exist in the document even if they are not in the request. Must be a bug in the simulator. I wanted to prevent a field from being changed, ended up having to add it to the fields I was counting on receiving and then add a request.resource.data.xyz == resource.data.xyz clause to prevent it from being changed.

    • @gomsoares
      @gomsoares 5 ปีที่แล้ว +1

      yeah, i have the same problem today, thinking that request.resource.data have only the update values, and the simulator not complaining.
      but you can use `request.writeFields` to get the fields that are being updated, and to prevent a update on a field, you can do !('someField' in request.writeFields).
      you can even create a function to simplify:
      function notUpdating(field) {
      return !(field in request.writeFields)
      }
      and just call notUpdating('someField')