This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.25.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.25.x by this push: new 9c4edbe CAMEL-15050: Templating components - Variable map to be limited to body/headers 9c4edbe is described below commit 9c4edbe3aa15df08f46a9149ad8f5fdbed0413e4 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue May 12 09:10:25 2020 +0200 CAMEL-15050: Templating components - Variable map to be limited to body/headers --- .../src/main/docs/mustache-component.adoc | 6 ++++-- .../camel/component/mustache/MustacheComponent.java | 18 ++++++++++++++++++ .../camel/component/mustache/MustacheEndpoint.java | 2 +- .../springboot/MustacheComponentConfiguration.java | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/components/camel-mustache/src/main/docs/mustache-component.adoc b/components/camel-mustache/src/main/docs/mustache-component.adoc index 2ce545c..68f2415 100644 --- a/components/camel-mustache/src/main/docs/mustache-component.adoc +++ b/components/camel-mustache/src/main/docs/mustache-component.adoc @@ -39,7 +39,7 @@ You can append query options to the URI in the following format, // component options: START -The Mustache component supports 3 options, which are listed below. +The Mustache component supports 4 options, which are listed below. @@ -48,6 +48,7 @@ The Mustache component supports 3 options, which are listed below. | Name | Description | Default | Type | *mustacheFactory* (advanced) | To use a custom MustacheFactory | | MustacheFactory | *allowTemplateFrom Header* (producer) | Whether to allow to use resource template from header or not (default false). Enabling this allows to specify dynamic templates via message header. However this can be seen as a potential security vulnerability if the header is coming from a malicious user, so use this with care. | false | boolean +| *allowContextMapAll* (producer) | Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and CamelContext. Doing so impose a potential security risk as this opens access to the full power of CamelContext API. | false | boolean | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |=== // component options: END @@ -78,12 +79,13 @@ with the following path and query parameters: |=== -=== Query Parameters (6 parameters): +=== Query Parameters (7 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *allowContextMapAll* (producer) | Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and CamelContext. Doing so impose a potential security risk as this opens access to the full power of CamelContext API. | false | boolean | *allowTemplateFromHeader* (producer) | Whether to allow to use resource template from header or not (default false). Enabling this allows to specify dynamic templates via message header. However this can be seen as a potential security vulnerability if the header is coming from a malicious user, so use this with care. | false | boolean | *contentCache* (producer) | Sets whether to use resource content cache or not | false | boolean | *encoding* (producer) | Character encoding of the resource content. | | String diff --git a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java index ab955a1..a4aeec6 100644 --- a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java +++ b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java @@ -38,6 +38,8 @@ public class MustacheComponent extends UriEndpointComponent { @Metadata(defaultValue = "false") private boolean allowTemplateFromHeader; + @Metadata(defaultValue = "false") + private boolean allowContextMapAll; @Metadata(label = "advanced") private MustacheFactory mustacheFactory = new DefaultMustacheFactory(); @@ -51,6 +53,7 @@ public class MustacheComponent extends UriEndpointComponent { MustacheEndpoint endpoint = new MustacheEndpoint(uri, this, remaining); endpoint.setMustacheFactory(getMustacheFactory()); endpoint.setAllowTemplateFromHeader(allowTemplateFromHeader); + endpoint.setAllowContextMapAll(allowContextMapAll); setProperties(endpoint, parameters); return endpoint; } @@ -80,4 +83,19 @@ public class MustacheComponent extends UriEndpointComponent { this.allowTemplateFromHeader = allowTemplateFromHeader; } + public boolean isAllowContextMapAll() { + return allowContextMapAll; + } + + /** + * Sets whether the context map should allow access to all details. + * By default only the message body and headers can be accessed. + * This option can be enabled for full access to the current Exchange and CamelContext. + * Doing so impose a potential security risk as this opens access to the full power of CamelContext API. + */ + public void setAllowContextMapAll(boolean allowContextMapAll) { + this.allowContextMapAll = allowContextMapAll; + } + + } diff --git a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java index 7949356..ca97290 100644 --- a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java +++ b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java @@ -112,7 +112,7 @@ public class MustacheEndpoint extends ResourceEndpoint { } // Execute Mustache - Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange); + Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange, isAllowContextMapAll()); StringWriter writer = new StringWriter(); newMustache.execute(writer, variableMap); writer.flush(); diff --git a/platforms/spring-boot/components-starter/camel-mustache-starter/src/main/java/org/apache/camel/component/mustache/springboot/MustacheComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-mustache-starter/src/main/java/org/apache/camel/component/mustache/springboot/MustacheComponentConfiguration.java index 6f04767..134cd46 100644 --- a/platforms/spring-boot/components-starter/camel-mustache-starter/src/main/java/org/apache/camel/component/mustache/springboot/MustacheComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-mustache-starter/src/main/java/org/apache/camel/component/mustache/springboot/MustacheComponentConfiguration.java @@ -49,6 +49,14 @@ public class MustacheComponentConfiguration */ private Boolean allowTemplateFromHeader = false; /** + * Sets whether the context map should allow access to all details. By + * default only the message body and headers can be accessed. This option + * can be enabled for full access to the current Exchange and CamelContext. + * Doing so impose a potential security risk as this opens access to the + * full power of CamelContext API. + */ + private Boolean allowContextMapAll = false; + /** * Whether the component should resolve property placeholders on itself when * starting. Only properties which are of String type can use property * placeholders. @@ -71,6 +79,14 @@ public class MustacheComponentConfiguration this.allowTemplateFromHeader = allowTemplateFromHeader; } + public Boolean getAllowContextMapAll() { + return allowContextMapAll; + } + + public void setAllowContextMapAll(Boolean allowContextMapAll) { + this.allowContextMapAll = allowContextMapAll; + } + public Boolean getResolvePropertyPlaceholders() { return resolvePropertyPlaceholders; }