Summary
fast-mcp-telegram improperly builds session file paths directly from bearer tokens, allowing crafted tokens with path separators to select unintended sessions.
A remote HTTP client can exploit this to authenticate as the default legacy session, gaining access to tools and capabilities intended for a different account when a default session file exists.
Affected context
This vulnerability occurs in fast-mcp-telegram deployments that:
- Expose the HTTP MCP server interface to remote clients
- Use file-based sessions where bearer tokens map to session filenames
- Keep the documented default session file (e.g.,
~/.config/fast-mcp-telegram/telegram.session) present - Rely on the reserved
telegramsession name protection to separate HTTP users from the default stdio or legacy account
In such environments, the path derived from a bearer token is not normalized or sanitized before use, enabling bypass of the reserved session control.
Exploit preconditions
- Attack surface: HTTP interface of the fast-mcp-telegram server.
- Required access: Ability to send HTTP requests with arbitrary Bearer tokens to the server (no prior authentication needed).
- Trigger point: The authentication routine that:
- Takes the raw bearer token string,
- Joins it into a session-file path,
- Checks whether the corresponding session file exists, while only rejecting the exact literal token
telegram.
- Why exploitation is possible:
- The verifier does not normalize or sanitize the token-derived path.
- Path separators such as
../are accepted in the token value. - The reserved token check only matches the literal string
telegram, so variants like../fast-mcp-telegram/telegramare allowed. - If a default legacy session file is present at the documented location, a crafted token can traverse into that path and select it.
Why this happens
The core issue is treating untrusted authentication material (the HTTP Bearer token) as a trusted filesystem path component without sufficient validation or normalization.
Instead of constraining tokens to safe identifier formats, the implementation joins the raw token directly into a session-file path and only special-cases the exact string telegram.
This allows path traversal sequences to alter which session file is selected and maps to:
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), by allowing
../-style traversal through the session directory. - CWE-287: Improper Authentication, because the authentication step can be bypassed or misdirected to an unintended account, authenticating a remote user as the default legacy session.
Conceptually, the bug is an insecure coupling between authentication identifiers and filesystem layout, with inadequate boundary enforcement around those paths.
Potential impact
- Remote clients may authenticate as the default legacy session without knowing its intended credentials.
- Attackers could access MCP tools and capabilities bound to the default account, including account-prefixed tools.
- Actions performed via the hijacked session can be mistaken for those of the legitimate default user.
- Depending on connected tools, attackers may read or modify data, invoke external services, or trigger automated workflows.
- Multi-user isolation between HTTP sessions and the default stdio or legacy account can be undermined.
General mitigation guidance
Effective mitigation focuses on decoupling untrusted tokens from raw filesystem paths and enforcing strict input normalization:
- Treat bearer tokens purely as opaque identifiers or keys, not as path fragments; map them to session records via a controlled lookup or a safe naming scheme.
- Restrict allowed token formats (e.g., alphanumeric plus a short, fixed-safe character set) and reject any tokens containing path separators or control characters.
- Normalize and canonicalize any token-derived path, then enforce that it resides within an expected session directory before use.
- Avoid special-casing single reserved names alone; instead, define explicit rules and allowlists for valid session identifiers.
- Where possible, store session metadata in a structured store (database or key-value store) rather than directly in filenames tied to user-controlled strings.
- Maintain least-privilege access for the process, so that compromise of a session limits the scope of accessible files and tools.
How teams detect issues like this
Organizations can detect similar vulnerabilities and misuse patterns through:
- Static analysis and code scanning:
- Flagging concatenation or joining of untrusted input (e.g., bearer tokens, headers) into filesystem paths.
- Rules that detect use of
../or path separators in values used for authentication or authorization decisions. - Code review practices:
- Scrutinizing authentication and session-selection logic for reliance on filenames or directory structures.
- Ensuring that any mapping from identifiers to paths includes canonicalization and directory boundary checks.
- Verifying that reserved names or special accounts are enforced via explicit logic, not only by filename conventions.
- Runtime monitoring and logging:
- Logging bearer token patterns in a privacy-preserving way (e.g., hashed) and flagging tokens containing path separator characters.
- Alerting on repeated failed or unusual session selection attempts, especially those referencing unexpected directories.
- Policy enforcement and tooling:
- Using security linters, SAST tools, or custom CI checks to enforce safe path-handling practices.
- Adding unit and integration tests that verify tokens with traversal patterns cannot select arbitrary or default sessions.

