@@ -296,8 +296,6 @@ void V8DealerFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
296296void V8DealerFeature::validateOptions (std::shared_ptr<ProgramOptions> options) {
297297 ProgramOptions::ProcessingResult const & result = options->processingResult ();
298298
299- V8SecurityFeature& v8security = server ().getFeature <V8SecurityFeature>();
300-
301299 // a bit of duck typing here to check if we are an agent.
302300 // the problem is that the server role may be still unclear in this early
303301 // phase, so we are also looking for startup options that identify an agent
@@ -340,39 +338,8 @@ void V8DealerFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
340338 }
341339
342340 ctx->normalizePath (_startupDirectory, " javascript.startup-directory" , true );
343- v8security.addToInternalAllowList (_startupDirectory, FSAccessType::READ);
344-
345341 ctx->normalizePath (_moduleDirectories, " javascript.module-directory" , false );
346342
347- // try to append the current version name to the startup directory,
348- // so instead of "/path/to/js" we will get "/path/to/js/3.4.0"
349- std::string const versionAppendix =
350- std::regex_replace (rest::Version::getServerVersion (), std::regex (" -.*$" ),
351- " " );
352- std::string versionedPath =
353- basics::FileUtils::buildFilename (_startupDirectory, versionAppendix);
354-
355- LOG_TOPIC (" 604da" , DEBUG, Logger::V8)
356- << " checking for existence of version-specific startup-directory '"
357- << versionedPath << " '" ;
358- if (basics::FileUtils::isDirectory (versionedPath)) {
359- // version-specific js path exists!
360- _startupDirectory = versionedPath;
361- }
362-
363- for (auto & it : _moduleDirectories) {
364- versionedPath = basics::FileUtils::buildFilename (it, versionAppendix);
365-
366- LOG_TOPIC (" 8e21a" , DEBUG, Logger::V8)
367- << " checking for existence of version-specific module-directory '"
368- << versionedPath << " '" ;
369- if (basics::FileUtils::isDirectory (versionedPath)) {
370- // version-specific js path exists!
371- it = versionedPath;
372- }
373
8000
code>- v8security.addToInternalAllowList (it, FSAccessType::READ);
374- }
375-
376343 // check whether app-path was specified
377344 if (_appPath.empty ()) {
378345 LOG_TOPIC (" a161b" , FATAL, arangodb::Logger::V8)
@@ -383,9 +350,6 @@ void V8DealerFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
383350 // Tests if this path is either a directory (ok) or does not exist (we create
384351 // it in ::start) If it is something else this will throw an error.
385352 ctx->normalizePath (_appPath, " javascript.app-path" , false );
386- v8security.addToInternalAllowList (_appPath, FSAccessType::READ);
387- v8security.addToInternalAllowList (_appPath, FSAccessType::WRITE);
388- v8security.dumpAccessLists ();
389353
390354 // use a minimum of 1 second for GC
391355 if (_gcFrequency < 1 ) {
@@ -409,26 +373,51 @@ void V8DealerFeature::start() {
409373 // now check if we have a js directory inside the database directory, and if
410374 // it looks good
411375 auto & dbPathFeature = server ().getFeature <DatabasePathFeature>();
412- const std::string dbJSPath =
376+ std::string const dbJSPath =
413377 FileUtils::buildFilename (dbPathFeature.directory (), " js" );
414- const std::string checksumFile =
378+ std::string const checksumFile =
415379 FileUtils::buildFilename (dbJSPath, StaticStrings::checksumFileJs);
416- const std::string serverPath = FileUtils::buildFilename (dbJSPath, " server" );
417- const std::string commonPath = FileUtils::buildFilename (dbJSPath, " common" );
380+ std::string const serverPath = FileUtils::buildFilename (dbJSPath, " server" );
381+ std::string const commonPath = FileUtils::buildFilename (dbJSPath, " common" );
382+ std::string const nodeModulesPath = FileUtils::buildFilename (dbJSPath, " node" , " node_modules" );
418383 if (FileUtils::isDirectory (dbJSPath) && FileUtils::exists (checksumFile) &&
419384 FileUtils::isDirectory (serverPath) && FileUtils::isDirectory (commonPath)) {
420- // only load node modules from original startup path
421- _nodeModulesDirectory = _startupDirectory;
422385 // js directory inside database directory looks good. now use it!
423386 _startupDirectory = dbJSPath;
387+ // older versions didn't copy node_modules. so check if it exists inside the
388+ // database directory or not.
389+ if (FileUtils::isDirectory (nodeModulesPath)) {
390+ _nodeModulesDirectory = nodeModulesPath;
391+ } else {
392+ _nodeModulesDirectory = _startupDirectory;
393+ }
424394 }
425395 }
426-
396+
427397 LOG_TOPIC (" 77c97" , DEBUG, Logger::V8)
428398 << " effective startup-directory: " << _startupDirectory
429399 << " , effective module-directories: " << _moduleDirectories
430400 << " , node-modules-directory: " << _nodeModulesDirectory;
401+
402+ // add all paths to allowlists
403+ V8SecurityFeature& v8security = server ().getFeature <V8SecurityFeature>();
404+ TRI_ASSERT (!_startupDirectory.empty ());
405+ v8security.addToInternalAllowList (_startupDirectory, FSAccessType::READ);
406+
407+ if (!_nodeModulesDirectory.empty ()) {
408+ v8security.addToInternalAllowList (_nodeModulesDirectory, FSAccessType::READ);
409+ }
410+ for (auto const & it : _moduleDirectories) {
411+ if (!it.empty ()) {
412+ v8security.addToInternalAllowList (it, FSAccessType::READ);
413+ }
414+ }
431415
416+ TRI_ASSERT (!_appPath.empty ());
417+ v8security.addToInternalAllowList (_appPath, FSAccessType::READ);
418+ v8security.addToInternalAllowList (_appPath, FSAccessType::WRITE);
419+ v8security.dumpAccessLists ();
420+
432421 _startupLoader.setDirectory (_startupDirectory);
433422
434423 // dump paths
@@ -672,7 +661,10 @@ void V8DealerFeature::copyInstallationFiles() {
672661 LOG_TOPIC (" 38e1e" , INFO, Logger::V8)
673662 << " copying " << copied << " JS installation file(s) took " << Logger::FIXED (TRI_microtime () - start, 6 ) << " s" ;
674663 }
664+
665+ // finally switch over the paths
675666 _startupDirectory = copyJSPath;
667+ _nodeModulesDirectory = basics::FileUtils::buildFilename (copyJSPath, " node" , " node_modules" );
676668}
677669
678670V8Context* V8DealerFeature::addContext () {
0 commit comments