Switching default instance silently invalidates user sessions with no notice or re-auth prompt

Open
#737 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go

Research direction

Start in server/instance.go at setDefaultInstance, then read server/configuration.go and server/plugin.go to trace how the active instance changes and how user tokens are stored. Check the connection and status paths that use those tokens. Done means users are told to reconnect after a default switch and invalid tokens produce a reconnect prompt; the issue names no tests to run.

Written by the indexing model from the issue text.

Description

Summary

When an administrator switches the default GitLab instance using /gitlab instance set-default <name>, all currently connected users' OAuth tokens become invalid against the new instance. However, no notification, broadcast, or token invalidation occurs, leaving users with broken slash commands and silent notification failures.

Steps to Reproduce
  1. Have two instances installed (instance-a and instance-b), with instance-a as the default.
  2. Users connect their accounts via /gitlab connect (storing tokens issued by instance-a).
  3. An administrator switches the default instance using /gitlab instance set-default instance-b.
  4. A connected user runs /gitlab me, /gitlab todo, or creates an issue.
    • Result: Commands fail with 401 Unauthorized or token errors because the plugin passes instance-a tokens to instance-b.
Expected Behavior
  1. When the default instance changes, connected users should receive a notification (or a system message in Town Square / DM) informing them that the active instance changed to <name> (<url>) and prompting them to reconnect via /gitlab connect.
  2. The user profile / status check should recognize that stored tokens do not match the active instance and display a disconnected / reconnect prompt instead of raw API errors.
Root Cause / Code References
  1. server/instance.go:
    • setDefaultInstance only mutates config.DefaultInstanceName and calls p.refreshEffectiveInstance().
  2. server/configuration.go:
    • refreshEffectiveInstance re-resolves the internal API client and command autocomplete, but does not notify users or inspect stored user tokens.
  3. server/plugin.go:
    • Stored tokens in KV (<userID>_userinfo and <userID>_gitlabtoken) are global to the Mattermost user and lack instance metadata, meaning the plugin blindly sends the prior instance's token to the newly selected instance.
Proposed Fix
  1. In setDefaultInstance, notify connected users or post a broadcast message alerting them to reconnect to the new default instance.
  2. In user connection verification, check token validity against /api/v4/user on the active instance and guide the user to reconnect if a 401 Unauthorized is encountered.
Dominant language
JavaScript
Stars
158
Forks
97
Avg merge
2d 17h
Merged PRs (30d)
21

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mattermost/mattermost-plugin-gitlab

All issues in mattermost/mattermost-plugin-gitlab

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.