Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate secure private urls in CakePHP?

I like to create a secure URL for a user for his entries (delete and edit links).

for ex, this is my actual URL

http://localhost/project/blogs/delete/1/test-title

what i want to do is,

http://localhost/project/blogs/delete/4324143563443/test-title (some hash made of salt+user auth id)

My main purpose is to create a secure hash along with the URL for delete and edit method. Is there any custom method's available? I searched in CakePHP Security functions http://book.cakephp.org/2.0/en/core-utility-libraries/security.html and not sure whether its the right way to do it or not sure which algorith to use)

like image 991
sk8terboi87 ツ Avatar asked Dec 30 '12 13:12

sk8terboi87 ツ


2 Answers

Firstly, although I am not quite clear on how/why you want to do this, it sounds like you want to "protect" these links through obscuring their URL's. This is known as "Security through Obscurity" and is generally frowned upon.

In Cake (and most apps), the usual way to achieve this is to allow users to login (see: Auth Component) and then, for example, in your delete action (i.e. for the URL /delete/1) requests would be checked for a valid user session, and that the user has sufficient permissions to delete.

Although I would strongly reccommend otherwise, if you did wish to create these obscure URLs then you should probably use Security::hash();. The problem with this is that you wouldn't be able to just hash the id and then determine the id from the hash directly (thats the whole point!). Instead you would need to store the hashes in the database and then query for the hash (each post could have a unique hash generated either from the id or just random data, either would do).

like image 86
Thom Seddon Avatar answered Nov 18 '22 14:11

Thom Seddon


As already mentioned "Security by obscurity" isn't very smart. Nevertheless easiest way to achieve what you want is use UUID's for your table's primary key instead of numeric auto increment.

like image 3
ADmad Avatar answered Nov 18 '22 16:11

ADmad