CodeIgniter Forums
Filter Customization for disallowed characters - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Filter Customization for disallowed characters (/showthread.php?tid=91278)



Filter Customization for disallowed characters - Avega Soft - 07-13-2024

Hello everyone. There was a problem with customizing the filter for disallowed characters. If I understand correctly, the exception is triggered before the standard filters are applied. 

PHP Code:
public function before(RequestInterface $request$arguments null)
    {
        $uri $request->getUri()->getPath();

        if ( ! preg_match('/^[' config(App::class)->permittedURIChars ']+$/i'$uri)) {
            if ($request->getUri()->getSegment(1) === 'api') {
                return Services::response()->setStatusCode(404);
            }

            return redirect()->to('/page-404');
        }
    

in App/Config/Filters
PHP Code:
public array $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
            // 'invalidchars',
            'uri'
        ],
        'after'  => [
            // 'honeypot',
            // 'secureheaders',
        ],
    ]; 

The code of my filter is shown below. How to solve this problem correctly without violating the logic of the framework?


RE: Filter Customization for disallowed characters - InsiteFX - 07-13-2024

Not sure what your trying to do here, but the permitted chars are checked for in the Router.php file.

system/Router/Router.php

Look at the __constructor.


RE: Filter Customization for disallowed characters - Avega Soft - 07-13-2024

(07-13-2024, 03:20 AM)InsiteFX Wrote: Not sure what your trying to do here, but the permitted chars are checked for in the Router.php file.

system/Router/Router.php

Look at the __constructor.

I'm trying to catch forbidden characters in the URL (for example mysite.com/привет ) and issue a 404 page , or if there was an api request , then the 404 header


RE: Filter Customization for disallowed characters - ozornick - 07-13-2024

First, allow all characters in the URL.
To be added to .env

Сначала разрешите все символы в URL
В .env добавить 
Code:
app.permittedURIChars =