Possible To Change Firebase Callable Functions Data On Front End?
I'm using Stripe and Firebase Function for payment. My current scenario for buying items in my app looks like the following.
- Loading an Item, which is an firestore document with an Id and a price
- User clicks on "Buy now for price", enters credit card information and confirems
- I get a stripe source with an id, which to my knowledge contains information about the credit card
- I call my firestore callable function and pass the
stripeSourceId
,itemID
and theitem.price
- In my function I check if the user (from context) is authentiated, then I charge the user and save the bought item in the user data, to deisplay the item later
My concerns are the point 4. Is it possible for a user to hack my front end code in a way, so that after stripe returns the sourceId
, the hacker would call the function with a different price or a different itemId to get a different item for another price? If that is the case, how could I fix this problem?
Answer
Anything you pass from the client to the server, can be changed by a malicious user. That's why you should never trust any data that comes directly from the server.
The solution is to only pass the itemID from the client, and have the server look up the price based on that. If the malicious user passes a different item ID, they'll just be buying a different item, but still at the price that you have set.
I highly recommend watching Five tips to secure your app from the Firebase Summit 2018 for more tips on securing your app.
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?