Security Disclosure Recommendation: Rotate MongoDB Database Credentials

Learn how to Security Disclosure Recommendation: Rotate MongoDB Database Credentials

Mykal Machon ۳ دقیقه مطالعهمتن اصلی

Author: Mykal Machon

This guide is part of Railway's response to the security disclosure published on October 21, 2026.

If you use MongoDB on Railway, regenerate its password, redeploy every service that uses it, and confirm nothing is still connecting with the old credential.

If your MongoDB password or MONGO_URL may have been exposed, rotate your credentials. This guide applies if your database uses the Railway MongoDB template. The fastest path is Regenerate in the Database View, which changes the password inside MongoDB and updates the service variables in one step.

## Before you rotate

Three checks tell you how exposed the credential is and what you must update afterwards.

  1. Find every consumer. Open the MongoDB service's Variables tab. Services that use reference variables such as ${{ MongoDB.MONGO_URL }} pick up the new password on their next deploy. Services with a pasted connection string don't update.
  2. Check public access. Open the MongoDB service's Settings and find Networking. If Public Access is enabled, the credential is usable from anywhere through the TCP proxy until you rotate. Remove public access now if nothing outside the project needs it.
  3. List external consumers. Anything that uses MONGO_PUBLIC_URL needs the new value manually.

## Regenerate the password

Regenerate is the supported way to change a database password on Railway. It keeps the database and the variables in sync.

  1. Open the MongoDB service and click the Database tab, then Config.
  2. In the Connection section, click Regenerate next to the password. Railway changes the password inside MongoDB. See Database View: Connection.
  3. Expect new connections with the old password to fail from this point.

⚠️ Don't edit MONGOPASSWORD or MONGO_INITDB_ROOT_PASSWORD by hand and don't run db.changeUserPassword() yourself. Each changes only one side and leaves the variable and the database out of sync. If that already happened, see how to recover.

## Redeploy the services that use it

Containers read variables only at startup, so every service that uses the credential must be redeployed.

  1. Redeploy every service that references the MongoDB variables. Regenerate redeploys only the database, so these services keep the old password until you do.
  2. If a service has a pasted connection string, replace it with the reference ${{ MongoDB.MONGO_URL }} so the next rotation reaches it automatically, then deploy.
  3. Update external consumers with the new MONGO_PUBLIC_URL.

## Verify the rotation

Confirm the new credential works and nothing is still connected with the old one.

  1. Check each dependent service's deploy logs for no Authentication failed errors.

  2. Open the Database tab and confirm the Data view lists collections.

  3. Connect with the new credential using railway connect. railway connect MongoDB

  4. List active operations and sessions, and look for clients you don't recognize.

    db.currentOp(true).inprog.map(op => ({
      client: op.client,
      users: op.effectiveUsers,
      desc: op.desc,
      active: op.active,
    }));
    db.getSiblingDB("config").system.sessions.aggregate([
      { $listSessions: { allUsers: true } },
    ]);
    
  5. End a suspicious operation with db.killOp(<opid>) or a session with db.runCommand({ killSessions: [{ id: <uuid> }] }).

## Look for misuse

A rotated password stops future access. These checks show whether the old credential was used.

  • Inside MongoDB, look for users you didn't create with db.getSiblingDB("admin").getUsers().
  • Compare collection counts and the most recent documents (db.orders.find().sort({ _id: -1 }).limit(20)) against what you expect.
  • If data was altered, preserve the evidence first, then restore from a backup taken before the exposure.

If you have any other questions, contact Railway support at [email protected].

RB

منتشرشده در

Railway Blog

خواندن در منبع

ادامه مطالعه