Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "context" from HTTPS callable Cloud Functions be trusted?

I am using Cloud Functions to handle read/write to Cloud Firestore on the server side. The Cloud Functions are triggered by clients in the web app using HTTPS callable function.

When calling a Cloud Functions using HTTPS, there is a parameter sent from the client call "context" that carries user auth information. For example, a Cloud Functions on the server can look like this:

// Saves a message to the Firebase Realtime Database but sanitizes the text by removing swearwords.
exports.addMessage = functions.https.onCall((data, context) => {
  // ...
});

However, since context is passed by the client, and the client could pass in a manipulated ID token, do I need to always perform a ID token verification before trusting and using something like context.auth.uid to interact with my database?

The ID token verification I am talking about is this:

// idToken comes from the client app
admin.auth().verifyIdToken(idToken)
  .then(function(decodedToken) {
    var uid = decodedToken.uid;
    // ...
  }).catch(function(error) {
    // Handle error
  });

Essentially, I want to know if Firebase performs ID token verification automatically when passing context using https call and therefore I can go ahead and trust that if the client has manipulated context, the https call will fail due to token verification failing. Or, do I need to explicitly do a manual ID token verification on the server every single time to check the integrity of context, since the client can easily insert a manipulated token using the browser's devtools or something like that.

like image 458
LittleTomato Avatar asked Sep 15 '25 11:09

LittleTomato


1 Answers

Yes, the ID token is automatically included in the request and verified in the function. You don't have to write code to verify the toekn when using callable functions.

like image 85
Doug Stevenson Avatar answered Sep 17 '25 20:09

Doug Stevenson