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

Đang mở
#18,938 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart, firebase, flutter
Lĩnh vực
api, authentication

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Dart
Star
9.3k
Fork
4.1k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
78

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/flutterfire

Tất cả issue của firebase/flutterfire

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.