Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit b2103a5

Browse files
authored
Merge pull request #221 from PerimeterX/revert-219-feature/new-block-page
Revert "[SDKNEW-1645] Feature/new block page"
2 parents d0cc413 + f3d90d9 commit b2103a5

File tree

3 files changed

+174
-34
lines changed

3 files changed

+174
-34
lines changed

lib/pxconfig.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PxConfig {
6868
['ADVANCED_BLOCKING_RESPONSE', 'px_advanced_blocking_response_enabled'],
6969
['TELEMETRY_COMMAND_HEADER', 'px_telemetry_header'],
7070
['CUSTOM_TEMPLATE_ROOT', 'px_custom_template_root'],
71+
['CUSTOM_TEMPLATE_DATA', 'px_custom_template_data'],
7172
['FILTER_BY_IP', 'px_filter_by_ip'],
7273
['FILTER_BY_USERAGENT', 'px_filter_by_user_agent'],
7374
['FILTER_BY_METHOD', 'px_filter_by_http_method'],
@@ -202,7 +203,6 @@ function pxInternalConfig() {
202203
MODULE_VERSION: 'NodeJS Module',
203204
COLLECTOR_HOST: 'collector.perimeterx.net',
204205
CAPTCHA_HOST: 'captcha.px-cdn.net',
205-
BACKUP_CAPTCHA_HOST: 'https://captcha.px-cloud.net',
206206
CLIENT_HOST: 'client.perimeterx.net',
207207
CD_XHR_HOST: 'b.px-cdn.net',
208208
CONFIGURATIONS_HOST: 'px-conf.perimeterx.net',
@@ -291,6 +291,7 @@ function pxDefaultConfig() {
291291
CSS_REF: '',
292292
JS_REF: '',
293293
CUSTOM_LOGO: '',
294+
LOGO_VISIBILITY: 'hidden',
294295
SENSITIVE_ROUTES: [],
295296
WHITELIST_ROUTES: [],
296297
MONITORED_ROUTES: [],
@@ -309,6 +310,7 @@ function pxDefaultConfig() {
309310
CONFIG_PATH: '',
310311
ADVANCED_BLOCKING_RESPONSE: true,
311312
CUSTOM_TEMPLATE_ROOT: '',
313+
CUSTOM_TEMPLATE_DATA: {},
312314
FILTER_BY_IP: [],
313315
FILTER_BY_USERAGENT: [],
314316
FILTER_BY_METHOD: [],
@@ -368,6 +370,7 @@ const allowedConfigKeys = [
368370
'px_advanced_blocking_response_enabled',
369371
'px_telemetry_header',
370372
'px_custom_template_root',
373+
'px_custom_template_data',
371374
'px_filter_by_ip',
372375
'px_filter_by_user_agent',
373376
'px_filter_by_http_method',

lib/pxenforcer.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ class PxEnforcer {
337337
uuid: responseObject.uuid,
338338
hostUrl: responseObject.hostUrl,
339339
blockScript: responseObject.blockScript,
340-
altBlockScript: responseObject.altBlockScript,
341-
customLogo: responseObject.customLogo,
342340
};
343341
return cb(null, response);
344342
}
@@ -525,30 +523,34 @@ class PxEnforcer {
525523

526524
getProps(ctx) {
527525
let jsClientSrc = `//${this._config.CLIENT_HOST}/${this._config.PX_APP_ID}/main.min.js`;
528-
const captchaParams = `/captcha.js?a=${ctx.blockAction}&u=${
526+
let captchaSrc = `//${this._config.CAPTCHA_HOST}/${this._config.PX_APP_ID}/captcha.js?a=${ctx.blockAction}&u=${
529527
ctx.uuid
530528
}&v=${ctx.vid || ''}&m=${ctx.isMobile() ? '1' : '0'}`;
531-
let captchaSrc = `//${this._config.CAPTCHA_HOST}/${this._config.PX_APP_ID}${captchaParams}`;
532529
let hostUrl = ctx.collectorUrl;
530+
533531
if (this._config.FIRST_PARTY_ENABLED && !ctx.isMobile()) {
534532
const prefix = this._config.PX_APP_ID.substring(2);
535533
jsClientSrc = `/${prefix}${this._config.FIRST_PARTY_VENDOR_PATH}`;
536-
captchaSrc = `/${prefix}${this._config.FIRST_PARTY_CAPTCHA_PATH}${captchaParams}`;
534+
captchaSrc = `/${prefix}${this._config.FIRST_PARTY_CAPTCHA_PATH}/captcha.js?a=${ctx.blockAction}&u=${
535+
ctx.uuid
536+
}&v=${ctx.vid || ''}&m=${ctx.isMobile() ? '1' : '0'}`;
537537
hostUrl = `/${prefix}${this._config.FIRST_PARTY_XHR_PATH}`;
538538
}
539539

540540
return {
541+
refId: ctx.uuid,
541542
appId: this._config.PX_APP_ID,
542543
vid: ctx.vid,
543544
uuid: ctx.uuid,
544545
customLogo: this._config.CUSTOM_LOGO,
545546
cssRef: this._config.CSS_REF,
546547
jsRef: this._config.JS_REF,
548+
logoVisibility: this._config.CUSTOM_LOGO ? 'visible' : 'hidden',
547549
hostUrl: hostUrl,
548550
jsClientSrc: jsClientSrc,
549551
firstPartyEnabled: this._config.FIRST_PARTY_ENABLED,
550552
blockScript: captchaSrc,
551-
altBlockScript: `${this._config.BACKUP_CAPTCHA_HOST}/${this._config.PX_APP_ID}${captchaParams}`
553+
customData: this._config.CUSTOM_TEMPLATE_DATA && JSON.stringify(this._config.CUSTOM_TEMPLATE_DATA),
552554
};
553555
}
554556

lib/templates/block_template.mustache

Lines changed: 162 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,173 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<meta name="description" content="px-captcha">
7-
<title>Access to this page has been denied</title>
8-
{{cssRef}}
6+
<title>Access to this page has been denied.</title>
7+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
8+
<style>
9+
html, body {
10+
margin: 0;
11+
padding: 0;
12+
font-family: 'Open Sans', sans-serif;
13+
color: #000;
14+
}
15+
16+
a {
17+
color: #c5c5c5;
18+
text-decoration: none;
19+
}
20+
21+
.container {
22+
align-items: center;
23+
display: flex;
24+
flex: 1;
25+
justify-content: space-between;
26+
flex-direction: column;
27+
height: 100%;
28+
}
29+
30+
.container > div {
31+
width: 100%;
32+
display: flex;
33+
justify-content: center;
34+
}
35+
36+
.container > div > div {
37+
display: flex;
38+
width: 80%;
39+
}
40+
41+
.customer-logo-wrapper {
42+
padding-top: 2rem;
43+
flex-grow: 0;
44+
background-color: #fff;
45+
visibility: {{logoVisibility}};
46+
}
47+
48+
.customer-logo {
49+
border-bottom: 1px solid #000;
50+
}
51+
52+
.customer-logo > img {
53+
padding-bottom: 1rem;
54+
max-height: 50px;
55+
max-width: 100%;
56+
}
57+
58+
.page-title-wrapper {
59+
flex-grow: 2;
60+
}
61+
62+
.page-title {
63+
flex-direction: column-reverse;
64+
}
65+
66+
.content-wrapper {
67+
flex-grow: 5;
68+
}
69+
70+
.content {
71+
flex-direction: column;
72+
}
73+
74+
.page-footer-wrapper {
75+
align-items: center;
76+
flex-grow: 0.2;
77+
background-color: #000;
78+
color: #c5c5c5;
79+
font-size: 70%;
80+
}
81+
82+
@media (min-width: 768px) {
83+
html, body {
84+
height: 100%;
85+
}
86+
}
87+
</style>
88+
<!-- Custom CSS -->
89+
{{#cssRef}}
90+
<link rel="stylesheet" type="text/css" href="{{{cssRef}}}"/>
91+
{{/cssRef}}
992
</head>
93+
1094
<body>
95+
<section class="container">
96+
<div class="customer-logo-wrapper">
97+
<div class="customer-logo">
98+
<img src="{{customLogo}}" alt="Logo"/>
99+
</div>
100+
</div>
101+
<div class="page-title-wrapper">
102+
<div class="page-title">
103+
<h1>Please verify you are a human</h1>
104+
</div>
105+
</div>
106+
<div class="content-wrapper">
107+
<div class="content">
108+
109+
<div id="px-captcha">
110+
</div>
111+
<p>
112+
Access to this page has been denied because we believe you are using automation tools to browse the
113+
website.
114+
</p>
115+
<p>
116+
This may happen as a result of the following:
117+
</p>
118+
<ul>
119+
<li>
120+
Javascript is disabled or blocked by an extension (ad blockers for example)
121+
</li>
122+
<li>
123+
Your browser does not support cookies
124+
</li>
125+
</ul>
126+
<p>
127+
Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking
128+
them from loading.
129+
</p>
130+
<p>
131+
Reference ID: #{{refId}}
132+
</p>
133+
</div>
134+
</div>
135+
<div class="page-footer-wrapper">
136+
<div class="page-footer">
137+
<p>
138+
Powered by
139+
<a href="https://www.perimeterx.com/whywasiblocked">PerimeterX</a>
140+
, Inc.
141+
</p>
142+
</div>
143+
</div>
144+
</section>
145+
<!-- Px -->
11146
<script>
12-
window._pxVid = '{{vid}}';
13-
window._pxUuid = '{{uuid}}';
14147
window._pxAppId = '{{appId}}';
15-
window._pxHostUrl = '{{hostUrl}}';
16-
window._pxCustomLogo = '{{customLogo}}';
17-
window._pxJsClientSrc = '{{jsClientSrc}}';
148+
window._pxJsClientSrc = '{{{jsClientSrc}}}';
18149
window._pxFirstPartyEnabled = {{firstPartyEnabled}};
19-
var script = document.createElement('script');
20-
script.src = '{{blockScript}}';
21-
document.head.appendChild(script);
22-
script.onerror = function () {
23-
script = document.createElement('script');
24-
script.src = '{{altBlockScript}}';
25-
script.onerror = window._pxDisplayErrorMessage;
26-
document.head.appendChild(script);
27-
};
28-
window._pxDisplayErrorMessage = function () {
29-
var style = document.createElement('style');
30-
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}@media (max-width:480px){body{background-color:#fff}}.px-captcha-error-container{position:fixed;height:328px;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}div.px-captcha-error-button{text-align:center;line-height:50px;width:253px;margin:auto;border-radius:25px;border:solid 1px #f0f1f2;font-size:20px;color:#f0f1f2}div.px-captcha-error-wrapper{margin:23px 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 10px -2px 0}@media (min-width:620px){.px-captcha-error-container{width:528px;top:50%;left:50%;margin-top:-164px;margin-left:-264px;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:-164px;margin-left:-42.5%;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (max-width:480px){.px-captcha-error-container{width:528px;top:50%;left:50%;margin-top:-164px;margin-left:-264px}}';
31-
document.head.appendChild(style);
32-
var div = document.createElement('div');
33-
div.className = 'px-captcha-error-container';
34-
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 network connection or disable your ad-blocker.</div></div>';
35-
document.body.appendChild(div);
36-
};
150+
window._pxVid = '{{vid}}';
151+
window._pxUuid = '{{uuid}}';
152+
window._pxHostUrl = '{{{hostUrl}}}';
153+
</script>
154+
<script>
155+
var s = document.createElement('script');
156+
s.src = '{{{blockScript}}}';
157+
var p = document.getElementsByTagName('head')[0];
158+
p.insertBefore(s, null);
159+
if ({{firstPartyEnabled}}) {
160+
s.onerror = function () {
161+
s = document.createElement('script');
162+
var suffixIndex = '{{{blockScript}}}'.indexOf('captcha.js');
163+
var temperedBlockScript = '{{{blockScript}}}'.substring(suffixIndex);
164+
s.src = '//captcha.px-cdn.net/{{appId}}/' + temperedBlockScript;
165+
p.parentNode.insertBefore(s, p);
166+
};
167+
}
37168
</script>
38-
{{jsRef}}
169+
170+
<!-- Custom Script -->
171+
{{#jsRef}}
172+
<script src="{{{jsRef}}}"></script>
173+
{{/jsRef}}
39174
</body>
40175
</html>

0 commit comments

Comments
 (0)