mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Only accept application/json
requests for (JSON) API requests
This commit is contained in:
parent
8c21969b84
commit
5080d776a7
@ -19,6 +19,7 @@ use Grocy\Services\TasksService;
|
||||
use Grocy\Services\UserfieldsService;
|
||||
use Grocy\Services\UsersService;
|
||||
use DI\Container;
|
||||
use Slim\Exception\HttpException;
|
||||
|
||||
class BaseController
|
||||
{
|
||||
@ -213,6 +214,11 @@ class BaseController
|
||||
|
||||
protected function GetParsedAndFilteredRequestBody($request)
|
||||
{
|
||||
if ($request->getHeaderLine('Content-Type') != 'application/json')
|
||||
{
|
||||
throw new HttpException($request, 'Bad Content-Type', 400);
|
||||
}
|
||||
|
||||
if (self::$htmlPurifierInstance == null)
|
||||
{
|
||||
$htmlPurifierConfig = \HTMLPurifier_Config::createDefault();
|
||||
|
@ -22,7 +22,7 @@ class LoginController extends BaseController
|
||||
public function ProcessLogin(Request $request, Response $response, array $args)
|
||||
{
|
||||
$authMiddlewareClass = GROCY_AUTH_CLASS;
|
||||
if ($authMiddlewareClass::ProcessLogin($this->GetParsedAndFilteredRequestBody($request)))
|
||||
if ($authMiddlewareClass::ProcessLogin($request->getParsedBody()))
|
||||
{
|
||||
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/'));
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
|
||||
};
|
||||
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
@ -108,7 +108,7 @@ Grocy.Api.Put = function(apiFunction, jsonData, success, error)
|
||||
};
|
||||
|
||||
xhr.open('PUT', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
@ -146,7 +146,7 @@ Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
|
||||
};
|
||||
|
||||
xhr.open('DELETE', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
@ -184,7 +184,7 @@ Grocy.Api.UploadFile = function(file, group, fileName, success, error)
|
||||
};
|
||||
|
||||
xhr.open('PUT', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/octet-stream');
|
||||
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
|
||||
xhr.send(file);
|
||||
};
|
||||
|
||||
@ -222,7 +222,7 @@ Grocy.Api.DeleteFile = function(fileName, group, success, error)
|
||||
};
|
||||
|
||||
xhr.open('DELETE', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user