Signup abuse detection and blocking

Signup abuse detection and blocking [Paid] 1.20.11

No permission to buy ($45.00)
Please imagine this situation:

Every day, you have at least one new email domain you want to block.

And every single day, you have to do the following:
  1. Select and copy the email domain without the username and @ sign. Easy on a PC, but annoying on a phone.
  2. Click two radio buttons.
  3. Paste the domain and submit.
Please, please, please make this easier!

Just add one radio button to block the entire email domain. Select radio, click Submit, and you're done.
 
Give yourself the [SignupAbuse] Banning email domains permission, and when rejecting a user it provides an option to ban the email domain.

With the [SignupAbuse] Approving email domains permission, you can add a domain to the known domain list which prevents banning that email domain via the approval queue.
 
Code:
Server error log

XF\Db\InvalidQueryException: SV\SignupAbuseBlocking\Job\PruneUserAgentsJob: MySQL statement prepare error [1064]: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT 5000' at line 16
src/XF/Db/AbstractStatement.php:225
Generated by: Unknown account
Nov 26, 2026 at 4:02 PM

Stack trace
                DELETE ua
                FROM xf_sv_user_agent AS ua
                WHERE
                    ua.last_log_date < ?
                    AND NOT EXISTS(
                        SELECT 1
                        FROM xf_sv_signup_log
                        WHERE ua.user_agent_id = xf_sv_signup_log.user_agent_id
                    )
                    AND NOT EXISTS(
                        SELECT 1
                        FROM xf_sv_login_log
                        WHERE ua.user_agent_id = xf_sv_login_log.user_agent_id
                    )
         
LIMIT 5000
------------

#0 src/XF/Db/Mysqli/Statement.php(207): XF\Db\AbstractStatement->getException('MySQL statement...', 1064, '42000')
#1 src/XF/Db/Mysqli/Statement.php(43): XF\Db\Mysqli\Statement->getException('MySQL statement...', 1064, '42000')
#2 src/XF/Db/Mysqli/Statement.php(61): XF\Db\Mysqli\Statement->prepare()
#3 src/XF/Db/AbstractAdapter.php(96): XF\Db\Mysqli\Statement->execute()
#4 src/addons/SV/SignupAbuseBlocking/Job/PruneUserAgentsJob.php(43): XF\Db\AbstractAdapter->query('
              ...', Array)
#5 src/XF/Job/Manager.php(275): SV\SignupAbuseBlocking\Job\PruneUserAgentsJob->run(7.99497)
#6 src/XF/Job/Manager.php(205): XF\Job\Manager->runJobInternal(Array, 7.99497)
#7 src/XF/Job/Manager.php(89): XF\Job\Manager->runJobEntry(Array, 7.99497)
#8 job.php(46): XF\Job\Manager->runQueue(false, 8)
#9 {main}

Request state
array(4) {
  ["url"] => string(8) "/job.php"
  ["referrer"] => string(30) "https://forum.bodybuilding.nl/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 
Last edited:
1.20.11: the user agent prune now runs, but on a large board (login log in the tens of millions of rows, MySQL 8.0) it looks expensive:
  • logUserAgent() returns an existing user agent's id without updating last_log_date, so last_log_date is effectively the first-seen date. Nearly every user agent older than the cut-off becomes a candidate, including ones still in use.
  • Each candidate runs NOT EXISTS against xf_sv_login_log, which has no index on user_agent_id. At best that's a full scan of the login log per 5,000-row batch, every hour.
  • As a DELETE with subqueries under REPEATABLE READ, InnoDB takes shared next-key locks on the login log rows it reads, so new login log inserts (every login) can wait behind it.

Possible fixes: update last_log_date when a user agent is reused (at most once a day) and prune on last_log_date alone, or add user_agent_id keys to xf_sv_login_log and xf_sv_signup_log. xf_sv_user_registration_log also references user agents and isn't checked.

Feature request: a "Delete registration log after X days" option, like the login and signup logs have.
 
Feature request: a "Delete registration log after X days" option, like the login and signup logs have.
Pruning the user agent log only happens if the login or signup logs are also pruned.

I'll have a look to see if I can improve the performance the user agent pruning. Missing index should be a simple fix at least.

logUserAgent() returns an existing user agent's id without updating last_log_date, so last_log_date is effectively the first-seen date. Nearly every user agent older than the cut-off becomes a candidate, including ones still in use.
Whatever AI you are using to analyze the code is just wrong.

PHP:
$db->insert('xf_sv_user_agent', [
'user_agent'      => $userAgent,
'user_agent_hash' => $hash,
'first_log_date'  => \XF::$time,
'last_log_date'   => \XF::$time,
'count'           => 1,
], false, '
    last_log_date = GREATEST(last_log_date, values(last_log_date))
    , count = count + 1
');
When an identical row is added (based off user_agent_hash), the latest last_log_date is updated based on which ever has the latest date (the existing row or the insert query).
 
Pruning the user agent log only happens if the login or signup logs are also pruned.

I'll have a look to see if I can improve the performance the user agent pruning. Missing index should be a simple fix at least.


Whatever AI you are using to analyze the code is just wrong.

PHP:
$db->insert('xf_sv_user_agent', [
'user_agent'      => $userAgent,
'user_agent_hash' => $hash,
'first_log_date'  => \XF::$time,
'last_log_date'   => \XF::$time,
'count'           => 1,
], false, '
    last_log_date = GREATEST(last_log_date, values(last_log_date))
    , count = count + 1
');
When an identical row is added (based off user_agent_hash), the latest last_log_date is updated based on which ever has the latest date (the existing row or the insert query).

That insert only runs when the SELECT just above it finds nothing:

PHP:
$userAgentId = (int)$db->fetchOne('
    SELECT user_agent_id
    FROM xf_sv_user_agent
    WHERE user_agent_hash = ? AND user_agent = ?
    LIMIT 1
', [$hash, $userAgent]);
if ($userAgentId !== 0)
{
    return $userAgentId;
}

An existing user agent returns there, so ON DUPLICATE KEY UPDATE never runs for it. xf_sv_user_agent also has no unique key on user_agent_hash (only the primary key and keys on first_log_date and last_log_date), so a racing insert can't take the duplicate-key path either.

From our live database, the five user agents with the most logged logins in the last hour:

Code:
user_agent_id  first_seen           last_log_date        count
208685         2026-10-13 22:04:23  2026-10-13 22:04:23  1
213540         2026-10-23 04:09:22  2026-10-23 04:09:22  1
210448         2026-10-16 22:43:57  2026-10-16 22:43:57  1
224628         2026-11-10 14:37:03  2026-11-10 14:37:03  1
216431         2026-10-28 01:07:07  2026-10-28 01:07:07  1

Each of these is in heavy use right now, yet last_log_date still equals the first-seen date and count is still 1, so once the prune cut-off passes those dates they become prune candidates.

Since there's no index on user_agent_hash, that SELECT also scans xf_sv_user_agent on every logged login and signup.
 
I'm going to need to fully review the code for this feature as it is missing a number indexes and the code makes assumptions about the data model which likely do not hold. Part of this is I'll need to write migration code since without a hash on user_agent_hash the assumption of a single unique row likely does not hold.

For now I'ld recommend disabling the pruning tasks via setting the expiry for login/signup logs to 0 until I can stabilize the feature
 
Back
Top Bottom