diff --git a/frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java b/frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java index 9a7c0d657e..294abd9fbe 100644 --- a/frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java +++ b/frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java @@ -45,6 +45,7 @@ import org.apache.commons.io.IOUtils; import org.pytorch.serve.servingsdk.snapshot.SnapshotSerializer; import org.pytorch.serve.snapshot.SnapshotSerializerFactory; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class ConfigManager { @@ -111,6 +112,9 @@ public final class ConfigManager { private static final String MODEL_CONFIG = "models"; private static final String VERSION = "version"; + // Configuration default values + private static final String DEFAULT_TS_ALLOWED_URLS = "file://.*|http(s)?://.*"; + // Variables which are local public static final String MODEL_METRICS_LOGGER = "MODEL_METRICS"; public static final String MODEL_LOGGER = "MODEL_LOG"; @@ -136,6 +140,7 @@ public final class ConfigManager { private String hostName; private Map> modelConfig = new HashMap<>(); private String torchrunLogDir; + private Logger logger = LoggerFactory.getLogger(ConfigManager.class); private ConfigManager(Arguments args) throws IOException { prop = new Properties(); @@ -234,6 +239,13 @@ private ConfigManager(Arguments args) throws IOException { } setModelConfig(); + + // Issue warnining about URLs that can be accessed when loading models + if (prop.getProperty(TS_ALLOWED_URLS, DEFAULT_TS_ALLOWED_URLS) == DEFAULT_TS_ALLOWED_URLS) { + logger.warn( + "Your torchserve instance can access any URL to load models. " + + "When deploying to production, make sure to limit the set of allowed_urls in config.properties"); + } } public static String readFile(String path) throws IOException { @@ -783,7 +795,7 @@ private static int getAvailableGpu() { } public List getAllowedUrls() { - String allowedURL = prop.getProperty(TS_ALLOWED_URLS, "file://.*|http(s)?://.*"); + String allowedURL = prop.getProperty(TS_ALLOWED_URLS, DEFAULT_TS_ALLOWED_URLS); return Arrays.asList(allowedURL.split(",")); }