Skip to content

fix: use correct path for token file deletion in clearSessionData and logOutSession#2480

Open
Aitriq wants to merge 1 commit intowppconnect-team:mainfrom
Aitriq:fix/clear-session-token-path
Open

fix: use correct path for token file deletion in clearSessionData and logOutSession#2480
Aitriq wants to merge 1 commit intowppconnect-team:mainfrom
Aitriq:fix/clear-session-token-path

Conversation

@Aitriq
Copy link
Copy Markdown

@Aitriq Aitriq commented Mar 7, 2026

Summary

clearSessionData and logOutSession fail to delete token files from the tokens/ directory due to incorrect path construction. This causes orphaned sessions to persist in show-all-sessions responses even after session data has been cleared.

Bug

Both controllers use __dirname + '../../../tokens/${session}.data.json' to build the token file path. This has two issues:

  1. String concatenation without separator__dirname does not end with /, so the resulting path is malformed (e.g. /opt/wppconnect-server/dist/controller../../../tokens/...)
  2. Wrong number of ../ — depending on whether the code runs from src/ or dist/, three levels up may not resolve to the project root

Meanwhile, FileTokenStore already uses the correct approach: path.resolve(process.cwd(), './tokens/').

Fix

Replace __dirname + '../../../tokens/...' with path.resolve(process.cwd(), 'tokens', ...) in both:

  • src/controller/miscController.ts (clearSessionData)
  • src/controller/sessionController.ts (logOutSession)

Also fix variable shadowing in clearSessionData where const path = config.customUserDataDir + session shadows the path import.

Impact

Without this fix, calling clear-session-data or logout-session removes the Chrome user data directory but leaves the token file on disk. On restart, show-all-sessions (via getAllTokens) still lists these ghost sessions and attempts to restore them — potentially spawning hundreds of unnecessary Chrome processes.

Tested on production with v2.9.0.

Test plan

  1. Start a session → verify token file exists in tokens/
  2. Call clear-session-data → verify token file is deleted
  3. Call show-all-sessions → verify session no longer appears
  4. Restart server → verify no orphaned Chrome processes spawn

… logOutSession

Token files in `tokens/` directory were never deleted because of broken
path construction using string concatenation (`__dirname + '../../../tokens/...'`).
This resulted in an invalid path that `fs.existsSync()` always returned false for.

Use `path.resolve(process.cwd(), 'tokens', ...)` instead — the same approach
used by `FileTokenStore.resolverPath()` in the WPPConnect client library.

Fixes wppconnect-team#2102

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants