Fix include directives for non-AsciiDoc files#777
Fix include directives for non-AsciiDoc files#777rolfedh wants to merge 1 commit intoquarkiverse:mainfrom
Conversation
ia3andy
left a comment
There was a problem hiding this comment.
I would feel safer if we had a list of authrized extensions for include in the config
|
Also I just tried something like |
|
@jtama are you using jruby? |
a846f2a to
042a434
Compare
|
@jtama Your example works because the included file ( The issue shows up with cross-directory includes that use document attributes to reference files elsewhere in the project, e.g.: include::{generated-dir}/examples/MyApp.java[tags=example]Since Roq feeds content to AsciidoctorJ via Per @ia3andy's feedback, the allowed extensions are now configurable via |
|
Thanks @ia3andy and @jtama for the feedback! Here's what changed in the latest force-push:
|
|
I need to run a few check locally to remember how that behaves |
|
if it's left as is, we could include resources outside of the project ? And in anycase, what is the base path if the include is a relative one ? |
Add configurable extension allowlist (quarkus.asciidoc.include-extensions) for Roq's custom include processor. The default list covers languages that use //-style tag markers (.java, .kt, .js, .ts, .groovy, .scala). The .adoc/.asciidoc extensions are always handled regardless of config. This enables cross-directory and classpath-based include:: directives for source files in technical documentation. Co-located includes already work via the default AsciidoctorJ handler. Also fix URL prefix check to use find() instead of matches(), which previously failed to reject URL targets due to matches() requiring the entire string to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
042a434 to
5fe51ee
Compare
|
@jtama Great questions, thank you! Security boundary: The Your question actually helped me spot a pre-existing issue: absolute paths were not being normalized before the boundary check, so a path like // Before (only relative paths normalized):
Path targetPath = p.isAbsolute() ? p : baseDir.resolve(dir).resolve(target).normalize();
// After (both branches normalized):
Path targetPath = (p.isAbsolute() ? p : baseDir.resolve(dir).resolve(target)).normalize();Base path for relative includes: Relative paths resolve against Note: |

Summary
quarkus.asciidoc.include-extensionsproperty to control which non-AsciiDoc file types the custom include processor handles.java,.kt,.js,.ts,.groovy,.scala(languages using//-style tag markers).adoc/.asciidocfiles are always handled regardless of configmatches()→find()) so URL include targets are correctly delegated to the default handlerProblem
The custom
AsciidocJIncludeprocessor'shandles()method only accepted.adocand.asciidoctargets. Include directives for other file types fell through to AsciidoctorJ's default include handler.For co-located files (same directory), the default handler works fine. But for cross-directory includes using document attributes, the default handler fails because Roq feeds content to AsciidoctorJ via
asciidoctor.load()(as a string, not from a file), so there is no source file context to resolve relative paths against.For example, this pattern fails with the default handler:
Fix
Add a configurable allowlist of file extensions (
quarkus.asciidoc.include-extensions) that the custom processor handles. The default list covers languages where//-style tag markers work correctly. Users can extend or restrict the list viaapplication.properties.The existing path resolution, security boundary enforcement (ROOTDIR check), and tag/line extraction logic already work correctly for all file types.
Test plan
AsciidocJIncludeHandlesTestforhandles()logic)mvn verify -pl blog)include::for.javafiles with tag extraction🤖 Generated with Claude Code