-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
fix: prisma.d.ts is not properly saved #1090
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
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
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 pattern Also 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
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
saveSourceFile
toprismaDts.save()
for saving the source file whenwithLogicalClient
is true is a good improvement in terms of direct usage of thets-morph
library's capabilities. However, there's a potential security concern with the use ofpath.join
without sanitizing or validating theoutDir
parameter, which could lead to path traversal vulnerabilities ifoutDir
is influenced by user input.To mitigate this, ensure that any user input influencing the
outDir
parameter 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:
sanitizePath
is 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 ifdelegateModelNames
is influenced by user input or can grow unbounded.Consider validating
delegateModelNames
to 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
delegateInfo
could 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.