Skip to content

Commit d27f700

Browse files
authored
Keep the refreshed access token out of the log (#1287)
## Problem With verbose SDK logging on, the access token the server refreshes during a session is written to the log, on every platform. An app that turns on FINE logging, or forwards SDK logs to a crash reporter or a support bundle, ends up with a usable token in them. #1275 masked the token in the signalling URL log line. This is the other place it was logged. ## Cause `SignalTokenUpdatedEvent.toString()` printed the token. Events are logged with their text form in two places: - the event emitter logs every emitted event at FINEST - the signal client logs every signal event at FINE The event is emitted each time the server refreshes the token, and when the participant is moved to another room, and each emit writes the new token twice. ## Fix The event's text form now says `token: <redacted>`. The event still carries the token for the code that needs it. ## Testing - New unit test `test/core/signal_token_log_test.dart`: emits the event with logging at its most verbose and checks that no log record contains the token. It fails without the fix and passes with it. - Full suite: 575 passed, 1 skipped. Analyze, format and import order pass. - e2e-flutter, new scenario "The access token stays out of the logs" (local branch `hiroshi/token-log-scenario`, not pushed yet). It scans every log record through a connect, a resume, a full reconnect and a disconnect for anything shaped like a token, on macOS: | livekit_client | Result | |---|---| | `release/2.14.0` 7adfa35 | fails, 6 records carry a token, from the two log lines above | | this branch | passes, 599 records and none carries a token | ## Notes - Not a regression. The published 2.13.2 logs the token the same way. - A candidate for 2.14.0 (#1286), since that release's changelog already says the token is kept out of the signalling log.
1 parent f9a7dc7 commit d27f700

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "The access token the server refreshes during a session is no longer written to the log. The internal event that carries it printed the token, and every emitted event is logged at FINEST level, so an app that enabled the most verbose logging or forwarded SDK logs wrote a usable token to its logs"

‎lib/src/internal/events.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,9 @@ class SignalTokenUpdatedEvent with SignalEvent, InternalEvent {
554554
required this.token,
555555
});
556556

557+
// Every emitted event is logged, so the token itself stays out of this.
557558
@override
558-
String toString() => '${runtimeType}(token: ${token})';
559+
String toString() => '${runtimeType}(token: <redacted>)';
559560
}
560561

561562
@internal
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2026 LiveKit, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:flutter_test/flutter_test.dart';
16+
import 'package:logging/logging.dart';
17+
18+
import 'package:livekit_client/src/events.dart';
19+
import 'package:livekit_client/src/internal/events.dart';
20+
import 'package:livekit_client/src/managers/event.dart';
21+
22+
void main() {
23+
test('a refreshed token is not written to the log when its event is emitted', () async {
24+
const token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIn0.c2lnbmF0dXJl';
25+
final messages = <String>[];
26+
final previous = Logger.root.level;
27+
Logger.root.level = Level.ALL;
28+
final subscription = Logger.root.onRecord.listen((record) => messages.add(record.message));
29+
addTearDown(() async {
30+
await subscription.cancel();
31+
Logger.root.level = previous;
32+
});
33+
34+
final emitter = EventsEmitter<SignalEvent>();
35+
addTearDown(emitter.dispose);
36+
emitter.emit(const SignalTokenUpdatedEvent(token: token));
37+
await pumpEventQueue();
38+
39+
expect(
40+
messages.where((m) => m.contains('SignalTokenUpdatedEvent')),
41+
isNotEmpty,
42+
reason: 'the emit is logged, otherwise this checks nothing',
43+
);
44+
expect(messages.where((m) => m.contains(token)), isEmpty);
45+
});
46+
}

0 commit comments

Comments
 (0)