[firebase_ai] Live sessions on web don't send the App Check token

Abierto
#18,938 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
dart, firebase, flutter

Línea de trabajo

Start with lib/src/live_session.dart and live_model.dart, then check how web WebSocket connections can pass Firebase App Check and Auth tokens and whether the backend accepts them in the query or setup message. Reproduce the reported Chrome connection with App Check enforced; done means Live sessions send the required tokens on web and the server no longer closes them with code 1008.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

blocked: external dependency platform: web plugin: ai type: bug
Bug

On web, a LiveGenerativeModel session doesn't send the App Check token, so when App Check is enforced for Firebase AI Logic the server closes every Live session right after it connects:

WebSocket Closed, closeCode: 1008, closeReason: Firebase App Check token is invalid.

Non-Live requests in the same app pass App Check with the same token.

Cause

LiveSession._defaultConnector in lib/src/live_session.dart drops the headers on web:

static WebSocketChannel _defaultConnector(
        Uri uri, Map<String, String> headers) =>
    kIsWeb
        ? WebSocketChannel.connect(uri)
        : IOWebSocketChannel.connect(uri, headers: headers);

live_model.dart builds those headers with BaseModel.firebaseTokens(...), so the X-Firebase-AppCheck header (and the Auth token) only reach the server on native platforms. On web the token is in neither the URL (only ?key=) nor the setup message. Browsers can't set headers on a WebSocket, so the token needs to travel another way, for example as a query parameter or in the setup message, if the backend accepts one.

Same code in firebase_ai 3.15.0, 4.0.0, 5.0.0 and 5.1.0.

Repro
  1. Enforce App Check for Firebase AI Logic and register a web debug token.
  2. On Chrome, connect a Live session, for example FirebaseAI.googleAI().liveGenerativeModel(model: 'gemini-3.8-live') and connect().
  3. The server closes the socket with 1008 "Firebase App Check token is invalid".

Seen with the Gemini Developer API and with Agent Platform (us-central1). Found through the Genkit Firebase AI plugin: genkit-ai/genkit-dart#730.

Versions

firebase_ai 5.1.0, Flutter 3.47.9, Chrome.

Lenguaje dominante
Dart
Estrellas
9.3k
Forks
4.1k
Merge medio
2 d 10 h
PR fusionados (30 d)
78

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/flutterfire

Todos los issues de firebase/flutterfire

Issues similares

Más issues de Dart

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.