firewall icon indicating copy to clipboard operation
firewall copied to clipboard

Don't allow same range of IPs in black and whitelist

Open meyer59 opened this issue 8 years ago • 13 comments

Hi, First, i would like to thank you your amazing package! I just installed the latest version of the firewall and when i'm trying to get any route, i ran into this issue: Call to undefined function PragmaRX\Firewall\ipv4_in_range() in Firewall.php (line 375) I have the range ip activated with a bunch of ips in the whitelist array like 192.168.*.* I'm on Laravel 5.4. Any help wil be greatly appreciated, Thank you

meyer59 avatar Sep 06 '17 02:09 meyer59

Yeah, sorry, I just tagged 2.1.0 and it should be fixed.

antonioribeiro avatar Sep 06 '17 02:09 antonioribeiro

I also changed the way we configure response, so you should also add this to your config/firewall.php:

    'responses' => [
        'blacklist' => [
            'code' => 403, // 200 = log && notify, but keep pages rendering

            'message' => null,

            'view' => null,

            'redirect_to' => null,

            'abort' => false, // return abort() instead of Response::make() - disabled by default
        ],

        'whitelist' => [
            'code' => 403, // 200 = log && notify, but keep pages rendering

            'message' => null,

            'view' => null,

            'redirect_to' => null,

            'abort' => false, // return abort() instead of Response::make() - disabled by default
        ],
    ],

antonioribeiro avatar Sep 06 '17 02:09 antonioribeiro

Thanks, just updated and no more exception. However, the range filter doesn't seem to work properly. My ip is 192.168.0.250, this doesn't work 'blacklist' => [ '192.168.0.*'] This is working: 'blacklist' => [ '192.168.0.250'] Maybe i am missing something in the config ?

meyer59 avatar Sep 06 '17 03:09 meyer59

Try to use it as

'blacklist' => [ '192.168.0.0/24' ]

antonioribeiro avatar Sep 06 '17 04:09 antonioribeiro

And I'm not sure why it's not working with you, because tests are passing:

public function test_wildcard()
{
    Firewall::whitelist('172.17.*.*');

    $this->assertTrue(Firewall::isWhitelisted($ip = '172.17.0.100'));

    $this->assertTrue(Firewall::isWhitelisted($ip = '172.17.1.101'));

    $this->assertTrue(Firewall::isWhitelisted($ip = '172.17.2.102'));

    $this->assertTrue(Firewall::isWhitelisted($ip = '172.17.255.255'));
}

antonioribeiro avatar Sep 06 '17 13:09 antonioribeiro

The 'blacklist' => [ '192.168.0.0/24' ] don't work too. How i can run the test_wildcard method in my project to see if it passes ?

meyer59 avatar Sep 06 '17 16:09 meyer59

Go to the firewall path: vendor/pragmarx/firewall and run:

composer install

then

phpunit

antonioribeiro avatar Sep 06 '17 16:09 antonioribeiro

Here's the output: Runtime: PHP 5.6.31-1~dotdeb+zts+7.1 with Xdebug 2.4.0 Configuration: /home/html/site2/web/TV/vendor/pragmarx/firewall/phpunit.xml

................................................................. 65 / 74 ( 87%) ......... 74 / 74 (100%)

Time: 1.88 minutes, Memory: 73.75MB

OK (74 tests, 150 assertions)

Generating code coverage report in Clover XML format ... done

Generating code coverage report in HTML format ... done

meyer59 avatar Sep 06 '17 16:09 meyer59

Do you get anything in your laravel.log?

antonioribeiro avatar Sep 06 '17 16:09 antonioribeiro

Tests passing, all of them. And I just tested it in an application here

When blacklisting:

image

I get:

image

Removing localhost:

image

I get the page back:

image

Then I cleared the database:

image

Added it to the array:

image

And it worked.

antonioribeiro avatar Sep 06 '17 16:09 antonioribeiro

Thank you for your detailled response. I think i got what's going on. I have the same range in the whitelist and the blacklist. I was doing some test on blacklisted/whitelisted routes that's why i had the same range here and there.
when i did php artisan firewall:list i got that image All seems to work, Thanks!

meyer59 avatar Sep 06 '17 17:09 meyer59

Cool! I'll add a test for that too and a warning in the log.

Thank you!

antonioribeiro avatar Sep 06 '17 17:09 antonioribeiro

And I'll leave it open until I get this done.

antonioribeiro avatar Sep 06 '17 17:09 antonioribeiro