diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImpl.java index c8c489abb9..72921f3357 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImpl.java @@ -60,16 +60,6 @@ public class OEmbedClientImpl implements OEmbedClient { @Reference private HttpClientBuilderFactory httpClientBuilderFactory; - /** - * Socket timeout. - */ - private int soTimeout = 60000; - - /** - * Connection timeout. - */ - private int connectionTimeout = 5000; - private static final Logger LOGGER = LoggerFactory.getLogger(OEmbedClientImpl.class); private Map configs = new HashMap<>(); @@ -103,7 +93,7 @@ public OEmbedResponse getResponse(String url) { return null; } OEmbedResponse.Format format = OEmbedResponse.Format.fromString(config.format()); - try (CloseableHttpClient httpClient = getHttpClient()) { + try (CloseableHttpClient httpClient = getHttpClient(config)) { if (OEmbedResponse.Format.JSON == format) { String jsonURL = buildURL(config.endpoint(), url, OEmbedResponse.Format.JSON.getValue(), null, null); try (InputStream jsonStream = getDataStream(jsonURL, httpClient)) { @@ -112,6 +102,7 @@ public OEmbedResponse getResponse(String url) { } else if (jaxbContext != null && OEmbedResponse.Format.XML == format) { String xmlURL = buildURL(config.endpoint(), url, OEmbedResponse.Format.XML.getValue(), null, null); try (InputStream xmlStream = getDataStream(xmlURL, httpClient)) { + //Disable XXE SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setFeature("http://xml.org/sax/features/external-general-entities", false); @@ -154,8 +145,8 @@ protected OEmbedClientImplConfigurationFactory.Config getConfiguration(String ur return null; } - protected CloseableHttpClient getHttpClient() { - RequestConfig rc = RequestConfig.custom().setConnectTimeout(connectionTimeout).setSocketTimeout(soTimeout) + protected CloseableHttpClient getHttpClient(OEmbedClientImplConfigurationFactory.Config config) { + RequestConfig rc = RequestConfig.custom().setConnectTimeout(config.connectionTimeout()).setSocketTimeout(config.socketTimeout()) .build(); if (httpClientBuilderFactory != null && httpClientBuilderFactory.newBuilder() != null) { return httpClientBuilderFactory.newBuilder().setDefaultRequestConfig(rc).build(); diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplConfigurationFactory.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplConfigurationFactory.java index 562e5b2478..dcba9eb745 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplConfigurationFactory.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplConfigurationFactory.java @@ -39,6 +39,9 @@ public class OEmbedClientImplConfigurationFactory { description = "Configuration for defining oEmbed endpoints." ) public @interface Config { + + int DEFAULT_CONNECTION_TIMEOUT = 2000, DEFAULT_SOCKET_TIMEOUT=5000; + @AttributeDefinition( name = "Provider Name", description = "Name of the oEmbed provider." @@ -77,6 +80,18 @@ public class OEmbedClientImplConfigurationFactory { description = "Describes whether the provider response HTML is allowed to be displayed in an unsafe context." ) boolean unsafeContext() default false; + + @AttributeDefinition( + name = "Socket Timeout", + description = "The time waiting for data – after establishing the connection; maximum time of inactivity between two data packets." + ) + int socketTimeout() default DEFAULT_SOCKET_TIMEOUT; + + @AttributeDefinition( + name = "Connection Timeout", + description = "The time to establish the connection with the remote host." + ) + int connectionTimeout() default DEFAULT_CONNECTION_TIMEOUT; } @Activate diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/ListImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/ListImplTest.java index be8275da24..d7a5e72eee 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/ListImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/ListImplTest.java @@ -72,7 +72,7 @@ private List getListUnderTest(String resourcePath) { Utils.enableDataLayer(context, true); Resource resource = context.resourceResolver().getResource(resourcePath); if (resource == null) { - throw new IllegalStateException("Did you forget to defines test resource " + resourcePath + "?"); + throw new IllegalStateException("Did you forget to define test resource " + resourcePath + "?"); } context.request().setContextPath(CONTEXT_PATH); context.currentResource(resource); diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplTest.java index 54286e4c2d..ea71965bc4 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/services/embed/OEmbedClientImplTest.java @@ -89,6 +89,16 @@ public String[] scheme() { public boolean unsafeContext() { return false; } + + @Override + public int socketTimeout() { + return 1000; + } + + @Override + public int connectionTimeout() { + return 1000; + } }); client.bindOEmbedClientImplConfigurationFactory(configurationFactory, new HashMap<>()); @@ -155,6 +165,16 @@ public String[] scheme() { public boolean unsafeContext() { return false; } + + @Override + public int socketTimeout() { + return 1000; + } + + @Override + public int connectionTimeout() { + return 1000; + } }); client.bindOEmbedClientImplConfigurationFactory(configurationFactory, new HashMap<>()); diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookPost.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookPost.config index 34cba6e53b..42cb412465 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookPost.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookPost.config @@ -21,3 +21,5 @@ scheme=["https?://www\\.facebook\\.com/.*/posts/.*", "https?://www\\.facebook\\.com/photo\\.php.*", "https?://www\\.facebook\\.com/photo\\.php"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookVideo.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookVideo.config index 7053d5a87c..c80398aa3e 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookVideo.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-facebookVideo.config @@ -17,3 +17,5 @@ endpoint="https://www.facebook.com/plugins/video/oembed.json" format="json" scheme=["https?://www\\.facebook\\.com/.*/videos/.*","https?://www\\.facebook\\.com/video\\.php.*"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-flickr.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-flickr.config index e1af02c5f2..58c512b5db 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-flickr.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-flickr.config @@ -17,3 +17,5 @@ endpoint="https://www.flickr.com/services/oembed/" format="xml" scheme=["https?://.*\.flickr\\.com/photos/.*","https?://flic\\.kr/p/.*"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-instagram.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-instagram.config index a30524e46a..7629c39d64 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-instagram.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-instagram.config @@ -17,3 +17,5 @@ endpoint="https://api.instagram.com/oembed" format="json" scheme=["https?://(www\\.)?instagram\\.com/p/.*","https?://(www\\.)?instagr\\.am/p/.*"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-soundcloud.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-soundcloud.config index 2af8e36af2..48d1ad4059 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-soundcloud.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-soundcloud.config @@ -17,3 +17,5 @@ endpoint="https://soundcloud.com/oembed" format="json" scheme=["https?://soundcloud\\.com/.*"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-twitter.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-twitter.config index 8ed1688aca..fa5d7ae470 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-twitter.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-twitter.config @@ -17,3 +17,5 @@ endpoint="https://publish.twitter.com/oembed" format="json" scheme=["https?://(.*\.)?twitter\.com/.*"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-youtube.config b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-youtube.config index a860cc30e0..b12869d64f 100644 --- a/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-youtube.config +++ b/config/src/content/jcr_root/apps/core/wcm/config/com.adobe.cq.wcm.core.components.internal.services.embed.OEmbedClientImplConfigurationFactory-youtube.config @@ -17,3 +17,5 @@ endpoint="https://www.youtube.com/oembed" format="json" scheme=["https://.*\.youtube.com/watch.*","https://.*\.youtube.com/v/.*","https://youtu\.be/.*"] unsafeContext="true" +socketTimeout="5000" +connectionTimeout="2000" diff --git a/content/pom.xml b/content/pom.xml index 7f37b8a3cd..c699065fcd 100644 --- a/content/pom.xml +++ b/content/pom.xml @@ -72,6 +72,11 @@ + + org.apache.maven.plugins + maven-antrun-plugin + 1.3 + com.day.jcr.vault content-package-maven-plugin