Skip to content

Commit ba3c390

Browse files
committed
fix: Requiring local node files is restricted
1 parent df142b1 commit ba3c390

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/cubejs-schema-compiler/compiler/DataSchemaCompiler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,16 @@ class DataSchemaCompiler {
247247
path.resolve('node_modules', modulePath);
248248

249249
if (absPath.indexOf(nodeModulesPath) !== 0) {
250+
if (this.allowNodeRequire) {
251+
return null;
252+
}
250253
throw new UserError(`'${modulePath}' restricted`);
251254
}
252255
const packagePath = absPath.replace(nodeModulesPath, '').split('/').filter(s => !!s)[0];
253256
if (!packagePath) {
257+
if (this.allowNodeRequire) {
258+
return null;
259+
}
254260
throw new UserError(`'${modulePath}' is incorrect`);
255261
}
256262
if (!this.isWhiteListedPackage(packagePath)) {
@@ -267,6 +273,9 @@ class DataSchemaCompiler {
267273
}
268274
absPath = path.extname(absPath) !== '.js' ? absPath + '.js' : absPath;
269275
if (!fs.existsSync(absPath)) {
276+
if (this.allowNodeRequire) {
277+
return null;
278+
}
270279
throw new UserError(`Path '${absPath.replace(nodeModulesPath + '/', '')}' not found`);
271280
}
272281
return this.readModuleFile(absPath, errorsReport);

0 commit comments

Comments
 (0)