About Spam Score

Spam Score provides local, explainable spam detection for Drupal forms.

It evaluates form submissions using configurable rules, calculates a numeric spam score, and records the individual signals that contributed to the result. Administrators can start in log-only mode to evaluate scoring before enabling enforcement.

Core functionality includes:

  • Drupal core Contact form integration
  • Configurable scoring rules and thresholds
  • Duplicate and flood detection
  • Configurable allowlists and blocklists
  • Administrative reporting and audit information
  • Optional email outcome tracking
  • Drush commands for diagnostics and maintenance
  • Extension hooks for custom integrations

The core scoring process can operate entirely within Drupal and does not require an external spam-classification API or subscription.

Differences from similar projects

Honeypot: Honeypot primarily focuses on automated submissions using hidden fields and timing behavior. Spam Score instead evaluates multiple content and submission signals and produces an explainable numeric score. The two approaches can be used together.

Akismet, CleanTalk, KireiFilter, and similar hosted services: These services use external spam-classification infrastructure. Spam Score provides a local scoring engine and does not require submitted form content to be sent to an external classification service.

The goal of Spam Score is to provide a reusable local spam-scoring and auditing framework with administrator-controlled rules and extensibility for site-specific requirements.

Drupal development practices

The 1.0.x branch uses Drupal core APIs and dependency injection and currently passes the Drupal.org GitLab CI pipeline.

CI validation includes:

  • PHPCS / Drupal coding standards
  • PHPStan static analysis
  • CSpell
  • PHPUnit

Automated test coverage includes:

  • Unit tests for scoring behavior
  • Kernel tests for configuration, storage, mail-state persistence, and update/migration behavior
  • Functional tests for Contact form integration and enforcement
  • Functional tests for administrative pages, permissions, and configuration

Maintainer

I am the project maintainer and have personally committed the code being submitted for review.

I would appreciate a review for the vetted maintainer role and permission to opt eligible contributed projects into Drupal Security Advisory coverage.

Manual reviews of other projects

https://www.drupal.org/project/projectapplications/issues/3608209#commen...
https://www.drupal.org/project/projectapplications/issues/3613219#commen...
https://www.drupal.org/project/projectapplications/issues/3448428#commen...

Project link

https://www.drupal.org/project/spam_score

Comments

binquanwang created an issue. See original summary.

binquanwang’s picture

Issue summary: View changes
binquanwang’s picture

Issue summary: View changes
vishal.kadam’s picture

Issue summary: View changes
avpaderno’s picture

Thank you for applying!

Before giving links helpful to understand how the review process works, what to expect from a review, and what to do to avoid a review takes more time than needed, I would like to thank all the reviewers for the work they do.
These applications are volunters-driven, which also means it is not possible to predict when an application will be marked fixed and the applicant will get the permission to opt projects into security advisory policy. While we aim to make an application as quick as possible, it is also important for us that more people review the project used for an application. In this way, we make sure applications do not miss some important points that should be instead reported.
Applications are not meant to be complete debugging sessions that eliminate every existing bug, though. I apologize if sometimes applications seem to go into too-detailed reviews.

Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

The important notes are the following.

  • If you have not done it yet, you should enable GitLab CI for the project and fix the PHP_CodeSniffer errors/warnings it reports.
  • For the time this application is open, only your commits are allowed.
  • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status will not be changed by this application; once this application is closed, you will be able to change the project status from Not covered to Opt into security advisory coverage. This is possible only 14 days after the project is created.

    Keep in mind that once the project is opted into security advisory coverage, only Security Team members may change coverage.
  • Only the person who created the application will get the permission to opt projects into security advisory coverage. No other person will get the same permission from the same application; that applies also to co-maintainers/maintainers of the project used for the application.
  • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

To the reviewers

Please read How to review security advisory coverage applications, Application workflow, What to cover in an application review, and Tools to use for reviews.

The important notes are the following.

  • It is preferable to wait for a project moderator before posting the first comment on newly created applications. Project moderators will do some preliminary checks that are necessary before any change on the project files is suggested.
  • Reviewers should show the output of a CLI tool only once per application.
  • It may be best to have the applicant fix things before further review.

For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues.

vishal.kadam’s picture

Status: Needs review » Needs work

1. FILE: README.md

The README file is missing the required sections - Requirements and Configuration.

2. FILE: spam_score.module

A module that aims to be compatible with Drupal 10 and Drupal 11 is expected to implement hooks as class methods as described in Support for object oriented hook implementations using autowired services.

3. FILE: src/Form/SettingsForm.php

With Drupal 10 and Drupal 11, there is no longer need to use #default_value for each form element, when the parent class is ConfigFormBase: It is sufficient to use #config_target, as in the following code.

    $form['image_toolkit'] = [
      '#type' => 'radios',
      '#title' => $this->t('Select an image processing toolkit'),
      '#config_target' => 'system.image:toolkit',
      '#options' => [],
    ];

Using that code, it is no longer needed to save the configuration values in the form submission handler: The parent class will take care of that.

4. FILE: src/Plugin/Mail/SpamScoreMail.php

 * @Mail(
 *   id = "spam_score_mail",
 *   label = @Translation("Spam Score (records send outcome)"),
 *   description = @Translation("Delegates to the configured mail plugin while recording delivery outcomes for Spam Score.")
 * )

FILE: src/Plugin/QueueWorker/MailRetryWorker.php

 * @QueueWorker(
 *   id = "spam_score_mail_retry",
 *   title = @Translation("Spam Score - mail retry"),
 *   cron = {"time" = 30}
 * )

Projects that are compatible with Drupal 10 or higher versions should use attributes instead of annotations.

binquanwang’s picture

Status: Needs work » Needs review

Thank you for the review. I addressed the four reported items in the current 1.0.x branch in #7:

Added explicit Requirements and Configuration sections to README.md.
Converted module hooks to object-oriented #[Hook] implementations with injected services, retaining #[LegacyHook] compatibility shims for supported older Drupal versions.
Converted SettingsForm to use #config_target, including ConfigTarget transformations for typed numeric/boolean values and newline-delimited list fields. The custom configuration-saving submitForm() implementation was removed.
Converted the Mail and QueueWorker plugins from annotations to PHP attributes.

The changes have been pushed to 1.0.x and the Drupal.org GitLab CI pipeline is passing.

binquanwang’s picture

avpaderno’s picture

avpaderno’s picture

Assigned: Unassigned » avpaderno
avpaderno’s picture

Assigned: avpaderno » Unassigned
Status: Needs review » Needs work
  • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
  • A specific point may just be an example and may apply in other places
  • A review is about code that does not follow the coding standards, contains possible security issue, or does not correctly use the Drupal API
  • The single review points are not ordered, not even by importance

src/Controller/ReportController.php

Since that class does not use methods from the parent class, or it uses a single method from the parent class, it does not need to use ControllerBase as parent class.

Controllers do not need to have a parent class; as long as they implement \Drupal\Core\DependencyInjection\ContainerInjectionInterface, they are fine.

  public function __construct(
    protected Connection $database,
    protected SpamScorer $scorer,
    protected RequestStack $requestStack,
    protected DateFormatterInterface $dateFormatter,
  ) {}

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container): static {
    return new static(
      $container->get('database'),
      $container->get('spam_score.scorer'),
      $container->get('request_stack'),
      $container->get('date.formatter'),
    );
  }

There is no need to use a \Symfony\Component\HttpFoundation\RequestStack or a \Symfony\Component\HttpFoundation\Request as class properties, since the \Symfony\Component\HttpFoundation\Request object is automatically passed to the page controller, if one of its parameters is correctly type-hinted. See Typehinted parameters.

public function content(AccountInterface $user, Request $request) {
  // …
}

'protected_forms' => $this->t('Form IDs to score. A trailing * is a wildcard, e.g. contact_message_*_form.'),

The given example does not show a string with a trailing asterisk, which would instead be contact_message_form_*.

    $form['thresholds']['quarantine_threshold'] = [
      '#type' => 'number',
      '#title' => $this->t('Quarantine threshold'),
      '#config_target' => new ConfigTarget(self::SETTINGS, 'quarantine_threshold', NULL, [self::class, 'toInteger']),
      '#min' => 1,
      '#description' => $this->t('At or above this score a submission is tagged as suspicious.'),
    ];

Drupal core does not use a conversion function for integer configuration values. I take that means it is not necessary.
The same is true for configuration values that expect a floating point value.

binquanwang’s picture

Status: Needs work » Needs review

Removed ControllerBase/RequestStack, simplified primitive #config_target mappings across the entire settings form, and corrected the wildcard wording in all affected locations.

The changes have been pushed to 1.0.x and the Drupal.org GitLab CI pipeline is passing.

Thanks!