Skip to content

Commit 009d88d

Browse files
committed
Fix: ct_prev_referer no longer breaks page caching.
Move prev_referer to JS so PHP does not Set-Cookie on every pageview; give ct_cookies_test a 7-day TTL instead of a session cookie.
1 parent f6356b0 commit 009d88d

4 files changed

Lines changed: 13 additions & 16 deletions

File tree

cleantalk/antispam/acp/main_info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function module()
1717
return array(
1818
'filename' => '\cleantalk\antispam\acp\main_module',
1919
'title' => 'ACP_CLEANTALK_TITLE',
20-
'version' => '5.8.0',
20+
'version' => '5.8.1',
2121
'modes' => array(
2222
'settings' => array('title' => 'ACP_CLEANTALK_SETTINGS', 'auth' => 'ext_cleantalk/antispam && acl_a_board', 'cat' => array('ACP_CLEANTALK_TITLE')),
2323
),

cleantalk/antispam/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "Antispam by CleanTalk",
55
"homepage": "https://cleantalk.org",
6-
"version": "5.8.0",
6+
"version": "5.8.1",
77
"time": "2017-06-07",
88
"license": "GPL-2.0-only",
99
"authors": [

cleantalk/antispam/model/main_model.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class main_model
2424
const JS_TIME_ZONE_FIELD_NAME = 'ct_timezone';
2525
const JS_PREVIOUS_REFERER = 'ct_prev_referer';
2626
const JS_PS_TIMESTAMP = 'ct_ps_timestamp';
27+
/** Lifetime for ct_cookies_test (7 days); independent of prev_referer */
28+
const COOKIE_TEST_LIFETIME = 604800;
2729

2830
/* @var \phpbb\config\config */
2931
protected $config;
@@ -114,7 +116,8 @@ public function check_spam($spam_check)
114116
//Timezone from JS, Page set timestamp
115117
$page_set_timestamp = $this->request->variable(self::JS_PS_TIMESTAMP, "none", false, \phpbb\request\request_interface::COOKIE);
116118
$js_timezone = $this->request->variable(self::JS_TIME_ZONE_FIELD_NAME, "none", false, \phpbb\request\request_interface::COOKIE);
117-
$previous_referer = $this->request->variable($this->config['cookie_name'] . '_' . self::JS_PREVIOUS_REFERER, "none", false, \phpbb\request\request_interface::COOKIE);
119+
// Set by JS (no phpBB cookie prefix), same as ct_checkjs / ct_ps_timestamp
120+
$previous_referer = $this->request->variable(self::JS_PREVIOUS_REFERER, "none", false, \phpbb\request\request_interface::COOKIE);
118121

119122
$js_timezone = ($js_timezone === "none" ? 0 : $js_timezone);
120123
$page_set_timestamp = ($page_set_timestamp === "none" ? 0 : intval($page_set_timestamp));
@@ -288,25 +291,15 @@ public function filter_response($ct_response)
288291
}
289292

290293
/**
291-
* Sets cookie
294+
* Sets cookie test probe (prev_referer is set from JS on each pageview).
292295
*/
293296
public function set_cookie()
294297
{
295-
// Cookie names to validate
296298
$cookie_test_value = array(
297299
'cookies_names' => array(),
298-
'check_value' => $this->config['cleantalk_antispam_apikey'],
300+
'check_value' => md5($this->config['cleantalk_antispam_apikey']),
299301
);
300-
301-
// Pervious referer
302-
if ( $this->request->server('HTTP_REFERER', '') !== '' ) {
303-
$this->user->set_cookie('ct_prev_referer', $this->request->server('HTTP_REFERER', ''), 0);
304-
$cookie_test_value['cookies_names'][] = 'ct_prev_referer';
305-
$cookie_test_value['check_value'] .= $this->request->server('HTTP_REFERER', '');
306-
}
307-
// Cookies test
308-
$cookie_test_value['check_value'] = md5($cookie_test_value['check_value']);
309-
$this->user->set_cookie('ct_cookies_test', json_encode($cookie_test_value), 0);
302+
$this->user->set_cookie('ct_cookies_test', json_encode($cookie_test_value), time() + self::COOKIE_TEST_LIFETIME);
310303
}
311304

312305
/**

cleantalk/antispam/styles/all/template/cleantalk.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ function ctSetCookie(c_name, value) {
55
}
66
ctSetCookie("ct_ps_timestamp", Math.floor(new Date().getTime()/1000));
77
ctSetCookie("ct_timezone", "0");
8+
// Previous page URL for spam check; session cookie, updated on every pageview (no PHP Set-Cookie)
9+
if (document.referrer) {
10+
ctSetCookie("ct_prev_referer", document.referrer);
11+
}
812
setTimeout(function(){
913
ctSetCookie(ct_cookie_name, ct_cookie_value);
1014
ctSetCookie("ct_timezone", ct_date.getTimezoneOffset()/60*(-1));

0 commit comments

Comments
 (0)