Skip to content

[Security] WhatsApp accountId path traversal in resolveDefaultAuthDir #2692

@robbyczgw-cla

Description

@robbyczgw-cla

Summary

resolveDefaultAuthDir() in src/web/accounts.ts uses the accountId parameter directly in path.join() without sanitization, allowing potential path traversal attacks.

Vulnerable Code

// src/web/accounts.ts line 88-90
function resolveDefaultAuthDir(accountId: string): string {
  return path.join(resolveOAuthDir(), "whatsapp", accountId);
  // ^^^ accountId used directly without sanitization
}

Attack Vector

A malicious config with accountId: "../../../etc" could escape the intended directory structure. While this is config-level input (not user input), it's risky for:

  • Multi-user deployments
  • Shared configs
  • Plugin systems that might pass untrusted account IDs

Recommended Fix

Sanitize accountId similar to how Telegram does it in src/telegram/update-offset-store.ts:

function normalizeAccountId(accountId: string): string {
  const trimmed = accountId.trim();
  if (!trimmed) return "default";
  return trimmed.replace(/[^a-z0-9._-]+/gi, "_");
}

function resolveDefaultAuthDir(accountId: string): string {
  return path.join(resolveOAuthDir(), "whatsapp", normalizeAccountId(accountId));
}

Severity

Low-Medium: Config-level input, but defense-in-depth principle suggests sanitization.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions