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 a18a09d CAMEL-15050: Templating components - Variable map to be limited to body/headers a18a09d is described below commit a18a09d1ed0c9f7767677497e930ae991638a301 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue May 12 09:26:44 2020 +0200 CAMEL-15050: Templating components - Variable map to be limited to body/headers --- .../src/main/docs/string-template-component.adoc | 6 ++++-- .../stringtemplate/StringTemplateComponent.java | 16 ++++++++++++++++ .../component/stringtemplate/StringTemplateEndpoint.java | 2 +- .../component/stringtemplate/StringTemplateTest.java | 2 +- .../springboot/StringTemplateComponentConfiguration.java | 16 ++++++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/components/camel-stringtemplate/src/main/docs/string-template-component.adoc b/components/camel-stringtemplate/src/main/docs/string-template-component.adoc index 1c953cd..6d41301 100644 --- a/components/camel-stringtemplate/src/main/docs/string-template-component.adoc +++ b/components/camel-stringtemplate/src/main/docs/string-template-component.adoc @@ -39,7 +39,7 @@ You can append query options to the URI in the following format, // component options: START -The String Template component supports 2 options, which are listed below. +The String Template component supports 3 options, which are listed below. @@ -47,6 +47,7 @@ The String Template component supports 2 options, which are listed below. |=== | Name | Description | Default | Type | *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 @@ -72,12 +73,13 @@ with the following path and query parameters: |=== -=== Query Parameters (5 parameters): +=== Query Parameters (6 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 | *delimiterStart* (producer) | The variable start delimiter | < | char diff --git a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java index dace9fd..82f683d 100644 --- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java +++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java @@ -30,6 +30,8 @@ public class StringTemplateComponent extends UriEndpointComponent { @Metadata(defaultValue = "false") private boolean allowTemplateFromHeader; + @Metadata(defaultValue = "false") + private boolean allowContextMapAll; public StringTemplateComponent() { super(StringTemplateEndpoint.class); @@ -38,6 +40,7 @@ public class StringTemplateComponent extends UriEndpointComponent { protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { StringTemplateEndpoint answer = new StringTemplateEndpoint(uri, this, remaining); answer.setAllowTemplateFromHeader(allowTemplateFromHeader); + answer.setAllowContextMapAll(allowContextMapAll); setProperties(answer, parameters); // if its a http resource then append any remaining parameters and update the resource uri @@ -63,5 +66,18 @@ public class StringTemplateComponent 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; + } } \ No newline at end of file diff --git a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java index 1f4696e..84f0cc9 100644 --- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java +++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java @@ -105,7 +105,7 @@ public class StringTemplateEndpoint extends ResourceEndpoint { variableMap = exchange.getIn().getHeader(StringTemplateConstants.STRINGTEMPLATE_VARIABLE_MAP, Map.class); } if (variableMap == null) { - variableMap = ExchangeHelper.createVariableMap(exchange); + variableMap = ExchangeHelper.createVariableMap(exchange, isAllowContextMapAll()); } // getResourceAsInputStream also considers the content cache diff --git a/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java index 20bbd47..09a9929 100644 --- a/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java +++ b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java @@ -72,7 +72,7 @@ public class StringTemplateTest extends CamelTestSupport { public void configure() { // START SNIPPET: example from("direct:a"). - to("string-template:org/apache/camel/component/stringtemplate/template.tm?allowTemplateFromHeader=true"); + to("string-template:org/apache/camel/component/stringtemplate/template.tm?allowTemplateFromHeader=true&allowContextMapAll=true"); // END SNIPPET: example } }; diff --git a/platforms/spring-boot/components-starter/camel-stringtemplate-starter/src/main/java/org/apache/camel/component/stringtemplate/springboot/StringTemplateComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-stringtemplate-starter/src/main/java/org/apache/camel/component/stringtemplate/springboot/StringTemplateComponentConfiguration.java index de57699..dbfdb76 100644 --- a/platforms/spring-boot/components-starter/camel-stringtemplate-starter/src/main/java/org/apache/camel/component/stringtemplate/springboot/StringTemplateComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-stringtemplate-starter/src/main/java/org/apache/camel/component/stringtemplate/springboot/StringTemplateComponentConfiguration.java @@ -44,6 +44,14 @@ public class StringTemplateComponentConfiguration */ 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. @@ -58,6 +66,14 @@ public class StringTemplateComponentConfiguration this.allowTemplateFromHeader = allowTemplateFromHeader; } + public Boolean getAllowContextMapAll() { + return allowContextMapAll; + } + + public void setAllowContextMapAll(Boolean allowContextMapAll) { + this.allowContextMapAll = allowContextMapAll; + } + public Boolean getResolvePropertyPlaceholders() { return resolvePropertyPlaceholders; }