Skip to content

Commit

Permalink
fix(plantuml): pass plantuml.include.path property to native plantuml…
Browse files Browse the repository at this point in the history
… binary (#1828)
  • Loading branch information
mlyczek authored Feb 14, 2025
1 parent ddeb145 commit bcbc2de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 0 additions & 5 deletions server/src/main/java/io/kroki/server/service/Plantuml.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ public String decode(String encoded) throws DecodeException {
this.ditaaCommand = new DitaaCommand(config);
this.includeWhitelist = parseIncludeWhitelist(config);
this.logging = new Logging(logger);
// Disable unsafe include for security reasons
String plantUmlIncludePath = config.getString("KROKI_PLANTUML_INCLUDE_PATH");
if (plantUmlIncludePath != null) {
System.setProperty("plantuml.include.path", plantUmlIncludePath);
}
}

static List<Pattern> parseIncludeWhitelist(JsonObject config) {
Expand Down
12 changes: 12 additions & 0 deletions server/src/main/java/io/kroki/server/service/PlantumlCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.kroki.server.format.FileFormat;
import io.kroki.server.unit.TimeValue;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -19,13 +21,17 @@

public class PlantumlCommand {

private static final Logger logger = LoggerFactory.getLogger(PlantumlCommand.class);

private static final Pattern ERROR_MESSAGE_RX = Pattern.compile(".*ERROR\\n(?<lineNumber>[0-9]+)\\n(?<cause>[^\\n]+)\\n.*", Pattern.MULTILINE | Pattern.DOTALL);
private final String binPath;
private final String includePath;
private final TimeValue convertTimeout;
private final Commander commander;

public PlantumlCommand(JsonObject config) {
this.binPath = config.getString("KROKI_PLANTUML_BIN_PATH", "plantuml");
this.includePath = config.getString("KROKI_PLANTUML_INCLUDE_PATH");
this.commander = new Commander(
config,
new CommandStatusHandler() {
Expand Down Expand Up @@ -70,6 +76,9 @@ public byte[] handle(int exitValue, byte[] stdout, byte[] stderr) {
public byte[] convert(String source, FileFormat format, JsonObject options) throws IOException, InterruptedException {
List<String> commands = new ArrayList<>();
commands.add(binPath);
if (includePath != null) {
commands.add("-Dplantuml.include.path=" + includePath);
}
commands.add("-pipe");
commands.add("-t" + (format == FileFormat.BASE64 ? FileFormat.PNG.getName() : format.getName()));
commands.add("-timeout");
Expand All @@ -83,6 +92,9 @@ public byte[] convert(String source, FileFormat format, JsonObject options) thro
if (no_metadata != null) {
commands.add("-nometadata");
}

logger.debug("Executing PlantUML command: {}", commands);

byte[] result = commander.execute(source.getBytes(), commands.toArray(new String[0]));
if (format == FileFormat.BASE64) {
final String encodedBytes = "data:image/png;base64," + Base64.getUrlEncoder().encodeToString(result).replaceAll("\\s", "");
Expand Down

0 comments on commit bcbc2de

Please sign in to comment.