Remove the dead 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.
Nothing calls _native/api/cookie: Electron sets _php_native itself via appendCookie() at boot and sends X-NativePHP-Secret on every request, so the route, its controller, its test and the middleware exemption all go.
|
Agreed, deleted rather than fixed. That also takes care of the red test you hit. It went away along with the controller, so no need to repoint it at Before deleting I checked the same thing you did. The only writer of PR title and description are updated accordingly. |
|
The nativephp/laravel repo has been superceeded by this one. The desktop package combined the laravel and electron packages in a single repo, so since grep didnt turn anything up its safe to assume there are no more callers to this route 👌 |
CreateSecurityCookieControllerreadsconfig('native-php.secret'), but there is nonative-phpconfig namespace. The package shipsconfig/nativephp.phpandconfig/nativephp-internal.php, and grep does not findnative-phpanywhere else in the repo. So the guard passed only when nosecretparameter was supplied, and the cookie was then issued with anullvalue, whichPreventRegularBrowserAccesscan never match.As per review, instead of repairing it: the route is vestigial. Nothing calls
_native/api/cookieat runtime. Electron sets_php_nativeitself throughappendCookie()inserver/index.tsat boot, and putsX-NativePHP-Secreton every request it makes. So this PR now deletes:routes/api.phpCreateSecurityCookieControllerCreateSecurityCookieControllerTest_native/api/cookieexemption inPreventRegularBrowserAccessNet diff is 46 deleted lines with no behaviour change. The deleted route could not issue a usable cookie in the first place, and removing the exemption closes a hole rather than taking away anything that was working.