fix/headerauth-crash-missing-header #19

Merged
benjamyn merged 5 commits from fix/headerauth-crash-missing-header into master 2023-10-11 00:58:54 -04:00
Owner

Fixed crash with missing header relies on #18

Fixed crash with missing header relies on #18
benjamyn added 6 commits 2023-10-10 00:52:04 -04:00
benjamyn added a new dependency 2023-10-10 00:52:11 -04:00
llama changed title from fix/headerauth-crash-missing-header to fix/headerauth-crash-missing-header 2023-10-10 01:14:35 -04:00
llama changed target branch from master to feat/user-reg-api 2023-10-10 01:14:35 -04:00
llama requested changes 2023-10-10 01:15:34 -04:00
@ -15,6 +15,10 @@ class HeaderAuth
*/
public function handle(Request $request, Closure $next): Response
{
if (is_null($request->header('X-BOTAUTH'))) {

If do empty here instead of is_null

if (empty($request->header('X-BOTAUTH'))) {
If do empty here instead of is_null ``` if (empty($request->header('X-BOTAUTH'))) { ```
benjamyn added 2 commits 2023-10-10 01:35:57 -04:00
kdonaldson requested changes 2023-10-10 01:56:36 -04:00
@ -15,6 +15,10 @@ class HeaderAuth
*/
public function handle(Request $request, Closure $next): Response
{
if (empty($request->header('X-BOTAUTH'))) {

->hasHeader(...) also works instead of having to do the empty check.

Alternatively you can do this:

$header = $request->header('X-BotAuth'); // Returns null when no value is found by default

if (! $header) {
    // return failure response
}

if (! hash_equals(config('bot.header_auth'), $header)) {
    // return failure response
}

return $next($request);

->header(...) has a second parameter that can be specified as a default value when header is not present.
Most of the time in Laravel when there's a "get" kind of function like this there's a secondary "default" parameter that defaults to null you can use, for example config(...), Arr::get(...), etc.

`->hasHeader(...)` also works instead of having to do the empty check. Alternatively you can do this: ```php $header = $request->header('X-BotAuth'); // Returns null when no value is found by default if (! $header) { // return failure response } if (! hash_equals(config('bot.header_auth'), $header)) { // return failure response } return $next($request); ``` `->header(...)` has a second parameter that can be specified as a default value when header is not present. Most of the time in Laravel when there's a "get" kind of function like this there's a secondary "default" parameter that defaults to null you can use, for example config(...), Arr::get(...), etc.
llama changed title from fix/headerauth-crash-missing-header to fix/headerauth-crash-missing-header 2023-10-10 03:19:28 -04:00
llama changed target branch from feat/user-reg-api to master 2023-10-10 03:19:28 -04:00
benjamyn added 1 commit 2023-10-10 22:54:39 -04:00
kdonaldson approved these changes 2023-10-11 00:34:53 -04:00
benjamyn added 1 commit 2023-10-11 00:56:50 -04:00
benjamyn removed a dependency 2023-10-11 00:58:14 -04:00
benjamyn merged commit 84529c373d into master 2023-10-11 00:58:54 -04:00
benjamyn deleted branch fix/headerauth-crash-missing-header 2023-10-11 00:59:01 -04:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
3 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: PriceyBot/PriceyBotPanel#19
No description provided.