Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

milosradic's avatar

Laravel - Bind Session to User-Agent string and IP address

During the Penetration testing of web application built with Laravel 6, testers said that user session should bind to User-Agent string and IP address in order to prevent stolen Session IDs to be used on another PCs.

I have googled about this and didn't find anything helpful. I am not even sure if Laravel does this by default.

My question is: How can i bind user session to User-Agent string and user IP address?

Any suggestions are appreciated.

1 like
3 replies
martinbean's avatar

@milosradic And what happens if I’m browsing on my mobile on a 3G or 4G network, and my mobile provider uses rotating IP addresses between page views? I’m going to be logged out clicking around your application.

milosradic's avatar

Hello,

Thanks for your reply.

The situation is kind of specific. It is the login for CMS users, and CMS will be available only from internal network (CMS will be available only from list of IP addresses) and not be available through external network (eg. 3G or 4G).

But, in CMS there are multiple user groups and if somehow one of the employees with lower privileges gets session cookie from employee with higher privileges he will be able to be authenticated as that user just by pasting that cookie value in his browser.

All of the employees will probably have same IP address, so it is not that important to bind session to IP address, but at least to bind it User-Agent so it can not be reused on another PC or different browser.

I hope you understand what i wanted to say :D

martinbean's avatar

@milosradic I still don’t really think that’s secure. As surely the same browser running on similar hardware is going to have the same user agent string. Not to mention that a user agent string can be “spoofed” just as easily as a cookie’s value can be copy-pasted.

Also, I don’t know off the top of my head, but Laravel’s cookies are encrypted and I think invalid somehow if it’s stolen. Like I say, I don’t know how it does it off the top of my head.

Please or to participate in this conversation.