Welcome Guest, Not a member yet? Register   Sign In
SecurityException #403
#1

(This post was last modified: 04-13-2020, 03:03 PM by Gary.)

Whilst purposefully throwing a 403 exception, using:

Code:
throw CodeIgniter\Security\Exceptions\SecurityException::forDisallowedAction();

I find that (with the ENVIRONMENT = development), I have a CI error response page displayed, detailing the problem:

Code:
CodeIgniter\Security\Exceptions\SecurityException #403
The action you requested is not allowed.

SYSTEMPATH/Security\Exceptions\SecurityException.php at line 10

3 use CodeIgniter\Exceptions\ExceptionInterface;
4 use CodeIgniter\Exceptions\FrameworkException;
5
6 class SecurityException extends FrameworkException implements ExceptionInterface
7 {
8    public static function forDisallowedAction()
9    {
10        return new static(lang('HTTP.disallowedAction'), 403);
11    }
12 }
… backtrace… etc…

Although the 403 is an error of sorts… and was thrown as an exception, it’s not a CI system error, so I am a bit surprised to see all the framework internals in the response.

I repeated the experiment with ENVIRONMENT = production.  This returns a 500 (Internal Server Error) response.

I have also noticed that during testing of my CSRF filter, the identical  SecurityException #403 errors are reported by the browser, with a trace of the code… and although I’ve not checked for this, I suspect these will also become Internal Server Errors (500) if the tests are done with ENVIRONMENT = production.

I have tried to disable 'toolbar' in the Filters, just in case this was causing the reporting.

What have I missed to be getting the CI SecurityException/Internal Server Error instead of a simple 403 header response page?

Thanks.
Reply
#2

do you solve this?
Reply
#3

> I repeated the experiment with ENVIRONMENT = production.  This returns a 500 (Internal Server Error) response.

I got 403 Whoops page.

Don't use Exceptions to normal operation.
Use it to abnormal operation.

If you want to return 403 page:
PHP Code:
return $this->response->setStatusCode(403)->setBody('403 Forbidden'); 
Reply
#4

Thanks for the pointer kenjis.  At the time I'd been throwing exceptions for test purpose... I don't recall what my final conclusion was, it's possible it was just finger-trouble on my side (?).
This messaging board doesn't make it immediately obvious that one's posts have replies, so missed it until now, sorry.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB