Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
Firestore rules 'Simulated read allowed' but fails in browser

My security rules are super simple. I have two collections - riders and races:

  • riders: can only be read from or written to when the user is signed in
  • races: can be read from by unauthenticated user; written to when user is signed in.
service cloud.firestore {
  match /databases/{database}/documents {    
    // restrict read/write on all to authenticated
    match /{document=**} {
      allow read, write: if request.auth != null;
      
      // then allow collection read if match
      match /races/{id} {
        allow read, list: if true;
      } 
      
    }
  }  
}

These rules allow what appears to be the correct setup using the Firebase consoles Rules Playground but in the browser auth users behave as expected but the unauthed users are returned an error when making a call for a race:

core.js:6456 ERROR FirebaseError: Missing or insufficient permissions.
    at new e (prebuilt-47338342-439a2133.js:188)
    at prebuilt-47338342-439a2133.js:10415
    at prebuilt-47338342-439a2133.js:10416
    at e.onMessage (prebuilt-47338342-439a2133.js:10438)
    at prebuilt-47338342-439a2133.js:10355
    at prebuilt-47338342-439a2133.js:10386
    at prebuilt-47338342-439a2133.js:15146
    at ZoneDelegate.invoke (zone.js:372)
    at Zone.run (zone.js:134)
    at zone.js:1276




// service call

this.racesCollection = this.firestore.collection<Race>('races');

this.racesCollection
      .doc(id)
      .valueChanges()
      .pipe(takeUntil(this.destroy$))
      .subscribe((response: any) => {
        console.log('=== APP SERVICE emits race ===', response);
        this.race.next(response);
      });

I've tried rewriting the rules but cannot seem to find my way around this one. Any help or ideas appreciated! Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should write your security rules in such a way they overlap:

service cloud.firestore {
  match /databases/{database}/documents {    
    // restrict read/write on all to authenticated
    match /{document=**} {
      allow read, write: if request.auth != null;      
    }

    // then allow read for the races collection for all users
    match /races/{id} {
      allow read, list: if true;
    } 

  }  
}

In addition, note that list is a "sub-case" of read, so you might remove the list rule, i.e. just do allow read: if true;.


BTW, the simulator does correctly show that your rules do not allow reading a document in the races collection if you are not authenticated.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda