Skip to content

Commit

Permalink
Merge pull request #343 from PerimeterX/release/v6.9.5
Browse files Browse the repository at this point in the history
Release/v6.9.5
  • Loading branch information
etrpx authored Nov 23, 2023
2 parents 0b088f8 + 7a7407f commit aa1eb61
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [v6.9.5](https://github.com/PerimeterX/perimeterx-java-sdk/compare/6.9.5...HEAD) (2023-11-23)
- Updated the configuration of PX first-party requests to include a connection timeout.
- Updated the captcha template to handle empty captcha responses.

## [v6.9.4](https://github.com/PerimeterX/perimeterx-java-sdk/compare/6.9.4...HEAD) (2023-11-21)
- Fixed first party connection timeout issue.
- Updated the captcha template with timeout mechanism addressing scenarios where delays occurred in retrieving the captcha.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# [PerimeterX](http://www.perimeterx.com) Java SDK

> Latest stable version: [v6.9.4](https://search.maven.org/#artifactdetails%7Ccom.perimeterx%7Cperimeterx-sdk%7C6.9.4%7Cjar)
> Latest stable version: [v6.9.5](https://search.maven.org/#artifactdetails%7Ccom.perimeterx%7Cperimeterx-sdk%7C6.9.5%7Cjar)
## Table of Contents

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>PerimeterX JAVA SDK</name>
<groupId>com.perimeterx</groupId>
<artifactId>perimeterx-sdk</artifactId>
<version>6.9.4</version>
<version>6.9.5</version>

<packaging>jar</packaging>
<description>PerimeterX Java SDK</description>
Expand Down
2 changes: 1 addition & 1 deletion px_metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "6.9.4",
"version": "6.9.5",
"supported_features": [
"advanced_blocking_response",
"bypass_monitor_header",
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/perimeterx/http/PXApacheHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.perimeterx.models.configuration.PXConfiguration;
import com.perimeterx.utils.PXCommonUtils;
import com.perimeterx.utils.PXLogger;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpRequestBase;
Expand Down Expand Up @@ -148,7 +149,6 @@ public boolean handle(RuntimeException ex) {
return ioReactor;
}


private HttpRequestBase createRequest(IPXOutgoingRequest request) {
HttpRequestBase req = buildBaseRequest(request);

Expand All @@ -160,10 +160,7 @@ private HttpRequestBase createRequest(IPXOutgoingRequest request) {
for (PXHttpHeader header : request.getHeaders()) {
req.addHeader(header.getName(), header.getValue());
}

if (!isValidPxThirdPartyRequest(req)) {
req.setConfig(PXCommonUtils.getRequestConfig(pxConfiguration));
}
req.setConfig(getRequestConfig(req));

return req;
}
Expand All @@ -188,4 +185,9 @@ public String getMethod() {
};
}
}

private RequestConfig getRequestConfig(HttpRequestBase req) {
return isValidPxThirdPartyRequest(req) ?
PXCommonUtils.getPXThirdPartyRequestConfig() : PXCommonUtils.getRequestConfig(pxConfiguration);
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/perimeterx/utils/PXCommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Created by nitzangoldfeder on 16/07/2017.
*/
public class PXCommonUtils {
final static int FIRST_PARTY_CONNECTION_TIMEOUT_IN_MSEC = 4000;

public static List<Header> getDefaultHeaders(String authToken) {
Header contentType = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -59,4 +60,9 @@ public static List<String> cookieHeadersNames(PXConfiguration configuration) {

return lst;
}

public static RequestConfig getPXThirdPartyRequestConfig() {
return RequestConfig.custom()
.setConnectTimeout(FIRST_PARTY_CONNECTION_TIMEOUT_IN_MSEC).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,79 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="px-captcha">
<title>Access to this page has been denied</title>
{{#cssRef}}
<link rel="stylesheet" type="text/css" href="{{{cssRef}}}" />
{{/cssRef}}
{{#cssRef}}
<link rel="stylesheet" type="text/css" href="{{{cssRef}}}"/>
{{/cssRef}}
</head>
<body>
<script>
/* PerimeterX assignments */
window._pxVid = '{{vid}}';
window._pxUuid = '{{uuid}}';
window._pxAppId = '{{appId}}';
window._pxMobile = {{isMobile}};
window._pxHostUrl = '{{{hostUrl}}}';
window._pxCustomLogo = '{{{customLogo}}}';
window._pxJsClientSrc = '{{{jsClientSrc}}}';
window._pxFirstPartyEnabled = {{firstPartyEnabled}};
window._pxBlockedUrl = '{{{blockedUrl}}}';
var pxCaptchaSrc = '{{{blockScript}}}';
<script>
/* PerimeterX assignments */
window._pxVid = '{{vid}}';
window._pxUuid = '{{uuid}}';
window._pxAppId = '{{appId}}';
window._pxHostUrl = '{{{hostUrl}}}';
window._pxBlockedUrl = '{{{blockedUrl}}}';
window._pxCustomLogo = '{{{customLogo}}}';
window._pxJsClientSrc = '{{{jsClientSrc}}}';
window._pxMobile = {{isMobile}};
window._pxFirstPartyEnabled = {{firstPartyEnabled}};
var script = document.createElement('script');
script.src = pxCaptchaSrc;
script.onload = onScriptLoad;
script.onerror = onScriptError;
window._pxOnError = function () {
var style = document.createElement('style');
style.innerText = '@import url(https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap);body{background-color:#fafbfc}.px-captcha-error-container{position:fixed;height:340px;background-color:#fff;font-family:Roboto,sans-serif}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:67px 0 33px;font-weight:500;line-height:.83;text-align:center}.px-captcha-error-message{color:#f0f1f2;font-size:18px;margin:0 0 29px;line-height:1.33;text-align:center}.px-captcha-error-button{text-align:center;line-height:48px;width:253px;margin:auto;border-radius:50px;border:solid 1px #f0f1f2;font-size:20px;color:#f0f1f2}.px-captcha-error-wrapper{margin:18px 0 0}div.px-captcha-error{margin:auto;text-align:center;width:400px;height:30px;font-size:12px;background-color:#fcf0f2;color:#ce0e2d}img.px-captcha-error{margin:6px 8px -2px 0}.px-captcha-error-refid{border-top:solid 1px #f0eeee;height:27px;margin:13px 0 0;border-radius:0 0 3px 3px;background-color:#fafbfc;font-size:10px;line-height:2.5;text-align:center;color:#b1b5b8}@media (min-width:620px){.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (min-width:481px) and (max-width:620px){.px-captcha-error-container{width:85%;top:50%;left:50%;margin-top:-170px;margin-left:-42.5%;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (max-width:480px){body{background-color:#fff}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:55px 0 33px}.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px}.px-captcha-error-refid{position:fixed;width:100%;left:0;bottom:0;border-radius:0;font-size:14px;line-height:2}}@media (max-width:390px){div.px-captcha-error{font-size:10px}.px-captcha-error-refid{font-size:11px;line-height:2.5}}';
document.head.appendChild(style);
var div = document.createElement('div');
div.className = 'px-captcha-error-container';
div.innerHTML = '<div class="px-captcha-error-header">Before we continue...</div><div class="px-captcha-error-message">Press & Hold to confirm you are<br>a human (and not a bot).</div><div class="px-captcha-error-button">Press & Hold</div><div class="px-captcha-error-wrapper"><div class="px-captcha-error"><img class="px-captcha-error" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAQCAMAAADDGrRQAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABFUExURUdwTNYELOEGONQILd0AONwALtwEL+AAL9MFLfkJSNQGLdMJLdQJLdQGLdQKLtYFLNcELdUGLdcBL9gFL88OLdUFLNEOLglBhT4AAAAXdFJOUwC8CqgNIRgRoAS1dWWuR4RTjzgryZpYblfkcAAAAI9JREFUGNNdj+sWhCAIhAdvqGVa1r7/oy6RZ7eaH3D4ZACBIed9wlOOMtUnSrEmZ6cHa9YAIfsbCkWrdpi/c50Bk2CO9mNLdMAu03wJA3HpEnfpxbyOg6ruyx8JJi6KNstnslp1dbPd9GnqmuYq7mmcv1zjnbQw8cV0xzkqo+fX1zkjUOO7wnrInUTxJiruC3vtBNRoQQn2AAAAAElFTkSuQmCC">Please check your internet connection' + (window._pxMobile ? '' : ' or disable your ad-blocker') + '.</div></div><div class="px-captcha-error-refid">Reference ID ' + window._pxUuid + '</div>';
document.body.appendChild(div);
if (window._pxMobile) {
setTimeout(function() {
location.href = '/px/captcha_close?status=-1';
}, 5000);
};
var pxCaptchaSrc = '{{{blockScript}}}';
var script = document.createElement('script');
script.src = pxCaptchaSrc;
script.onload = onScriptLoad;
script.onerror = onScriptError;
var onScriptErrorCalled;
document.head.appendChild(script);
var timeoutID = setTimeout(onScriptError, 5000);
function onScriptLoad() {
clearTimeout(timeoutID);
setTimeout(function() {
if (isCaptchaNotLoaded()) {
onScriptError();
}
}, 1000);
}
function onScriptError() {
if (onScriptErrorCalled) {
return;
}
onScriptErrorCalled = true;
script = document.createElement('script');
script.src = '{{{altBlockScript}}}';
script.onload = function() {
clearTimeout(timeoutID);
};
script.onerror = window._pxOnError;
document.head.appendChild(script);
var timeoutID = setTimeout(function() {
onScriptError();
timeoutID = setTimeout(function() {
if (isCaptchaNotLoaded()) {
window._pxOnError();
}
}, 5000);
function onScriptLoad() {
clearTimeout(timeoutID);
}
function onScriptError() {
script = document.createElement('script');
script.src = '{{{altBlockScript}}}';
script.onerror = window._pxOnError;
document.head.appendChild(script);
}
function isCaptchaNotLoaded() {
return !document.querySelector('div');
}
window._pxOnError = function () {
var style = document.createElement('style');
style.innerText = '@import url(https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap);body{background-color:#fafbfc}.px-captcha-error-container{position:fixed;height:340px;background-color:#fff;font-family:Roboto,sans-serif}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:67px 0 33px;font-weight:500;line-height:.83;text-align:center}.px-captcha-error-message{color:#f0f1f2;font-size:18px;margin:0 0 29px;line-height:1.33;text-align:center}.px-captcha-error-button{text-align:center;line-height:48px;width:253px;margin:auto;border-radius:50px;border:solid 1px #f0f1f2;font-size:20px;color:#f0f1f2}.px-captcha-error-wrapper{margin:18px 0 0}div.px-captcha-error{margin:auto;text-align:center;width:400px;height:30px;font-size:12px;background-color:#fcf0f2;color:#ce0e2d}img.px-captcha-error{margin:6px 8px -2px 0}.px-captcha-error-refid{border-top:solid 1px #f0eeee;height:27px;margin:13px 0 0;border-radius:0 0 3px 3px;background-color:#fafbfc;font-size:10px;line-height:2.5;text-align:center;color:#b1b5b8}@media (min-width:620px){.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (min-width:481px) and (max-width:620px){.px-captcha-error-container{width:85%;top:50%;left:50%;margin-top:-170px;margin-left:-42.5%;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (max-width:480px){body{background-color:#fff}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:55px 0 33px}.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px}.px-captcha-error-refid{position:fixed;width:100%;left:0;bottom:0;border-radius:0;font-size:14px;line-height:2}}@media (max-width:390px){div.px-captcha-error{font-size:10px}.px-captcha-error-refid{font-size:11px;line-height:2.5}}';
document.head.appendChild(style);
var div = document.createElement('div');
div.className = 'px-captcha-error-container';
div.innerHTML = '<div class="px-captcha-error-header">Before we continue...</div><div class="px-captcha-error-message">Press & Hold to confirm you are<br>a human (and not a bot).</div><div class="px-captcha-error-button">Press & Hold</div><div class="px-captcha-error-wrapper"><div class="px-captcha-error"><img class="px-captcha-error" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAQCAMAAADDGrRQAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABFUExURUdwTNYELOEGONQILd0AONwALtwEL+AAL9MFLfkJSNQGLdMJLdQJLdQGLdQKLtYFLNcELdUGLdcBL9gFL88OLdUFLNEOLglBhT4AAAAXdFJOUwC8CqgNIRgRoAS1dWWuR4RTjzgryZpYblfkcAAAAI9JREFUGNNdj+sWhCAIhAdvqGVa1r7/oy6RZ7eaH3D4ZACBIed9wlOOMtUnSrEmZ6cHa9YAIfsbCkWrdpi/c50Bk2CO9mNLdMAu03wJA3HpEnfpxbyOg6ruyx8JJi6KNstnslp1dbPd9GnqmuYq7mmcv1zjnbQw8cV0xzkqo+fX1zkjUOO7wnrInUTxJiruC3vtBNRoQQn2AAAAAElFTkSuQmCC">Please check your internet connection' + (window._pxMobile ? '' : ' or disable your ad-blocker') + '.</div></div><div class="px-captcha-error-refid">Reference ID ' + window._pxUuid + '</div>';
document.body.appendChild(div);
if (window._pxMobile) {
setTimeout(function() {
location.href = '/px/captcha_close?status=-1';
}, 5000);
}
</script>
};
</script>
{{#jsRef}}
<script src="{{{jsRef}}}"></script>
<script src="{{{jsRef}}}"></script>
{{/jsRef}}
</body>
</html>
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>com.perimeterx</groupId>
<artifactId>perimeterx-sdk</artifactId>
<version>6.9.4</version>
<version>6.9.5</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit aa1eb61

Please sign in to comment.