Skip to content

MCP OAuth expires_in=0 is saved as non-expiring #5355

Description

@tt-a1i

What happened?

MCP OAuth token responses treat expires_in=0 as if no expiry was provided.

In both authenticate() and refresh handling, the code only sets expiresAt when tokenResponse.expires_in is truthy:

if (tokenResponse.expires_in) {
  token.expiresAt = Date.now() + tokenResponse.expires_in * 1000;
}

So a token endpoint response like this:

access_token=tok&token_type=Bearer&expires_in=0

gets saved without expiresAt, which makes it look non-expiring instead of immediately expired.

The form-urlencoded parser also uses parseInt, so malformed values such as expires_in=3600abc are partially accepted.

What did you expect?

expires_in=0 should produce an immediate expiresAt, and malformed expires_in values should not be silently accepted or saved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category/authenticationAuthentication and authorizationpriority/P2Medium - Moderately impactful, noticeable problemscope/mcpModel Context Protocolscope/oauthOAuth authentication flowstype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions