CVE-2023-50713 (published 2023-12-14T19:15Z)

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.\n\nThis 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.

CVSS v3 base score: 5.0, MEDIUM (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:L)

Weakness information:
cwe_id: CWE-1220
cwe_name: Insufficient Granularity of Access Control
description: 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.
extended_description: 
                Integrated circuits and hardware engines can expose accesses to assets (device configuration, keys, etc.) to trusted firmware or a software module (commonly set by BIOS/bootloader). This access is typically access-controlled. Upon a power reset, the hardware or system usually starts with default values in registers, and the trusted firmware (Boot firmware) configures the necessary access-control protection.
                A common weakness that can exist in such protection schemes is that access controls or policies are not granular enough. This condition allows agents beyond trusted agents to access assets and could lead to a loss of functionality or the ability to set up the device securely. This further results in security risks from leaked, sensitive, key material to modification of device configuration.
            
			

Fix information:
repo_url: https://github.com/specklesystems/speckle-server
commit_details: repo_url: https://github.com/specklesystems/speckle-server
author: Kristaps Fabians Geikins
author_date: 2023-12-11 11:23:03+02:00
msg: fix: preventing PATs from creating PATs
repository: repo_url: https://github.com/specklesystems/speckle-server
repo_name: specklesystems/speckle-server
description: The Speckle Server, Frontend, 3D Viewer, & other JS utilities.
repo_language: TypeScript
owner: specklesystems
file_changes: filename: CreateEditApplicationDialog.vue
change_type: ModificationType.MODIFY
diff: @@ -101,9 +101,9 @@ const redirectUrl = ref('')
 const description = ref('')
 
 const applicationScopes = computed(() => {
-  return Object.values(AllScopes).map((value) => ({
-    id: value,
-    text: value
+  return Object.values(allScopes.value).map((value) => ({
+    id: value.name,
+    text: value.name
   }))
 })
 

programming_language: JavaScript
filename: CreateTokenDialog.vue
change_type: ModificationType.MODIFY
diff: @@ -39,7 +39,6 @@
 
 <script setup lang="ts">
 import { useMutation } from '@vue/apollo-composable'
-import { AllScopes } from '@speckle/shared'
 import { LayoutDialog, FormSelectBadges } from '@speckle/ui-components'
 import type { TokenFormValues } from '~~/lib/developer-settings/helpers/types'
 import { createAccessTokenMutation } from '~~/lib/developer-settings/graphql/mutations'
@@ -50,11 +49,13 @@ import {
   getFirstErrorMessage
 } from '~~/lib/common/helpers/graphql'
 import { useGlobalToast, ToastNotificationType } from '~~/lib/common/composables/toast'
+import { useServerInfoScopes } from '~/lib/common/composables/serverInfo'
 
 const emit = defineEmits<{
   (e: 'token-created', tokenId: string): void
 }>()
 
+const { scopes: allScopes } = useServerInfoScopes()
 const { mutate: createToken } = useMutation(createAccessTokenMutation)
 const { triggerNotification } = useGlobalToast()
 const { handleSubmit } = useForm<TokenFormValues>()
@@ -65,9 +66,9 @@ const name = ref('')
 const scopes = ref<typeof apiTokenScopes.value>([])
 
 const apiTokenScopes = computed(() => {
-  return Object.values(AllScopes).map((value) => ({
-    id: value,
-    text: value
+  return Object.values(allScopes.value).map((value) => ({
+    id: value.name,
+    text: value.name
   }))
 })
 

programming_language: TypeScript
filename: user.ts
change_type: ModificationType.MODIFY
diff: @@ -9,3 +9,8 @@ export class UserValidationError extends BaseError {
   static defaultMessage = 'The user input data is invalid'
   static code = 'USER_VALIDATION_ERROR'
 }
+
+export class TokenCreateError extends BaseError {
+  static code = 'TOKEN_CREATE_ERROR'
+  static defaultMessage = 'An error occurred while creating a token'
+}

programming_language: TypeScript
filename: apitoken.js
change_type: ModificationType.MODIFY
diff: @@ -6,7 +6,7 @@ const {
   revokeToken,
   getUserTokens
 } = require('../../services/tokens')
-const { canCreateToken } = require('@/modules/core/helpers/token')
+const { canCreatePAT } = require('@/modules/core/helpers/token')
 
 /** @type {import('@/modules/core/graph/generated/graphql').Resolvers} */
 const resolvers = {
@@ -23,11 +23,11 @@ const resolvers = {
   },
   Mutation: {
     async apiTokenCreate(parent, args, context) {
-      if (!canCreateToken(context.scopes || [], args.token.scopes)) {
-        throw new ForbiddenError(
-          "You can't create a token with scopes that you don't have"
-        )
-      }
+      canCreatePAT({
+        userScopes: context.scopes || [],
+        tokenScopes: args.token.scopes,
+        strict: true
+      })
 
       return await createPersonalAccessToken(
         context.userId,

programming_language: CoffeeScript
filename: token.ts
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,35 @@
-export const canCreateToken = (userScopes: string[], tokenScopes: string[]) => {
-  return tokenScopes.every((scope) => userScopes.includes(scope))
+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)
 }

programming_language: TypeScript
filename: apitokens.spec.ts
change_type: ModificationType.MODIFY
diff: @@ -66,6 +66,34 @@ describe('API Tokens', () => {
     ).to.be.ok
   })
 
+  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
+  })
+
   describe('without the tokens:write scope', () => {
     const limitedTokenScopes = difference(AllScopes, [Scopes.Tokens.Write])
     let limitedToken: string

programming_language: TypeScript