Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Fatal error: Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message: 167 #6227

Closed
dariusaurich opened this issue Jul 3, 2022 · 5 comments · Fixed by #6228 or #6254
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@dariusaurich
Copy link

dariusaurich commented Jul 3, 2022

PHP Version

8.1

CodeIgniter4 Version

4

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

ehm id write an api and this comes:

<b>Fatal error</b>:  Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message: 167 in /var/www/vhosts/blackserv.de/api.blackserv.de/system/HTTP/ResponseTrait.php: 158
Stack trace:
#0 /var/www/vhosts/blackserv.de/api.blackserv.de/system/HTTP/ResponseTrait.php(158): CodeIgniter\HTTP\Exceptions\HTTPException: :forUnkownStatusCode()
#1 /var/www/vhosts/blackserv.de/api.blackserv.de/system/Debug/Exceptions.php(114): CodeIgniter\HTTP\Response-&gt;setStatusCode()
#2 [internal function]: CodeIgniter\Debug\Exceptions-&gt;exceptionHandler()
#3 {main}
thrown in <b>/var/www/vhosts/blackserv.de/api.blackserv.de/system/HTTP/ResponseTrait.php</b> on line <b>158</b><br/>
{
    "title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Uncaught CodeIgniter\\HTTP\\Exceptions\\HTTPException: Unknown HTTP status code provided with no message: 167 in /var/www/vhosts/blackserv.de/api.blackserv.de/system/HTTP/ResponseTrait.php:158\nStack trace:\n#0 /var/www/vhosts/blackserv.de/api.blackserv.de/system/HTTP/ResponseTrait.php(158): CodeIgniter\\HTTP\\Exceptions\\HTTPException::forUnkownStatusCode()\n#1 /var/www/vhosts/blackserv.de/api.blackserv.de/system/Debug/Exceptions.php(114): CodeIgniter\\HTTP\\Response->setStatusCode()\n#2 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler()\n#3 {main}\n  thrown",
    "file": "/var/www/vhosts/blackserv.de/api.blackserv.de/system/HTTP/ResponseTrait.php",
    "line": 158,
    "trace": [
        {
            "function": "shutdownHandler",
            "class": "CodeIgniter\\Debug\\Exceptions",
            "type": "->"
        }
    ]
}

Steps to Reproduce

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use App\Libraries\AuthSystem;

class Authentication extends BaseController
{
    use ResponseTrait;

    public function index()
    {
        $data = ['options' => ['1' => '/authentication/login', '2' => '/authentication/register'], 'server' => getEnv("ServerID") , ];
        return $this->respond($data);
    }

    public function login()
    {
        $auth = new AuthSystem();
        if (isset($_POST['username']) || isset($_POST['email']) && isset($_POST['password']))
        {
            if (isset($_POST['username']))
            {
                $login = $auth->login($_POST['username'], $_POST['password']);
                $userdat = $auth->find($_POST['username']);
            }
            if (isset($_POST['email']))
            {
                $login = $auth->login($_POST['email'], $_POST['password']);
                $userdat = $auth->find($_POST['email']);
            }
            if ($login == "success")
            {	
				
                $sessiontoken = $auth->regentoken($userdat->id, $this->request->getUserAgent(), $this->request->getIPAddress());

                $data = ['state' => 'succes', 'session' => $sessiontoken, 'server' => getEnv("ServerID") , ];
                return $this->respond($data);

            }
            else
            {
                $data = ['state' => 'error', 'message' => $login, 'server' => getEnv("ServerID") , ];
				return $this->respond($data);
            }

        }
        else
        {
            $data = ['state' => 'error', 'message' => 'not all parameters given', 'server' => getEnv("ServerID") , ];
            return $this->respond($data);
        }
		return $this->respond($data);
    }

}

Expected Output

nothing

Anything else?

PLEASE HELP

@dariusaurich dariusaurich added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 3, 2022
@dariusaurich
Copy link
Author

dariusaurich commented Jul 3, 2022

image
It is because of this insert if I take it out then it works without problems, but I need this one!

@kenjis kenjis changed the title Bug: <b>Fatal error</b>: Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message Bug: Fatal error: Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message Jul 3, 2022
@kenjis
Copy link
Member

kenjis commented Jul 3, 2022

If it works when you comment out the $db->query() line, the query probably causes an error.
See CodeIgnite4 log file. Can you see any error for the query?

You misuse esc() and your code has vulnerability.
I recommend you learn SQL and SQL injections.

@kenjis kenjis changed the title Bug: Fatal error: Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message Bug: Fatal error: Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message: 167 Jul 4, 2022
@kenjis
Copy link
Member

kenjis commented Jul 4, 2022

What database are you using?

@kenjis
Copy link
Member

kenjis commented Jul 4, 2022

We can reproduce this error.

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        throw new \RuntimeException('Sample exception', 167);
    }
}

You will see:

Fatal error: Uncaught CodeIgniter\HTTP\Exceptions\HTTPException: Unknown HTTP status code provided with no message: 167 in .../CodeIgniter4/system/HTTP/ResponseTrait.php on line 158

@kenjis
Copy link
Member

kenjis commented Jul 13, 2022

@Darius01W This bug was fixed in develop branch, and it will be included in v4.2.2.
Thank you for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
2 participants