laravel icon indicating copy to clipboard operation
laravel copied to clipboard

Skip PreventBrowserAccess middleware when running tests

Open gwleuverink opened this issue 9 months ago • 7 comments

The PreventBrowserAccess middleware causes browser tests to fail with 403's. This PR adds a simple guard clause that skips the middleware when it detects it's running tests.

gwleuverink avatar Apr 14 '25 09:04 gwleuverink

Converted to Draft. Will address the feedback given on Discord first 👍🏻

gwleuverink avatar Apr 14 '25 10:04 gwleuverink

Couple notes @NativePHP/contributors:

I've added the automatic registration inside a if (config('nativephp-internal.running')) conditional. Additionally I've also added a guard clause in the middleware itself, in case anyone needs to apply it on other groups.

  • Would it make sense to add it to api group too?
  • We need to update the docs to reflect these changes

gwleuverink avatar Apr 14 '25 22:04 gwleuverink

@gwleuverink i think it does need to be applied globally, not just to the web group.

I'm thinking of scenarios where an attacker could use the API endpoints to trigger app behaviour in an unwanted manner simply by using curl against the right port...

So, if possible let's go for applying globally.

But we need to make sure that all requests from Electron to the Laravel app include the necessary header...

simonhamp avatar Apr 15 '25 05:04 simonhamp

I had to import Foundation\Http\Kernel instead of Contracts\Http\Kernel because phpstan complained the pushMiddleware method is not present on the interface.

gwleuverink avatar Apr 15 '25 22:04 gwleuverink

I tried this in a simple app. Seems to work as expected. Verification welcome!

@simonhamp About the necessary header. Any scenario's this isn't accounted for already?

gwleuverink avatar Apr 15 '25 22:04 gwleuverink

I don't think so. Just something we need to remember to do in case we add new ways to call the Laravel backend.

simonhamp avatar Apr 15 '25 23:04 simonhamp

Shall I remove this section from the docs entirely or leave a note about this behaviour?

At the bottom: https://nativephp.com/docs/desktop/1/digging-deeper/security#the-web-servers

gwleuverink avatar Apr 16 '25 20:04 gwleuverink

Does anyone remember why we didn't merge this? ^^

I know we had a discussion on Discord too but can't remember the outcome.

SRWieZ avatar May 08 '25 08:05 SRWieZ

I was wondering what to do with the docs & it slipped my mind.

Just pushed it: https://github.com/NativePHP/nativephp.com/pull/127

gwleuverink avatar May 09 '25 08:05 gwleuverink

Merged this in as docs also merged.

PeteBishwhip avatar May 12 '25 11:05 PeteBishwhip