Welcome Guest, Not a member yet? Register   Sign In
Filter Customization for disallowed characters
#1

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?
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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
Reply
#4

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

Сначала разрешите все символы в URL
В .env добавить 
Code:
app.permittedURIChars = 
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB