Fix config namespace in the security cookie route - #136
Conversation
config('native-php.secret') reads a namespace that does not exist; the config
files are nativephp.php and nativephp-internal.php. The guard therefore compared
user input against null, so it passed only when no secret was supplied, and the
cookie it issued had a null value.
This is also the one route PreventRegularBrowserAccess deliberately exempts, so
it is worth having work as intended.
gwleuverink
left a comment
There was a problem hiding this comment.
Confirmed this locally. config('native-php.secret') is null, so the guard only passes when no secret is sent at all, and the cookie it then sets is null, which the middleware can never match.
It does break CreateSecurityCookieControllerTest. That test sets native-php.secret and expects a 403 that only happens because of the bug, so it goes red. It needs pointing at nativephp-internal.secret with the secret actually passed.
Before fixing it though, is the route still doing anything? Nothing calls it at runtime. Electron sets _php_native itself and puts the secret header on every request. I'd rather delete the route, controller, test and the middleware exemption. If we keep it, it should 403 on a null secret instead of issuing an empty cookie.
CreateSecurityCookieControllerreadsconfig('native-php.secret'), but there is nonative-phpconfig namespace — the package shipsconfig/nativephp.phpandconfig/nativephp-internal.php, andgrepfindsnative-phpnowhere else in the repo.So today:
resolves to
abort_if($request->input('secret') !== null, 403). The guard passes only when nosecretparameter is supplied, and then the cookie is issued with anullvalue:The middleware that consumes it compares against
config('nativephp-internal.secret'), so the cookie this route sets can never satisfy it.This is also the one route
PreventRegularBrowserAccessdeliberately exempts:which seems worth having work as intended.
The fix points both reads at
nativephp-internal.secret, matching the middleware andconfig/nativephp-internal.php.Noticed while reading the request-authentication path closely — I was tracing how the cookie and the
X-NativePHP-Secretheader relate. Happy to adjust if the intent was different, or to close this if the route is vestigial now that the runtime sets_php_nativedirectly in the Electron session viaappendCookie().