CVE-2023-50713 (TypeScript, published 2023-12-14T19:15Z)
Description: value: Speckle Server provides server, frontend, 3D viewer, and other JavaScript utilities for the Speckle 3D data platform. A vulnerability in versions prior to 2.17.6 affects users who: authorized an application which requested a 'token write' scope or, using frontend-2, created a Personal Access Token (PAT) with `token write` scope. When creating a new token an agent needs to authorise the request with an existing token (the 'requesting token').  The requesting token is required to have token write scope in order to generate new tokens. However, Speckle server was not verifying that other privileges granted to the new token were not in excess of the privileges of the requesting token. A malicious actor could use a token with only token write scope to subsequently generate further tokens with additional privileges. These privileges would only grant privileges up to the existing privileges of the user. This vulnerability cannot be used to escalate a user's privileges or grant privileges on behalf of other users.

This has been patched as of version 2.17.6. All operators of Speckle servers should upgrade their server to version 2.17.6 or higher. Any users who authorized an application with 'token write' scope, or created a token in frontend-2 with `token write` scope should review existing tokens and permanently revoke any they do not recognize, revoke existing tokens and create new tokens, and review usage of their account for suspicious activity. No known workarounds for this issue exist.
Severity: nan (CVSS v3 base score: 5)
Weakness: CWE-1220 \u2014 Insufficient Granularity of Access Control
The product implements access controls via a policy or other feature with the intention to disable or restrict accesses (reads and/or writes) to assets in a system from untrusted agents. However, implemented access controls lack required granularity, which renders the control policy too broad because it allows accesses from unauthorized agents to the security-sensitive assets.
Repository: https://github.com/specklesystems/speckle-server
Files changed:
packages/frontend-2/components/developer-settings/CreateEditApplicationDialog.vue
packages/frontend-2/components/developer-settings/CreateTokenDialog.vue
packages/server/modules/core/errors/user.ts
packages/server/modules/core/graph/resolvers/apitoken.js
packages/server/modules/core/helpers/token.ts
packages/server/modules/core/tests/apitokens.spec.ts
Commit message: fix: preventing PATs from creating PATs


Vulnerable code:
  return Object.values(AllScopes).map((value) => ({
    id: value,
    text: value
import { AllScopes } from '@speckle/shared'
  return Object.values(AllScopes).map((value) => ({
    id: value,
    text: value
const { canCreateToken } = require('@/modules/core/helpers/token')
      if (!canCreateToken(context.scopes || [], args.token.scopes)) {
        throw new ForbiddenError(
          "You can't create a token with scopes that you don't have"
        )
      }
export const canCreateToken = (userScopes: string[], tokenScopes: string[]) => {
  return tokenScopes.every((scope) => userScopes.includes(scope))

Fixed code:
  return Object.values(allScopes.value).map((value) => ({
    id: value.name,
    text: value.name
import { useServerInfoScopes } from '~/lib/common/composables/serverInfo'
const { scopes: allScopes } = useServerInfoScopes()
  return Object.values(allScopes.value).map((value) => ({
    id: value.name,
    text: value.name

export class TokenCreateError extends BaseError {
  static code = 'TOKEN_CREATE_ERROR'
  static defaultMessage = 'An error occurred while creating a token'
}
const { canCreatePAT } = require('@/modules/core/helpers/token')
      canCreatePAT({
        userScopes: context.scopes || [],
        tokenScopes: args.token.scopes,
        strict: true
      })
import { TokenCreateError } from '@/modules/core/errors/user'
import { Scopes } from '@speckle/shared'

export const canCreateToken = (params: {
  userScopes: string[]
  tokenScopes: string[]
  strict?: boolean
}) => {
  const { userScopes, tokenScopes, strict } = params
  const hasAllScopes = tokenScopes.every((scope) => userScopes.includes(scope))
  if (!hasAllScopes) {
    if (!strict) return false
    throw new TokenCreateError(
      "You can't create a token with scopes that you don't have"
    )
  }

  return true
}

export const canCreatePAT = (params: {
  userScopes: string[]
  tokenScopes: string[]
  strict?: boolean
}) => {
  const { tokenScopes, strict } = params
  if (tokenScopes.includes(Scopes.Tokens.Write)) {
    if (!strict) return false
    throw new TokenCreateError(
      "You can't create a personal access token with the tokens:write scope"
    )
  }

  return canCreateToken(params)
  it("can't create PAT with tokens:write scope", async () => {
    const scopes = [Scopes.Profile.Read, Scopes.Tokens.Write]
    const { data, errors } = await apollo.execute(
      CreateTokenDocument,
      {
        token: {
          name: 'sometoken',
          scopes
        }
      },
      {
        context: {
          scopes
        }
      }
    )

    expect(data?.apiTokenCreate).to.not.be.ok
    expect(errors).to.be.ok
    expect(
      errors!.find((e) =>
        e.message.includes(
          "You can't create a personal access token with the tokens:write scope"
        )
      )
    ).to.be.ok
  })