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

未关闭
#18,938 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
dart, firebase, flutter

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Dart
星标
9.3k
派生
4.1k
平均合并
2 天 10 小时
30 天内合并 PR
78

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/flutterfire 的其他 Issue

查看 firebase/flutterfire 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。