Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special FieldValues not properly checked - major security risk #673

Open
Joebayld opened this issue Feb 21, 2021 · 1 comment
Open

Special FieldValues not properly checked - major security risk #673

Joebayld opened this issue Feb 21, 2021 · 1 comment

Comments

@Joebayld
Copy link

I'm trying to run an export but the timestamp special datatype doesn't seem to be working.. I'm testing in the Emulator and Production. When performing the export, the data looks like the following:

{
  "5Ie1pOL8": {
    "updated_at": {
      "_seconds": 1613879304,
      "_nanoseconds": 172000000
    },
    "__collections__": {}
  }
}

It's just exporting the raw Firebase timestamp and not the formatted special type.

Any ideas?

@Joebayld
Copy link
Author

Joebayld commented Feb 21, 2021

Just an update -

Did some digging and it found the issue resides in the serializeSpecialTypes function. Seems like when checking if the data is an instanceOf a FieldValue, all those checks fail as the instanceOf fail. Why? I think because it's checking it's own instance of firebase-admin and not the library in your project. It shouldn't even install firebase-admin as a dependency if the project is also using it..

This can end up EXTREMELY DANGEROUS. I did some digging and when you are exporting a FieldValue of type DocumentReference it exports the entire firebase ref as JSON. Included in that firebase ref is the service account private keys!

This is extremely dangerous - there must be some checks to make sure this can't happen. Here's a screenshot of the JSON I got back.

Screen Shot 2021-02-21 at 4 26 16 AM

Possible Fix

Something I did and seemed to fix it is instead of these calls:

if (rawValue instanceof admin.firestore.Timestamp)
if (rawValue instanceof admin.firestore.GeoPoint)
if (rawValue instanceof admin.firestore.DocumentReference)

We could check the constructor - which wouldn't rely on using the exact same library, but rather any admin library as long as the types are the same name.

if (rawValue.constructor.name === 'Timestamp')
if (rawValue.constructor.name === 'GeoPoint')
if (rawValue.constructor.name === 'DocumentReference')

@Joebayld Joebayld changed the title Timestamps not exporting properly Special FieldValues not properly checked - major security risk Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant