aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEl RIDO <[email protected]>2022-02-28 16:24:06 +0100
committerEl RIDO <[email protected]>2022-02-28 16:24:06 +0100
commit3e028183358b0241301df1b9925a32ace6c23f66 (patch)
tree96f0e9e9ab015b7d6a593ed13f227b9789ee2761
parent6b001b5e4abba23fe26bd8d685c15bf4c5001b9d (diff)
downloadprivatebin-3e028183358b0241301df1b9925a32ace6c23f66.tar.gz
privatebin-3e028183358b0241301df1b9925a32ace6c23f66.tar.bz2
privatebin-3e028183358b0241301df1b9925a32ace6c23f66.zip
actually support the short CIDR notationtrafficlimit-short-subnets
-rw-r--r--lib/Persistence/TrafficLimiter.php5
-rw-r--r--tst/Persistence/TrafficLimiterTest.php4
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/Persistence/TrafficLimiter.php b/lib/Persistence/TrafficLimiter.php
index f071562b..93f91d23 100644
--- a/lib/Persistence/TrafficLimiter.php
+++ b/lib/Persistence/TrafficLimiter.php
@@ -146,7 +146,10 @@ class TrafficLimiter extends AbstractPersistence
$ipRange = trim($ipRange);
}
$address = Factory::parseAddressString($_SERVER[self::$_ipKey]);
- $range = Factory::parseRangeString($ipRange, ParseStringFlag::IPV4_MAYBE_NON_DECIMAL);
+ $range = Factory::parseRangeString(
+ $ipRange,
+ ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4SUBNET_MAYBE_COMPACT | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED
+ );
// address could not be parsed, we might not be in IP space and try a string comparison instead
if (is_null($address)) {
diff --git a/tst/Persistence/TrafficLimiterTest.php b/tst/Persistence/TrafficLimiterTest.php
index a8b8040c..84e0bae8 100644
--- a/tst/Persistence/TrafficLimiterTest.php
+++ b/tst/Persistence/TrafficLimiterTest.php
@@ -57,7 +57,7 @@ class TrafficLimiterTest extends PHPUnit_Framework_TestCase
public function testTrafficLimitExempted()
{
- TrafficLimiter::setExempted('1.2.3.4,10.10.10.0/24,2001:1620:2057::/48');
+ TrafficLimiter::setExempted('1.2.3.4,10.10.10/24,2001:1620:2057::/48');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$this->assertTrue(TrafficLimiter::canPass(), 'first request may pass');
try {
@@ -85,7 +85,7 @@ class TrafficLimiterTest extends PHPUnit_Framework_TestCase
public function testTrafficLimitCreators()
{
- TrafficLimiter::setCreators('1.2.3.4,10.10.10.0/24,2001:1620:2057::/48');
+ TrafficLimiter::setCreators('1.2.3.4,10.10.10/24,2001:1620:2057::/48');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
try {
$this->assertFalse(TrafficLimiter::canPass(), 'expected an exception');