F
Filament4mo ago
ericmp

Prevent users from accessing app via browser

I’ve got an Electron app that’s essentially a web app under the hood, and I want to make sure users can only access it through the app itself, not by opening it in a browser. Right now, I’m trying to enforce this on the frontend, but some users are bypassing it and accessing the app through their browsers, which I want to prevent. Could you help me figure out how to stop this from happening and make them to go via the electron app? Let me know other servers where I may ask this question rather than in here with the non filament tag (:
40 Replies
Luuk Dahlmans
Luuk Dahlmans4mo ago
You could use the userAgent, so in Electron set the useragent to a custom string, like my-app, then use middleware in Laravel to check the userAgent in the request
ericmp
ericmpOP4mo ago
but this can be bypassed easily, am i right? the user can just set it up with a script in the frontend, no?
Luuk Dahlmans
Luuk Dahlmans4mo ago
it depends, if you prevent your electron app from accessing any other url, its more difficult to get the user agent you can even set a custom header
ericmp
ericmpOP4mo ago
hmm okay, also, the thing is that the mobile devices should be able to access it via browser so users can bypass it by simulating they are a mobile device
Luuk Dahlmans
Luuk Dahlmans4mo ago
ah thats a different situation
ericmp
ericmpOP4mo ago
so how would it change?
Luuk Dahlmans
Luuk Dahlmans4mo ago
Since you allow multiple apps to connect, so a regular mobile browser and your electron app. If it where just the electron app, setting a header var would be sufficient. But because you also want to allow browser apps setting something in the header is not possible.
ericmp
ericmpOP4mo ago
why is not possible?
Никола Стојков
I’m so interested in why you need this use case
ericmp
ericmpOP4mo ago
cuz with electron u can access to system stuff, while u cant using a browser basically the do not disturb mode or something like that
Никола Стојков
And the mobile web version? Anyhow, check for electron with custom headers, and do some device fingerprinting to check it’s really mobile and not spoofed If you really think your users would go so far as to spoof user agents for some reason
ericmp
ericmpOP4mo ago
not sure, but we need to let users access the app via mobile too but the custom headers can be spoofed anyways no? like, i can simulate it? like my user agent
Никола Стојков
So why don’t you just make a mobile version with a web view, same as you did with electron Headers shold be electron -> Filament app you can generate keys on every request or something, there are a milion ways to do this
ericmp
ericmpOP4mo ago
that would make the trick i guess yeah, but anyways from a desktop i would be able to change my headers simulating im an android device for example, if im not wrong
Никола Стојков
do some fingerprinting device size
ericmp
ericmpOP4mo ago
wdym filament app?
Никола Стојков
touch size pixels
ericmp
ericmpOP4mo ago
ye but how would be the workaround?
Никола Стојков
what do you mean
ericmp
ericmpOP4mo ago
like, i generate a key for a request and then what i do with it? send it to the frontend, so it gives it back to me in next request? or what do u mean?
Никола Стојков
check that it's valid so you can confirm it comes from electron and not the web brb have a meeting, we can pick some ideas apart later
ericmp
ericmpOP4mo ago
sure 🙌 not sure how
Dennis Koch
Dennis Koch4mo ago
Everything you send over the wire can be spoofed somehow unless you encrypt it. Is it a real security concern? Or just convenience for the users?
ericmp
ericmpOP4mo ago
just convenience for the users what u got in mind 👀 ?
Dennis Koch
Dennis Koch4mo ago
Nothing new. If it's just convenience, why bother with spoofing? If users add HTTP Headers or User Agents to access a web app that only works in Electron mode and they can't do any harm, who cares?
ericmp
ericmpOP4mo ago
ye im with u, yeah but they want to prevent it 🤷‍♂️
Dennis Koch
Dennis Koch4mo ago
Prevent it or have a "100% secure option"? Don't overthink it
ericmp
ericmpOP4mo ago
prevent it, i guess
Dennis Koch
Dennis Koch4mo ago
So I think a header or user-agent is a viable option.
ericmp
ericmpOP4mo ago
so how would be the workaround for that? how would u set it up?
Dennis Koch
Dennis Koch4mo ago
Uhm what do you mean? Add a user agent or a header for the electron app. Or is that not possible?
ericmp
ericmpOP4mo ago
im not sure for where to start. like, in the laravel api, setup a middleware so it expects the electron header to be present? but the user can manipulate it anyways and simulate they are in the electron app but they are in the browser, no?
Dennis Koch
Dennis Koch4mo ago
Yes. That's why I am asking whether it needs to be 100% secure. But you said, it's just for convenience 😅
ericmp
ericmpOP4mo ago
okay haha. and then, if i say u it has to be 100% secure? 👀 just to know what would u do it actually doesnt need to be 100% secure
Dennis Koch
Dennis Koch4mo ago
I don't think that's possible 😅
ericmp
ericmpOP4mo ago
(,: that is what i like about and dislike at the sime time about web dev like, u can customize the frontend as u want as end user but at same time, as the developer, u cant have real control on the frontend
Dennis Koch
Dennis Koch4mo ago
I don't understand. Why wouldn't you have control over the frontend if you are the dev? 🤔 And how is this related to your issue? 😅
ericmp
ericmpOP4mo ago
i ment that the end user can modify the html n stuff, not sure if i explain myself it relates to the issue cuz the user can modify the html i guess
Dennis Koch
Dennis Koch4mo ago
You can also modify native software if you know how to do it. It's more work, but nothing is safe 😅
ericmp
ericmpOP4mo ago
yeah thats true too xd

Did you find this page helpful?