|
1 | 1 | import fs from 'fs-extra' |
2 | 2 | import { join } from 'pathe' |
3 | 3 | import mongoose from 'mongoose' |
4 | | -import type { Collection, DevtoolsServerContext, Resource, ServerFunctions } from '../types' |
| 4 | +import type { CollectionDefinition, DevtoolsServerContext, Resource, ServerFunctions } from '../types' |
5 | 5 | import { capitalize, generateApiRoute, generateSchemaFile, pluralize, singularize } from '../utils' |
6 | 6 |
|
7 | 7 | export function setupResourceRPC({ nuxt }: DevtoolsServerContext): any { |
8 | 8 | const config = nuxt.options.runtimeConfig.mongoose |
9 | 9 |
|
10 | 10 | return { |
11 | | - async generateResource(collection: Collection, resources: Resource[]) { |
| 11 | + async generateResource(collection: CollectionDefinition, resources: Resource[]) { |
12 | 12 | const singular = singularize(collection.name).toLowerCase() |
13 | 13 | const plural = pluralize(collection.name).toLowerCase() |
14 | 14 | const dbName = capitalize(singular) |
@@ -56,7 +56,9 @@ export function setupResourceRPC({ nuxt }: DevtoolsServerContext): any { |
56 | 56 | const content = fs.readFileSync(schemaPath, 'utf-8').match(/schema: \{(.|\n)*\}/g) |
57 | 57 | if (content) { |
58 | 58 | const schemaString = content[0].replace('schema: ', '').slice(0, -3) |
59 | | - const schema = eval(`(${schemaString})`) |
| 59 | + // SECURITY FIX: Use Function constructor instead of eval |
| 60 | + // eslint-disable-next-line no-new-func |
| 61 | + const schema = new Function(`return ${schemaString}`)() |
60 | 62 | return schema |
61 | 63 | } |
62 | 64 | } |
|
0 commit comments