-
-
Notifications
You must be signed in to change notification settings - Fork 127
fix: prisma.d.ts is not properly saved #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,4 +40,5 @@ yarn-error.log* | |
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| package-lock.json | ||
| package-lock.json | ||
| package.json | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,7 +36,9 @@ export async function generate(model: Model, options: PluginOptions, project: Pr | |||||||||||||||||||||||
| let logicalPrismaClientDir: string | undefined; | ||||||||||||||||||||||||
| let dmmf: DMMF.Document | undefined; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (needsLogicalClient(model)) { | ||||||||||||||||||||||||
| const withLogicalClient = needsLogicalClient(model); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (withLogicalClient) { | ||||||||||||||||||||||||
| // schema contains delegate models, need to generate a logical prisma schema | ||||||||||||||||||||||||
| const result = await generateLogicalPrisma(model, options, outDir); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -49,15 +51,15 @@ export async function generate(model: Model, options: PluginOptions, project: Pr | |||||||||||||||||||||||
| `export type * from '${logicalPrismaClientDir}/index-fixed';`, | ||||||||||||||||||||||||
| { overwrite: true } | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| await saveSourceFile(prismaDts, options); | ||||||||||||||||||||||||
| await prismaDts.save(); | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| // just reexport the prisma client | ||||||||||||||||||||||||
| const prismaDts = project.createSourceFile( | ||||||||||||||||||||||||
| path.join(outDir, 'prisma.d.ts'), | ||||||||||||||||||||||||
| `export type * from '${getPrismaClientImportSpec(outDir, options)}';`, | ||||||||||||||||||||||||
| { overwrite: true } | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| await saveSourceFile(prismaDts, options); | ||||||||||||||||||||||||
| await prismaDts.save(); | ||||||||||||||||||||||||
|
Comment on lines
58
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, the use of Implement a sanitization or validation step for the - path.join(outDir, 'prisma.d.ts')
+ path.join(sanitizePath(outDir), 'prisma.d.ts')Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const enhanceTs = project.createSourceFile( | ||||||||||||||||||||||||
|
Comment on lines
51
to
65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Potential path traversal vulnerabilities detected due to user input influencing path operations. Ensure that any user input is sanitized or validated before being used in path operations to prevent unauthorized file access. - path.join(outDir, 'prisma.d.ts')
+ path.join(sanitizePath(outDir), 'prisma.d.ts')Note: Also applies to: 56-56, 64-64, 110-110, 136-136, 148-148, 163-163
Potential Regular Expression Denial-of-Service (ReDoS) vulnerabilities detected due to dynamically constructed regular expressions. Ensure that inputs to these regexes are validated or that the regex patterns are designed to be efficient and not susceptible to ReDoS. - new RegExp(`\\${delegateModelNames.join('|')}(Unchecked)?(Create|Update).*Input`)
+ // Ensure delegateModelNames are validated or consider using a more efficient regex patternAlso applies to: 352-354 |
||||||||||||||||||||||||
|
|
@@ -67,16 +69,18 @@ import modelMeta from './model-meta'; | |||||||||||||||||||||||
| import policy from './policy'; | ||||||||||||||||||||||||
| ${options.withZodSchemas ? "import * as zodSchemas from './zod';" : 'const zodSchemas = undefined;'} | ||||||||||||||||||||||||
| import { Prisma } from '${getPrismaClientImportSpec(outDir, options)}'; | ||||||||||||||||||||||||
| ${logicalPrismaClientDir ? `import { type PrismaClient } from '${logicalPrismaClientDir}/index-fixed';` : ``} | ||||||||||||||||||||||||
| ${withLogicalClient ? `import { type PrismaClient } from '${logicalPrismaClientDir}/index-fixed';` : ``} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export function enhance<DbClient extends object>(prisma: DbClient, context?: EnhancementContext, options?: EnhancementOptions) { | ||||||||||||||||||||||||
| export function enhance<DbClient extends object>(prisma: DbClient, context?: EnhancementContext, options?: EnhancementOptions)${ | ||||||||||||||||||||||||
| withLogicalClient ? ': PrismaClient' : '' | ||||||||||||||||||||||||
| } { | ||||||||||||||||||||||||
| return createEnhancement(prisma, { | ||||||||||||||||||||||||
| modelMeta, | ||||||||||||||||||||||||
| policy, | ||||||||||||||||||||||||
| zodSchemas: zodSchemas as unknown as (ZodSchemas | undefined), | ||||||||||||||||||||||||
| prismaModule: Prisma, | ||||||||||||||||||||||||
| ...options | ||||||||||||||||||||||||
| }, context)${logicalPrismaClientDir ? ' as PrismaClient' : ''}; | ||||||||||||||||||||||||
| }, context)${withLogicalClient ? ' as PrismaClient' : ''}; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||
| { overwrite: true } | ||||||||||||||||||||||||
|
Comment on lines
69
to
86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The creation and saving of the Ensure the - path.join(outDir, 'enhance.ts')
+ path.join(sanitizePath(outDir), 'enhance.ts') |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from
saveSourceFiletoprismaDts.save()for saving the source file whenwithLogicalClientis true is a good improvement in terms of direct usage of thets-morphlibrary's capabilities. However, there's a potential security concern with the use ofpath.joinwithout sanitizing or validating theoutDirparameter, which could lead to path traversal vulnerabilities ifoutDiris influenced by user input.To mitigate this, ensure that any user input influencing the
outDirparameter is properly sanitized or validated before being used in path operations. Consider implementing a sanitization function or using existing libraries to help with this task.Note:
sanitizePathis a placeholder for the actual sanitization function you implement.The dynamic construction of a regular expression using
delegateModelNames.join('|')could potentially lead to Regular Expression Denial-of-Service (ReDoS) vulnerabilities ifdelegateModelNamesis influenced by user input or can grow unbounded.Consider validating
delegateModelNamesto ensure they do not contain patterns that could lead to inefficient regex matching. Alternatively, use a more efficient regex pattern or a different approach to achieve the desired functionality without risking ReDoS.Similar to the previous comment regarding ReDoS vulnerabilities, dynamically constructing a regular expression with
delegateInfocould pose a risk if the input is not properly validated or controlled.Ensure that inputs to these regexes are validated or consider using hardcoded regexes instead. If dynamic construction is necessary, take steps to ensure the patterns are efficient and not susceptible to ReDoS.