Don't log the user's refresh token

This commit is contained in:
Roland Geider
2026-06-14 20:35:23 +02:00
parent efaa5121c5
commit db458acee4
2 changed files with 10 additions and 6 deletions

View File

@@ -113,7 +113,8 @@ class AppLinkRouter {
Future<void> _handle(Uri uri) async {
final token = tokenFromUri(uri);
if (token == null) {
_logger.fine('Ignoring unrelated or malformed deep link: $uri');
// Never log the fragment: it carries the refresh token on our links.
_logger.fine('Ignoring unrelated or malformed deep link: ${uri.removeFragment()}');
return;
}
final state = fragmentParam(uri, 'state');
@@ -124,7 +125,10 @@ class AppLinkRouter {
// Unsolicited link (no outstanding state), stale (past TTL), or state
// mismatch, all three look the same from here and are all rejected by
// design. Login-CSRF defence: only accept handoffs the app started itself.
_logger.warning('Rejecting handoff deep link with bad/missing state: $uri');
// Strip the fragment before logging: it carries the refresh token
_logger.warning(
'Rejecting handoff deep link with bad/missing state: ${uri.removeFragment()}',
);
return;
}
try {

View File

@@ -800,11 +800,11 @@ class AuthNotifier extends _$AuthNotifier {
newRefresh = (data?['refresh_token'] ?? meta?['refresh_token']) as String?;
newExp = jwtExp(decodeJwtPayload(newAccess));
} catch (e, s) {
final bodySnippet = response.body.length > 500
? '${response.body.substring(0, 500)}...'
: response.body;
// Don't log the body: on the success-shaped path it holds the rotated
// refresh token
_logger.warning(
'refreshAccessToken: malformed response body, clearing session. Body: $bodySnippet',
'refreshAccessToken: malformed response body, clearing session. '
'Status: ${response.statusCode}, body length: ${response.body.length}',
e,
s,
);