Skip to content

Commit 0b61f08

Browse files
authored
Use SCRIPT_NAME instead of REQUEST_URI to check path (#585) (#589)
The script is currently checking if the `REQUEST_URI` is containing `wp-comments-post.php`, the default script to handle the submission of a comment. Some security plugins have options to rename this file to disguise that WordPress is used. With this fix, the `SCRIPT_NAME` is used instead. Since many security plugins do use rewrite rules, while the `REQUEST_URI` value is changed, the `SCRIPT_NAME` value stays the same. Therefore the condition would still recognize if a comment was submitted.
1 parent cb75530 commit 0b61f08

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: antispam_bee.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ public static function precheck_incoming_request() {
11341134
return;
11351135
}
11361136

1137-
$request_uri = self::get_key( $_SERVER, 'REQUEST_URI' );
1137+
$request_uri = self::get_key( $_SERVER, 'SCRIPT_NAME' );
11381138
$request_path = self::parse_url( $request_uri, 'path' );
11391139

11401140
if ( strpos( $request_path, 'wp-comments-post.php' ) === false ) {
@@ -1168,7 +1168,7 @@ public static function precheck_incoming_request() {
11681168
public static function handle_incoming_request( $comment ) {
11691169
$comment['comment_author_IP'] = self::get_client_ip();
11701170

1171-
$request_uri = self::get_key( $_SERVER, 'REQUEST_URI' );
1171+
$request_uri = self::get_key( $_SERVER, 'SCRIPT_NAME' );
11721172
$request_path = self::parse_url( $request_uri, 'path' );
11731173

11741174
if ( empty( $request_path ) ) {

Diff for: tests/Unit/AntispamBeeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function test_gets_ip_address() {
6868
$_SERVER['REMOTE_ADDR'] = '192.0.2.1';
6969
$_SERVER['HTTP_X_FORWARDED_FOR'] = '192.0.2.2, 10.0.0.10';
7070
$_SERVER['HTTP_X_REAL_IP'] = 'bogus';
71-
$_SERVER['REQUEST_URI'] = 'https://domain.com/wp-comments-post.php';
71+
$_SERVER['SCRIPT_NAME'] = '/wp-comments-post.php';
7272
$_POST['comment'] = $comment;
7373

7474
$result = Testee::handle_incoming_request( $comment );
@@ -99,7 +99,7 @@ public function test_spam_reasons( $comment, $reason ) {
9999
$comment = array_merge( $this->get_base_comment(), $comment );
100100

101101
$_SERVER['REMOTE_ADDR'] = '12.23.34.45';
102-
$_SERVER['REQUEST_URI'] = 'https://domain.com/wp-comments-post.php';
102+
$_SERVER['SCRIPT_NAME'] = '/wp-comments-post.php';
103103
$_POST['comment'] = $comment;
104104

105105
// This is where we check for the spam reason that was detected.

0 commit comments

Comments
 (0)