yireo / magento2-salesblock2-by-ip

yireo/magento2-salesblock2-by-ip

Block transactions based on IP matching

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: Fail Security: Pass OSL-3.0

Yireo SalesBlock2ByIp for Magento 2

This module is a helper-module for the Yireo_SalesBlock2 extension, that allows you to block orders from being placed, based on specific rules defined in the Magento Admin Panel.

This specific module allows you to match by a specific IP pattern. The following patterns are supported:

  • 192.168.1.1 or 2001:db8::1 = Direct IP matches (IPv4 and IPv6, in any notation)
  • 192.168.1.0/24 or 2001:db8::/32 = IP ranges in CIDR notation
  • 192.168.1.1 - 192.168.1.10 = Explicit IP ranges
  • * = Every visitor

Be careful with *: a rule with this pattern blocks orders from every visitor of the store. Partial wildcards like 192.168.1.* are not supported and never match. Use a CIDR range like 192.168.1.0/24 instead. Invalid patterns (like 192.168.1.0/33) are skipped and never match.

Installation

To install this module, use the following commands. First, install this module using composer. Note that this step will fail if the Yireo_SalesBlock2 is not installed yet.

composer require yireo/magento2-salesblock2-by-ip

Once this module is installed via composer, you can enable it:

./bin/magento module:enable Yireo_SalesBlock2ByIp

There are no further steps to take. The Yireo_SalesBlock2 module automatically picks up on things.

Client IP detection and reverse proxies

This module reads the client IP from REMOTE_ADDR only. The X-Forwarded-For header can be set to any value by a client, so it is ignored by default.

When Magento runs behind a reverse proxy (load balancer, CDN, Varnish), add the IP addresses of your proxies to the setting Trusted proxies under Stores > Configuration > Yireo > Yireo SalesBlock. When a request comes from a trusted proxy, the rightmost IP in the X-Forwarded-For header that is not a trusted proxy is used as the client IP.

Upgrading to 2.1.3

Versions 2.1.1 and 2.1.2 configured Magento's RemoteAddress globally to trust the X-Forwarded-For header, which allowed visitors to fake their IP (see security advisory YIREO-SALESBLOCK2-BY-IP-2026-001). Version 2.1.3 removes this override. If your store is behind a reverse proxy, configure the Trusted proxies setting after upgrading. If other parts of your store relied on Magento core reading X-Forwarded-For, configure the alternativeHeaders argument of Magento\Framework\HTTP\PhpEnvironment\RemoteAddress in your own project, preferably with a header that your proxy overwrites.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.

[Unreleased]

[2.1.3] - 26 November 2026

Security

  • Backport of security advisory YIREO-SALESBLOCK2-BY-IP-2026-001 from 3.0.0

Fixed

  • Visitors could bypass IP rules by faking the X-Forwarded-For header: the global RemoteAddress override is removed, which also restores Magento core features relying on RemoteAddress (maintenance allowlist, CAPTCHA, rate limits); stores behind a reverse proxy must configure the new "Trusted proxies" setting (see README)
  • An invalid IP range (like 10.0.0.0/33) caused an exception on add-to-cart and checkout for every visitor
  • The customer message revealed the configured blocklist pattern; it now shows a generic message with the visitor's own IP
  • A cached IP could be reused across requests on long-running app servers, and any code could overwrite the detected IP via setIp()

Added

  • New "Trusted proxies" setting: X-Forwarded-For is only used when the request comes from a listed proxy IP, read from the right
  • IPv6 range matching and recognition of alternative notations of the same IP

[2.1.2] - 21 November 2025

Fixed

  • Switch from wikimedia/ip-set to wikimedia/ip-utils [#3 @Krinkle]

[2.1.1] - 10 April 2024

Fixed

  • Rename RuleMatch namespace because of compat PHP 8.2

[2.1.0] - 25 April 2022

Added

  • This CHANGELOG

Removed

  • Removed unneeded module version

[2.1.0] - 16 April 2022

Fixed

  • Remove PHP dep from composer
  • PHP 8 compatibility (and therefore Magento 2.4.4)

Previous versions were not added to CHANGELOG

Versions
Version Stability QA Status Compatibility Released
2.1.3 stable Not tested Not yet tested Details 2026-11-26 01:03:59
3.0.0 stable Fail Magento 2.4.7-2.4.9 Details 2026-11-25 16:53:16
2.1.2 stable Fail Magento 2.4.8 Details 2025-11-21 08:01:18
2.1.1 stable Not tested Not yet tested Details 2024-04-10 10:15:27
2.1.0 stable Not tested Not yet tested Details 2022-04-16 13:17:26
2.0.0 stable Not tested Not yet tested Details 2021-02-17 16:10:54

Requires 5

Package Constraint
ext-pcre *
magento/framework ^101.0|^102.0|^103.0
php >=8.2 <8.6
wikimedia/ip-utils ^4.0.1 || ^5.0
yireo/magento2-salesblock2 ^2.2

Requires-dev 2

Package Constraint
phpunit/phpunit ^10.0
yireo/magento2-integration-test-helper ~0.0

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Warning 6 6 warnings (ruleset: Magento2), 4 auto-fixable with phpcbf
PHPMD Pass 0
Cpd Pass 0
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 33 33
2.4.9 33 33

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 Pass Pass
2.4.9 Pass Pass

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0

More from yireo

View vendor
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.