verbb / knock-knock

Password protect your entire Craft website front-end with a single password
MIT License
18 stars 7 forks source link

Bypass with query param? #74

Closed janhenckens closed 2 months ago

janhenckens commented 3 months ago

What are you trying to do?

For a large migration, we're running a redirect inventory check but that script of course runs into knock-knock for all pages.

We tried adding a query param to all URLs and allow that through regex (/(.*)?rt=1 rt = redirect test) but that gets stripped here

What's your proposed solution?

I don't know if using a query parameters is the beter solution here, happy to hear your thoughts :)

Additional context

The script in question runs through Google Sheets, so setting an allowedIp isn't an option.

engram-design commented 2 months ago

Something I've been meaning to do for a while is allow the enabled setting to be a callback function to allow people greater flexibility to enable or disable the plugin.

To get this early, run composer require verbb/knock-knock:"dev-craft-4 as 2.0.11".

<?php

use Craft;

return [
    '*' => [
        'enabled' => function() {
            if (Craft::$app->getRequest()->getParam('bypass')) {
                return false;
            }

            return true;
        },
    ],
];
janhenckens commented 2 months ago

Thank @engram-design, that's perfect - tested and it works!

engram-design commented 2 months ago

Updated in 2.0.12