CVE-2023-3224 (published 2023-06-13T18:15Z)

Code Injection in GitHub repository nuxt/nuxt prior to 3.5.3.

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

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/nuxt/nuxt
commit_details: repo_url: https://github.com/nuxt/nuxt
author: Daniel Roe
author_date: 2023-04-27 11:31:52+01:00
msg: fix(nuxt): restrict access to single renderer outside of test/rootDir (#20543)
repository: repo_url: https://github.com/nuxt/nuxt
repo_name: nuxt/nuxt
description: The Intuitive Vue Framework.
repo_language: TypeScript
owner: nuxt
file_changes: filename: nuxt-root.vue
change_type: ModificationType.MODIFY
diff: @@ -23,7 +23,7 @@ const nuxtApp = useNuxtApp()
 const onResolve = nuxtApp.deferHydration()
 
 const url = process.server ? nuxtApp.ssrContext.url : window.location.pathname
-const SingleRenderer = process.dev && process.server && url.startsWith('/__nuxt_component_test__/') && defineAsyncComponent(() => import('#build/test-component-wrapper.mjs')
+const SingleRenderer = process.test && process.dev && process.server && url.startsWith('/__nuxt_component_test__/') && /* #__PURE__ */ defineAsyncComponent(() => import('#build/test-component-wrapper.mjs')
   .then(r => r.default(process.server ? url : window.location.href)))
 
 // Inject default route (outside of pages) as active route

programming_language: TypeScript
filename: test-component-wrapper.ts
change_type: ModificationType.MODIFY
diff: @@ -1,13 +1,20 @@
 import { parseURL } from 'ufo'
 import { defineComponent, h } from 'vue'
 import { parseQuery } from 'vue-router'
+import { resolve } from 'pathe'
+// @ts-expect-error virtual file
+import { devRootDir } from '#build/nuxt.config.mjs'
 
-export default (url:string) => defineComponent({
+export default (url: string) => defineComponent({
   name: 'NuxtTestComponentWrapper',
 
   async setup (props, { attrs }) {
     const query = parseQuery(parseURL(url).search)
     const urlProps = query.props ? JSON.parse(query.props as string) : {}
+    const path = resolve(query.path as string)
+    if (!path.startsWith(devRootDir)) {
+      throw new Error(`[nuxt] Cannot access path outside of project root directory: \`${path}\`.`)
+    }
     const comp = await import(/* @vite-ignore */ query.path as string).then(r => r.default)
     return () => [
       h('div', 'Component Test Wrapper for ' + query.path),

programming_language: TypeScript
filename: templates.ts
change_type: ModificationType.MODIFY
diff: @@ -299,7 +299,8 @@ export const nuxtConfigTemplate = {
     return [
       ...Object.entries(ctx.nuxt.options.app).map(([k, v]) => `export const ${camelCase('app-' + k)} = ${JSON.stringify(v)}`),
       `export const renderJsonPayloads = ${!!ctx.nuxt.options.experimental.renderJsonPayloads}`,
-      `export const devPagesDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.dir.pages) : 'null'}`
+      `export const devPagesDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.dir.pages) : 'null'}`,
+      `export const devRootDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.rootDir) : 'null'}`
     ].join('\n\n')
   }
 }

programming_language: TypeScript
filename: vite.ts
change_type: ModificationType.MODIFY
diff: @@ -1,4 +1,5 @@
 import { resolve } from 'pathe'
+import { isTest } from 'std-env'
 import { withoutLeadingSlash } from 'ufo'
 import { defineUntypedSchema } from 'untyped'
 
@@ -21,6 +22,7 @@ export default defineUntypedSchema({
     define: {
       $resolve: async (val, get) => ({
         'process.dev': await get('dev'),
+        'process.test': isTest,
         ...val || {}
       })
     },

programming_language: TypeScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -45,6 +45,7 @@
     "postcss-import": "^15.1.0",
     "postcss-loader": "^7.2.4",
     "postcss-url": "^10.1.3",
+    "std-env": "^3.3.2",
     "time-fix-plugin": "^2.0.7",
     "ufo": "^1.1.1",
     "unplugin": "^1.3.1",

programming_language: JavaScript
filename: base.ts
change_type: ModificationType.MODIFY
diff: @@ -10,6 +10,7 @@ import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
 import escapeRegExp from 'escape-string-regexp'
 import { joinURL } from 'ufo'
 import type { NuxtOptions } from '@nuxt/schema'
+import { isTest } from 'std-env'
 import type { WarningFilter } from '../plugins/warning-ignore'
 import WarningIgnorePlugin from '../plugins/warning-ignore'
 import type { WebpackConfigContext } from '../utils/config'
@@ -233,6 +234,7 @@ function getEnv (ctx: WebpackConfigContext) {
     'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
     'process.mode': JSON.stringify(ctx.config.mode),
     'process.dev': options.dev,
+    'process.test': isTest,
     __NUXT_VERSION__: JSON.stringify(ctx.nuxt._version),
     'process.env.VUE_ENV': JSON.stringify(ctx.name),
     'process.browser': ctx.isClient,

programming_language: JavaScript
filename: pnpm-lock.yaml
change_type: ModificationType.MODIFY
diff: @@ -1044,6 +1044,9 @@ importers:
       postcss-url:
         specifier: ^10.1.3
         version: 10.1.3(postcss@8.4.23)
+      std-env:
+        specifier: ^3.3.2
+        version: 3.3.2
       time-fix-plugin:
         specifier: ^2.0.7
         version: 2.0.7(webpack@5.80.0)

programming_language: CoffeeScript