-
-
Notifications
You must be signed in to change notification settings - Fork 91
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: more robust calculation of default location for code generation #1095
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
import type { ModelMeta, PolicyDef, ZodSchemas } from '@zenstackhq/runtime'; | ||
import { DEFAULT_RUNTIME_LOAD_PATH, type ModelMeta, type PolicyDef, type ZodSchemas } from '@zenstackhq/runtime'; | ||
import path from 'path'; | ||
import { AdapterBaseOptions } from './types'; | ||
|
||
Comment on lines
1
to
5
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.
Detected possible user input going into Also applies to: 61-61, 92-92 |
||
|
@@ -39,7 +39,8 @@ export function getDefaultModelMeta(loadPath: string | undefined): ModelMeta { | |
if (process.env.ZENSTACK_TEST === '1' && !loadPath) { | ||
try { | ||
// special handling for running as tests, try resolving relative to CWD | ||
return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'model-meta')).default; | ||
return require(path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH, 'model-meta')) | ||
.default; | ||
} catch { | ||
throw new Error('Model meta cannot be loaded. Please make sure "zenstack generate" has been run.'); | ||
} | ||
|
@@ -66,7 +67,7 @@ export function getDefaultPolicy(loadPath: string | undefined): PolicyDef { | |
if (process.env.ZENSTACK_TEST === '1' && !loadPath) { | ||
try { | ||
// special handling for running as tests, try resolving relative to CWD | ||
return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'policy')).default; | ||
return require(path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH, 'policy')).default; | ||
} catch { | ||
throw new Error( | ||
'Policy definition cannot be loaded from default location. Please make sure "zenstack generate" has been run.' | ||
|
@@ -97,7 +98,7 @@ export function getDefaultZodSchemas(loadPath: string | undefined): ZodSchemas | | |
if (process.env.ZENSTACK_TEST === '1' && !loadPath) { | ||
try { | ||
// special handling for running as tests, try resolving relative to CWD | ||
return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'zod')); | ||
return require(path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH, 'zod')); | ||
} catch { | ||
return undefined; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,13 @@ | |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { DMMF } from '@prisma/generator-helper'; | ||
import type { Model } from '@zenstackhq/language/ast'; | ||
import type { AuthUser, CrudContract, EnhancementKind, EnhancementOptions } from '@zenstackhq/runtime'; | ||
import { | ||
DEFAULT_RUNTIME_LOAD_PATH, | ||
type AuthUser, | ||
type CrudContract, | ||
type EnhancementKind, | ||
type EnhancementOptions, | ||
} from '@zenstackhq/runtime'; | ||
import { getDMMF } from '@zenstackhq/sdk'; | ||
import { execSync } from 'child_process'; | ||
import * as fs from 'fs'; | ||
Comment on lines
2
to
14
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.
Detected a call to
Detected possible user input going into Also applies to: 81-81 |
||
|
@@ -284,7 +290,7 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) { | |
? path.isAbsolute(opt.output) | ||
? opt.output | ||
: path.join(projectRoot, opt.output) | ||
: path.join(projectRoot, 'node_modules', '.zenstack'); | ||
: path.join(projectRoot, 'node_modules', DEFAULT_RUNTIME_LOAD_PATH); | ||
|
||
const policy = require(path.join(outputPath, 'policy')).default; | ||
const modelMeta = require(path.join(outputPath, 'model-meta')).default; | ||
|
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.
Detected possible user input going into
path.join
orpath.resolve
functions in several places withingetNodeModulesFolder
,ensureDefaultOutputFolder
, andgetDefaultOutputFolder
functions. This could potentially lead to a path traversal vulnerability. Ensure that any user input or variable paths are sanitized or validated before use to prevent unauthorized file system access.Also applies to: 18-18, 20-20, 31-31, 64-64, 77-77