Skip to content

Commit

Permalink
enhance JSON validation
Browse files Browse the repository at this point in the history
enable FastCGI Authorization Header
  • Loading branch information
andrerademacher committed Apr 11, 2017
1 parent 83bbda3 commit f43589c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# enable Authorization header on server using (Fast)CGI
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
Expand Down
6 changes: 5 additions & 1 deletion src/Broadcasting/Api/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ public function validateContentIsValidJson()
{
$content = $this->request->getBody();
$decodedBody = json_decode($content);
if (json_last_error() !== JSON_ERROR_NONE) {
if (json_last_error() !== JSON_ERROR_NONE ) {
throw new \Exception('The given JSON is invalid: ' . json_last_error_msg(), 400);
}

if (!($decodedBody instanceof \StdClass)) {
throw new \Exception('The given JSON is not an object.', 400);
}

return $decodedBody;
}

Expand Down

0 comments on commit f43589c

Please sign in to comment.