diff --git a/.snyk b/.snyk new file mode 100644 index 0000000000..93956804bf --- /dev/null +++ b/.snyk @@ -0,0 +1,8 @@ +# Snyk (https://snyk.io) policy file +version: v1.25.0 +# test code is not shipped; keep its fixtures out of Snyk Code results +exclude: + global: + - test/** + - py/**/tests/** + - py/testing/** diff --git a/src/prerna/util/linotp/LinOTPUtil.java b/src/prerna/util/linotp/LinOTPUtil.java index bf9280d0ef..1952bae1c1 100644 --- a/src/prerna/util/linotp/LinOTPUtil.java +++ b/src/prerna/util/linotp/LinOTPUtil.java @@ -82,6 +82,17 @@ public class LinOTPUtil { private static final Logger classLogger = LogManager.getLogger(LinOTPUtil.class); + private static final String SKIP_HOSTNAME_VERIFY_KEY = "linotp_skip_hostname_verify"; + + // host names are checked unless the admin opts out in social.properties + private static CloseableHttpClient newClient(SocialPropertiesUtil socialData) { + if (Boolean.parseBoolean(socialData.getProperty(SKIP_HOSTNAME_VERIFY_KEY, "false").trim())) { + classLogger.warn("{} is true so the LinOTP server's host name is not checked", SKIP_HOSTNAME_VERIFY_KEY); + return HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); + } + return HttpClients.createDefault(); + } + /** * * @param request @@ -184,8 +195,7 @@ public static LinOTPResponse login(HttpServletRequest request) throws ClientProt // first, request for challenge request using user pin // Create HTTP request via ssl port (https) and pass post parameters - try (CloseableHttpClient httpclient = HttpClients.custom() - .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()) { + try (CloseableHttpClient httpclient = newClient(socialData)) { HttpPost httpPost = new HttpPost(requestURL); List nvps = new ArrayList(); nvps.add(new BasicNameValuePair("user", username)); @@ -259,8 +269,7 @@ public static LinOTPResponse login(HttpServletRequest request) throws ClientProt } else { // subsequent challenge request with otp // Create HTTP request via ssl port (https) and pass post parameters - try (CloseableHttpClient httpclient = HttpClients.custom() - .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()) { + try (CloseableHttpClient httpclient = newClient(socialData)) { HttpPost httpPost = new HttpPost(requestURL); HttpSession session = request.getSession(); username = (String) session.getAttribute(LINOTP_USERNAME); @@ -445,8 +454,7 @@ private static LinOTPResponse resetCounter(LinOTPResponse linotpResponse, String context.setCookieStore(cstore); // Create HTTP request via ssl port (https) and pass post parameters - try (CloseableHttpClient httpclient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) - .build()) { + try (CloseableHttpClient httpclient = newClient(socialData)) { HttpPost httpPost = new HttpPost(requestURL); List nvps = new ArrayList();