MeshCentral: OIDC authentication causes critical error

Describe the bug Starting in version 1.1.22 and remaining in 1.1.24, OpenID/OIDC logins redirect to authentication server correctly, but the return to “https://mesh.example.com/oidc-callback?code=[redacted]” fails. In the case of using nginx reverse proxy, the error is “502 Bad Gateway”.

Meshcentral restarts after this crash.

To Reproduce Steps to reproduce the behavior:

  1. Attempt login using OIDC

Expected behavior Succesful login presenting the meshcentral dashboard

Error in mesherrors.txt

-------- 5/28/2024, 1:39:35 PM ---- 1.1.24 --------

/opt/meshcentral/meshcentral/node_modules/passport/lib/middleware/authenticate.js:134
          req.flash(type, msg);
              ^

TypeError: req.flash is not a function
    at allFailed (/opt/meshcentral/meshcentral/node_modules/passport/lib/middleware/authenticate.js:134:15)
    at attempt (/opt/meshcentral/meshcentral/node_modules/passport/lib/middleware/authenticate.js:183:28)
    at strategy.fail (/opt/meshcentral/meshcentral/node_modules/passport/lib/middleware/authenticate.js:314:9)
    at /opt/meshcentral/meshcentral/node_modules/openid-client/lib/passport_strategy.js:198:12
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.12.1

Server Software (please complete the following information):

  • OS: Ubuntu 22.04
  • Virtualization: LXC on ProxMox
  • Network: nginx reverse proxy
  • Version: 1.1.24
  • Node: v20.12.1

Client Device (please complete the following information):

  • Device: All
  • OS: Any

Remote Device (please complete the following information): N/A

Additional context Add any other context about the problem here.

Your config.json file

{
  "$schema": "https://raw.githubusercontent.com/Ylianst/MeshCentral/master/meshcentral-config-schema.json",
  "settings": {
    "plugins":{"enabled": false},
    "_mongoDb": null,
    "cert": "redacted",
    "_WANonly": true,
    "_LANonly": true,
    "sessionKey": "redacted",
    "port": 443,
    "_aliasPort": 443,
    "redirPort": 80,
    "_redirAliasPort": 80,
    "AgentPong": 300,
    "TLSOffload": true,
    "SelfUpdate": false,
    "AllowFraming": false,
    "WebRTC": false,
    "_trustedProxy": "CloudFlare",
    "trustedProxy": "10.0.42.253",
    "_ignoreAgentHashCheck": true
  },
  "domains": {
    "": {
      "_title": "MyServer",
      "_title2": "Servername",
      "minify": true,
      "NewAccounts": false,
      "authStrategies": {
        "oidc": {
          "authorizationURL": "https://auth.example.com/application/o/authorize/",
          "callbackURL": "https://mesh.example.com/oidc-callback",
          "clientid": "redacted",
          "clientsecret": "redacted",
          "issuer": "https://auth.example.com/application/o/meshcentral/",
          "tokenURL": "https://auth.example.com/application/o/token/",
          "userInfoURL": "https://auth.example.com/application/o/userinfo/",
          "logoutURL": "https://auth.example.com/application/o/meshcentral/end-session/",
          "NewAccounts": true
        }
      },
      "localSessionRecording": false,
      "_userNameIsEmail": true,
      "certUrl": "https://mesh.example.com",
      "cert": "*.example.com"
    }
  },
  "_letsencrypt": {
    "__comment__": "Requires NodeJS 8.x or better, Go to https://letsdebug.net/ first before>",
    "_email": "myemail@mydomain.com",
    "_names": "myserver.mydomain.com",
    "production": false
  }
}

docker-compose.yml

#version: '3'

networks:
  meshcentral-tier:
    driver: bridge

services:
  mongodb:
    restart: always
    container_name: mongodb
    image: mongo:latest
    env_file:
      - .env
    volumes:
      # mongodb data-directory - A must for data persistence
      - ./meshcentral/mongodb_data:/data/db
    networks:
      - meshcentral-tier

  meshcentral:
    restart: always
    container_name: meshcentral
    # use the official meshcentral container
    image: ghcr.io/ylianst/meshcentral:latest
    #image: ghcr.io/ylianst/meshcentral:1.1.21
    depends_on:
      - mongodb
    ports:
      # MeshCentral will moan and try everything not to use port 80, but you can also use it if you so desire, just change the config.json according to your needs
      - 8086:443
    env_file:
      - .env
    volumes:
      # config.json and other important files live here. A must for data persistence
      - ./meshcentral/data:/opt/meshcentral/meshcentral-data
      # where file uploads for users live
      - ./meshcentral/user_files:/opt/meshcentral/meshcentral-files
      # location for the meshcentral-backups - this should be mounted to an external storage
      - ./meshcentral/backup:/opt/meshcentral/meshcentral-backups
      # location for site customization files
      - ./meshcentral/web:/opt/meshcentral/meshcentral-web
    networks:
      - meshcentral-tier

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

ok ive fixed the reauth problem! https://github.com/Ylianst/MeshCentral/commit/c67a76bcc27bfe2b62b9043e8dddec5ba0a8b449 basically when u first hit the oidc callback from your provider you have session info, but when u try hitting the page again (by say pressing back history) the session info had vanished as you are already logged in and verified. so just need to do a check to carry on if you already authed!