Skip to content
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

Merged
merged 2 commits into from
Mar 7, 2024
Merged

fix: prisma.d.ts is not properly saved #1090

merged 2 commits into from
Mar 7, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Mar 7, 2024

Summary by CodeRabbit

  • New Features
    • Updated JetBrains IDE plugin to version 2.0.0-alpha.4, enhancing plugin stability and performance.
  • Bug Fixes
    • Fixed formatting in .gitignore file to ignore package.json and ensure proper newline at the end.
  • Refactor
    • Improved efficiency of file saving operations in the schema plugin.

Copy link
Contributor

coderabbitai bot commented Mar 7, 2024

Walkthrough

Walkthrough

The recent updates involve two primary changes: upgrading the JetBrains IDE plugin from version "2.0.0-alpha.1" to "2.0.0-alpha.4" to enhance functionality, and modifying the file saving operations within a TypeScript project by replacing saveSourceFile calls with prismaDts.save() for improved efficiency in handling source files. These adjustments aim at optimizing the development tools and processes involved in the project.

Changes

File Path Change Summary
packages/ide/jetbrains/build.gradle.kts Updated version from "2.0.0-alpha.1" to "2.0.0-alpha.4"
packages/plugins/trpc/tests/projects/t3-trpc-v10/.gitignore Added package.json to ignore list and fixed formatting by adding a newline at the end
packages/schema/src/plugins/enhancer/enhance/index.ts Replaced saveSourceFile with prismaDts.save() for efficient file saving operations

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 36e515e and c5b9d59.
Files ignored due to path filters (14)
  • package.json is excluded by: !**/*.json
  • packages/ide/jetbrains/package.json is excluded by: !**/*.json
  • packages/language/package.json is excluded by: !**/*.json
  • packages/misc/redwood/package.json is excluded by: !**/*.json
  • packages/plugins/openapi/package.json is excluded by: !**/*.json
  • packages/plugins/swr/package.json is excluded by: !**/*.json
  • packages/plugins/tanstack-query/package.json is excluded by: !**/*.json
  • packages/plugins/trpc/package.json is excluded by: !**/*.json
  • packages/plugins/trpc/tests/projects/t3-trpc-v10/package.json is excluded by: !**/*.json
  • packages/runtime/package.json is excluded by: !**/*.json
  • packages/schema/package.json is excluded by: !**/*.json
  • packages/sdk/package.json is excluded by: !**/*.json
  • packages/server/package.json is excluded by: !**/*.json
  • packages/testtools/package.json is excluded by: !**/*.json
Files selected for processing (2)
  • packages/ide/jetbrains/build.gradle.kts (1 hunks)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (1 hunks)
Additional comments: 2
packages/ide/jetbrains/build.gradle.kts (1)
  • 12-12: The version update to "2.0.0-alpha.3" appears correct and is a straightforward change. Ensure compatibility with other project dependencies and configurations.
packages/schema/src/plugins/enhancer/enhance/index.ts (1)
  • 52-52: The replacement of saveSourceFile with prismaDts.save() is aimed at enhancing file saving operations. Ensure that prismaDts.save() is implemented securely and efficiently.

Also applies to: 60-60

Comment on lines 49 to 63
`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();
}

const enhanceTs = project.createSourceFile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [48-48]

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: sanitizePath is a placeholder for the actual sanitization function you implement.

Also applies to: 56-56, 64-64, 110-110, 136-136, 148-148, 163-163


📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [329-331]

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c5b9d59 and bc5db1b.
Files ignored due to path filters (13)
  • package.json is excluded by: !**/*.json
  • packages/ide/jetbrains/package.json is excluded by: !**/*.json
  • packages/language/package.json is excluded by: !**/*.json
  • packages/misc/redwood/package.json is excluded by: !**/*.json
  • packages/plugins/openapi/package.json is excluded by: !**/*.json
  • packages/plugins/swr/package.json is excluded by: !**/*.json
  • packages/plugins/tanstack-query/package.json is excluded by: !**/*.json
  • packages/plugins/trpc/package.json is excluded by: !**/*.json
  • packages/runtime/package.json is excluded by: !**/*.json
  • packages/schema/package.json is excluded by: !**/*.json
  • packages/sdk/package.json is excluded by: !**/*.json
  • packages/server/package.json is excluded by: !**/*.json
  • packages/testtools/package.json is excluded by: !**/*.json
Files selected for processing (3)
  • packages/ide/jetbrains/build.gradle.kts (1 hunks)
  • packages/plugins/trpc/tests/projects/t3-trpc-v10/.gitignore (1 hunks)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • packages/plugins/trpc/tests/projects/t3-trpc-v10/.gitignore
Files skipped from review as they are similar to previous changes (1)
  • packages/ide/jetbrains/build.gradle.kts

Comment on lines 36 to 44
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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [41-54]

The change from saveSourceFile to prismaDts.save() for saving the source file when withLogicalClient is true is a good improvement in terms of direct usage of the ts-morph library's capabilities. However, there's a potential security concern with the use of path.join without sanitizing or validating the outDir parameter, which could lead to path traversal vulnerabilities if outDir 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.

- path.join(outDir, 'prisma.d.ts')
+ path.join(sanitizePath(outDir), 'prisma.d.ts')

Note: sanitizePath is a placeholder for the actual sanitization function you implement.


📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [333-335]

The dynamic construction of a regular expression using delegateModelNames.join('|') could potentially lead to Regular Expression Denial-of-Service (ReDoS) vulnerabilities if delegateModelNames 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.


📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [356-358]

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.

Comment on lines 58 to +62
path.join(outDir, 'prisma.d.ts'),
`export type * from '${getPrismaClientImportSpec(outDir, options)}';`,
{ overwrite: true }
);
await saveSourceFile(prismaDts, options);
await prismaDts.save();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous comment, the use of path.join here also poses a potential security risk due to the possibility of path traversal vulnerabilities. It's crucial to ensure that the outDir parameter is sanitized or validated if it can be influenced by user input.

Implement a sanitization or validation step for the outDir parameter to prevent unauthorized file access.

- path.join(outDir, 'prisma.d.ts')
+ path.join(sanitizePath(outDir), 'prisma.d.ts')

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
path.join(outDir, 'prisma.d.ts'),
`export type * from '${getPrismaClientImportSpec(outDir, options)}';`,
{ overwrite: true }
);
await saveSourceFile(prismaDts, options);
await prismaDts.save();
path.join(sanitizePath(outDir), 'prisma.d.ts'),
`export type * from '${getPrismaClientImportSpec(outDir, options)}';`,
{ overwrite: true }
);
await prismaDts.save();

Comment on lines 69 to 86
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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [66-83]

The creation and saving of the enhance.ts source file are correctly implemented. However, the use of path.join without sanitizing or validating the outDir parameter could lead to path traversal vulnerabilities, similar to the previous instances.

Ensure the outDir parameter is sanitized or validated to prevent potential security risks.

- path.join(outDir, 'enhance.ts')
+ path.join(sanitizePath(outDir), 'enhance.ts')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant