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

Zoul's avatar
Level 5

hiding id from url

Hi everyone, I searched and found there are 2 methods:

  1. using uuid, which requires adding uuid for my migrations table and following by a trait so that it can be used everywhere

  2. this is to encyptIs it use to encrypt id in blade like: encrypt($blog->id) and decrypt it in controller like: Crypt::decrypt($id); However this one is not very secure, if the user change the value, and an exception can be thrown.

Is there a way that i can make the secod method more secure to use it ? Or may be you have other suggestion ? Thanks a lot !

0 likes
23 replies
lat4732's avatar

You can decrypt what the user set as GET PARAMETER and check if it does exists in database as an id. If doesn't exist - throw 404. But I prefer uuid.

1 like
Zoul's avatar
Level 5

Thanks for your support @Laralex !

Yes, many developers prefer uuid, but i guess i have to modify all my migration tables by adding uuid column, right ? which is not practical when i want add it for an app in production mode, the second thing, is that uuid can slow the performence as it generates a long string encryption, but its recommanded when using multi dbs.

check if it does exists in database as an id. If doesn't exist - throw 404. this sounds good if its secure

MohamedTammam's avatar

May I know what's the use case that needs to hide the id from the URL?

1 like
Zoul's avatar
Level 5

Thanks @MohamedTammam for your help !

I'm sending IDs from blades via update,create,show, forms to controllers, and vise versa, and i don't want to expose IDs in url traffic which make my app vulnerable to attach, i'm looking for a way that i hide IDs on fly

iftekhs's avatar

@Zoul How does your id exposing make your app vulnerable? are you not protecting your app from that kind of thing? For example, you can easily validate your delete function so that the correct person deletes the correct data whether the id is exposed to them or not. so what vulnerability actually your trying to point out?

1 like
Zoul's avatar
Level 5

Thanks for your support @iftekhs !

Let me take the id of 2 as an example that is being sent from blade to controller, and send the id back again with more the exact record, this id looks like this in url:

http://www.exmaple.com/blog/2
http://www.exmaple.com/user/2
etc

Are you saying that, leaving the id in url is save ? If that is correct, why developers are using uuid or ecrypt ids to hide them from url ? Thanks

jlrdw's avatar

@Zoul click the My participation link, you do not see an ID, you can use the auth id. Using the ID in the URL it's not applicable in that case.

1 like
Zoul's avatar
Level 5

Thanks @MohamedTammam for your help ! I don't know if exposing IDs in url is not dangerous, i'm about to secure my app before deplying it in production, and i found developers talking about uuid, ecrypting ids that should be hidden from url, Do you think, if i'm sending id number 1 which passes through url as 1 and getting it in controller and then check and getting its reocrd from db and send it back again in blade, is save ?

Zoul's avatar
Level 5

thanks @jlrdw for your support ! If i got you correctly, you are saying, when authenticating users, its not applicable, but what is for when using other data, like blogs etc, does not that matter ?

MohamedTammam's avatar

@Zoul There's no security issue here. People use something different than the id for different cases.

For example, slugs for better seo, uuid to prevent users to find the order of records, for example if you see blog/2 you know that the next blog is blog/3 etc.

But there's no a security issue by exposing the id.

2 likes
jlrdw's avatar

@Zoul you have two main situations of updating:

  • A user can update their data (like a reply here)

In that case the auth id is verified via authorization to make sure the correct id is used.

  • A know trusted person is updating something (like a trusted admin)

In that case it is safe to use the id in the url but authorization is still used.

An example an admin is updating some employee data. If authorization and query scopes are used you really don't need uuid's.

2 likes
Zoul's avatar
Level 5

thanks a lot for your valuable time @dincho186, its very good article explaining uuid, i'm trying to avoid using uuid if i find another option, although its the most recommended,

Zoul's avatar
Level 5

thanks a lot @jlrdw for your help ! I was not aware of that, no need to use use any kind of uuid's when the user is authenticated, thank a lot

Zoul's avatar
Level 5

thanks a lot @iftekhs for your efforts and support ! Very informative discussion about uuids,GUIDs and ids,

Zoul's avatar
Level 5

thanks alot for your support @MohamedTammam, People use something different than the id for different cases. you are right, as others confirmed that for authenticated user no need to use uuids,guids or hashids but other than that, its not recommaed to expose ids in urls

martinbean's avatar
Level 80

@zoul Yes, pitting auto-incrementing primary keys in URLs can be a security issue if it means someone can just create a script to enumerate your IDs and scrape your data.

You can use UUIDs as has been mentioned. I wouldn’t put encrypted IDs in URLs because if you ever change your encryption key, then that’s going to “break” every URL for your site. So URLs people have bookmarked/favourited, in their browsers’ suggestions, URLs indexed by search engines, etc. Also, if someone does identify encrypted IDs as encrypted strings, then they can start attacking that by trying to decrypt them and if they discover your encryption key, then you have larger problems, especially if you’re using encryption anywhere else in your app.

Another alternative is hashids. This will let you put pseudo-random alphanumeric IDs in URLs that you can then decode server-side back to the integer primary key value.

2 likes
iftekhs's avatar

@martinbean can be a security issue if it means someone can just create a script to enumerate your IDs and scrape your data. -> Unless you have correct authorization and validation right?

Zoul's avatar
Level 5

Thanks a lot @martinbean, i guess i will finally use hashids, which takes less memory usage than uuids

Zoul's avatar
Level 5

Thank you all so much for your valuable time and support !

1 like

Please or to participate in this conversation.