orchidhq / Orchid

Build and deploy beautiful documentation sites that grow with you
https://orchid.run
GNU General Public License v3.0
520 stars 53 forks source link

java.lang.SecurityException: Modifying file outside source, destination, and temp directories #398

Closed serpro69 closed 3 years ago

serpro69 commented 3 years ago

Hi,

Trying to follow this guide: https://orchid.run/wiki/learn/tutorials/how-to-document-kotlin#orchid-setup

After doing the Orchid Setup bits I'm getting an exception: java.lang.SecurityException: Modifying file outside source, destination, and temp directories when running ./gradlew :docs:orchidServe

Steps:

// 2. Include Orchid dependencies dependencies { orchidRuntime "io.github.javaeden.orchid:OrchidDocs:0.21.1" orchidRuntime "io.github.javaeden.orchid:OrchidKotlindoc:0.21.1" orchidRuntime "io.github.javaeden.orchid:OrchidPluginDocs:0.21.1" }

repositories { jcenter() maven { url = "https://kotlin.bintray.com/kotlinx/" } }

orchid { theme = "Editorial" baseUrl = "https://serpro69.github.io/kotlin-faker" version = "1.0.0" }


Branch in my project to reproduce the issue: https://github.com/serpro69/kotlin-faker/tree/docs

Full stacktrace:

Task :docs:orchidServe Using the following modules:

  • com.eden.orchid.StandardModule

Auto-loaded modules:

Flag values:

-adminTheme: Default -baseUrl: https://serpro69.github.io/kotlin-faker -defaultTemplateExtension: peb -dest: /home/sergio/Projects/personal/personal/kotlin-faker/docs/build/docs/orchid -diagnose: false -dryDeploy: false -environment: debug -experimentalSourceDoc: false -legacyFileServer: false -legacySourceDoc: false -logLevel: VERBOSE -port: 22864 -src: /home/sergio/Projects/personal/personal/kotlin-faker/docs/src/orchid/resources -task: serve -theme: Editorial -version: 1.0.0

[INFO] Orchid: Running Orchid version 0.21.1, site version 1.0.0 in debug environment [INFO] TaskServiceImpl: Build Starting... [INFO] GeneratorServiceImpl: Indexing Generators [INFO] GeneratorServiceImpl: WARM_UP Stage [INFO] GeneratorServiceImpl: Indexing [assets] [INFO] GeneratorServiceImpl: Indexing [external] [INFO] GeneratorServiceImpl: CONTENT Stage [INFO] GeneratorServiceImpl: Indexing [changelog] [INFO] GeneratorServiceImpl: Indexing [forms] [INFO] GeneratorServiceImpl: Indexing [home] [INFO] GeneratorServiceImpl: Indexing [kotlindoc] java.lang.SecurityException: Modifying file outside source, destination, and temp directories: home/sergio/Projects/personal/personal/kotlin-faker/docs/build at com.eden.orchid.api.OrchidSecurityManagerImpl.checkFilesystemWriteAccess(OrchidSecurityManagerImpl.java:107) at com.eden.orchid.api.OrchidSecurityManagerImpl.checkWrite(OrchidSecurityManagerImpl.java:91) at sun.nio.fs.UnixPath.checkWrite(UnixPath.java:801) at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:376) at java.nio.file.Files.createDirectory(Files.java:674) at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) at java.nio.file.Files.createDirectories(Files.java:767) at com.eden.orchid.utilities.OrchidUtils.getTempDir(OrchidUtils.java:390) at com.eden.orchid.utilities.OrchidUtils.getTempDir(OrchidUtils.java:380) at com.eden.orchid.sourcedoc.SourcedocGenerator$outputDir$2.invoke(SourcedocGenerator.kt:49) at com.eden.orchid.sourcedoc.SourcedocGenerator$outputDir$2.invoke(SourcedocGenerator.kt:32) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.eden.orchid.sourcedoc.SourcedocGenerator.getOutputDir(SourcedocGenerator.kt) at com.eden.orchid.sourcedoc.SourcedocGenerator.loadFromCacheOrRun(SourcedocGenerator.kt:201) at com.eden.orchid.sourcedoc.SourcedocGenerator.setupModule(SourcedocGenerator.kt:113) at com.eden.orchid.sourcedoc.SourcedocGenerator.startIndexing(SourcedocGenerator.kt:59) at com.eden.orchid.sourcedoc.SourcedocGenerator.startIndexing(SourcedocGenerator.kt:32) at com.eden.orchid.api.generators.GeneratorServiceImpl.indexGenerator(GeneratorServiceImpl.java:111) at java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:2746) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) at com.eden.orchid.api.generators.GeneratorServiceImpl.startIndexing(GeneratorServiceImpl.java:91) at com.eden.orchid.api.generators.GeneratorService.startIndexing(GeneratorService.java:12) at com.eden.orchid.api.tasks.TaskServiceImpl.build(TaskServiceImpl.java:130) at com.eden.orchid.api.tasks.TaskService.build(TaskService.java:26) at com.eden.orchid.impl.tasks.ServeTask.run(ServeTask.kt:16) at com.eden.orchid.api.tasks.TaskServiceImpl.runTask(TaskServiceImpl.java:79) at com.eden.orchid.api.tasks.TaskServiceImpl.onPostStart(TaskServiceImpl.java:70) at java.util.HashMap$Values.forEach(HashMap.java:981) at com.eden.orchid.api.OrchidContextImpl.start(OrchidContextImpl.java:100) at com.eden.orchid.Orchid.start(Orchid.java:96) at com.eden.orchid.Orchid.start(Orchid.java:62) at com.eden.orchid.Orchid.internalMain(Orchid.java:54) at com.eden.orchid.Orchid.main(Orchid.java:45) [ERROR] Errors: [ERROR] Orchid: [ERROR] - Something went wrong running Orchid

serpro69 commented 3 years ago

Just to be clear, the issue here is with the tutorial, not the project, from what I can see. The root cause for the above is that if we have an empty docs module in a project, the build dir won't be created when orchidServe task is executed, thus resulting in the above exception. So the user has to specify the destDir explicitly and point it to something other than build/ dir if using a separate module for generating orchid docs.

As a side note, it would be nice if orchid (optionally) created the dest dir if it doesn't exist.

cjbrooks12 commented 3 years ago

It should be creating the destDir automatically, in normal usage you shouldn't have any issue with the SecurityManager. It's just there to prevent plugins from doing things horribly wrong and overwriting files that Orchid doesn't manage. I'll pull down that branch and take a look and try to see what's going wrong, but this is likely a bug.

So I can get full context, can you try pulling down the tutorials repo and see if you get the same error running Orchid from subproject 01? It's been a while since I've run it, but the last I recall that project worked fine, and it looks like it's configured the same as your project https://github.com/orchidhq/OrchidTutorials/tree/master/01

serpro69 commented 3 years ago

Hi @cjbrooks12 , So I've been playing around with it yesterday, and it only fails for a "basic" setup where you don't have any orchid sources or resources in the docs module. As soon as you add some resources, like homepage.md, those get built first and then the build dir will exist and orchid will create the website files just fine. Obviously no one will just use the plugin by itself without any extra files like homepage and config.yml. But if you strictly follow the tutorial, that's what is says to do - you add the plugin config to the build.gradle and then you should be able to run orchidServe, which fails.

ajstrand commented 3 years ago

@cjbrooks12 I had the same issue as @serpro69, but I was able to get the documentation site working by creating src/orchid/resources within my docs folder.

Mentioning that these folders need to be created in the tutorial/documentation would be great.