matcha icon indicating copy to clipboard operation
matcha copied to clipboard

BUG: OAuth2 token expiry not validated before use

Open andrinoff opened this issue 7 months ago • 2 comments

Describe the bug

In fetcher/fetcher.go lines 240-243, OAuth2 token fetched without expiration check:

token, err := config.GetOAuth2Token(account.Email)
if err != nil {
    return nil, fmt.Errorf("oauth2: %w", err)
}
// Token used immediately without expiry check

If token expired, IMAP connection fails with unclear auth error instead of refreshing token.

To reproduce

  1. Configure OAuth2 for account
  2. Let token expire
  3. Start matcha
  4. Connection fails - "authentication failed" instead of auto-refresh

Expected behavior

Check expiry and refresh if needed:

token, err := config.GetOAuth2Token(account.Email)
if err != nil {
    return nil, fmt.Errorf("oauth2: %w", err)
}

// Check if token expired
if !token.Valid() {
    // Refresh token
    newToken, err := refreshOAuth2Token(token)
    if err != nil {
        return nil, fmt.Errorf("oauth2 token refresh failed: %w", err)
    }
    token = newToken
    // Save refreshed token
}

Screenshots

N/A

Additional context

  • File: fetcher/fetcher.go
  • Lines: 240-243
  • Severity: Medium - failed connections with expired tokens
  • Fix complexity: Medium - implement token refresh logic

andrinoff avatar Apr 16 '26 20:04 andrinoff

This has had no activity for 30 days. It will be closed in 14 days unless updated. Comment or remove the stale label to keep it open.

floatpanebot avatar May 17 '26 05:05 floatpanebot

Closing due to inactivity. Reopen if still relevant.

floatpanebot avatar May 31 '26 06:05 floatpanebot