Commit a0fd0d58 authored by Matija Obreza's avatar Matija Obreza
Browse files

Don't check local reCaptcha

parent d3055d30
...@@ -40,12 +40,25 @@ public class ReCaptchaUtil { ...@@ -40,12 +40,25 @@ public class ReCaptchaUtil {
private static final String URL = "https://www.google.com/recaptcha/api/siteverify"; private static final String URL = "https://www.google.com/recaptcha/api/siteverify";
public static boolean isValid(String reCaptchaResponse, String remoteAddr, String captchaPrivateKey) throws IOException { public static boolean isValid(String reCaptchaResponse, String remoteAddr, String captchaPrivateKey) throws IOException {
boolean isLocalRequest = false;
try {
final InetAddress remoteInetAddr = InetAddress.getByName(remoteAddr);
isLocalRequest = remoteInetAddr.isLinkLocalAddress() || remoteInetAddr.isAnyLocalAddress() || remoteInetAddr.isLoopbackAddress();
LOG.warn("Remote addr: " + remoteAddr + " " + remoteInetAddr + " isLocal=" + isLocalRequest);
} catch (final UnknownHostException e1) {
LOG.warn(e1.getMessage());
}
if (isLocalRequest) {
LOG.info("Ignoring localhost re-captcha.");
return true;
}
if (reCaptchaResponse == null || "".equals(reCaptchaResponse)) { if (reCaptchaResponse == null || "".equals(reCaptchaResponse)) {
return false; return false;
} }
boolean isLocalRequest = false;
URL url = new URL(URL); URL url = new URL(URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
...@@ -61,20 +74,9 @@ public class ReCaptchaUtil { ...@@ -61,20 +74,9 @@ public class ReCaptchaUtil {
dataOutputStream.flush(); dataOutputStream.flush();
dataOutputStream.close(); dataOutputStream.close();
try {
final InetAddress remoteInetAddr = InetAddress.getByName(remoteAddr);
isLocalRequest = remoteInetAddr.isLinkLocalAddress() || remoteInetAddr.isAnyLocalAddress() || remoteInetAddr.isLoopbackAddress();
LOG.warn("Remote addr: " + remoteAddr + " " + remoteInetAddr + " isLocal=" + isLocalRequest);
} catch (final UnknownHostException e1) {
LOG.warn(e1.getMessage());
}
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();
LOG.info("Send recaptcha post request to --> " + url + "\nPost parameters : " + postParams + "\n Response Code : " + responseCode); LOG.info("Send recaptcha post request to --> " + url + "\nPost parameters : " + postParams + "\n Response Code : " + responseCode);
if (isLocalRequest) {
LOG.info("Ignoring localhost re-captcha.");
// return true;
}
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine; String inputLine;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment