# Encrypt URL Params, such as the id

**URL:** <https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995>\
**Category:** Rails\
**Created:** [September 26, 2006, 8:48am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995 "2006-09-26T08:48:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 8:48am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/1 "2006-09-26T08:48:35Z")

</div>

Is there any easy way to encrypt the URL params that is seen in the URL.  
I dont feel comfortable exposing the id of the models to the external  
user.

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 8:55am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/2 "2006-09-26T08:55:45Z")

</div>

---------- Forwarded message ----------  
From: Vinod K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Sep 25, 2006 11:48 PM  
Subject: [Rails] Encrypt URL Params, such as the id  
To: removed\_email\_address@domain.invalid

Is there any easy way to encrypt the URL params that is seen in the URL.  
I dont feel comfortable exposing the id of the models to the external  
user.

–  
Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 11:14am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/3 "2006-09-26T11:14:18Z")

</div>

Use :method=\>POST instead of GET.  
It does not encrypt them, but at least they are not seen in the url.

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/4 "2006-09-26T15:13:43Z")

</div>

Bogdan I. wrote:

> Use :method=\>POST instead of GET.  
> It does not encrypt them, but at least they are not seen in the url.

Unfortunately, that’s still not much of an improvement from a security  
standpoint. Anyone who knows what they’re doing can do a “view source”  
and hack around with the ids.

I would suggest putting the id in a session :

session[:the\_id] = @the\_id

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 4:18pm UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/5 "2006-09-26T16:18:59Z")

</div>

On 26 Sep 2006, at 15:13, Jon C. wrote:

> session[:the\_id] = @the\_id

This won’t be much use if you want to avoid ids being used in links.  
You could go about it in a number of ways: in your models, hash a  
certain field before\_save and save it in a seperate field, you can  
then use this field to search the record.

E.g. id, name, value, hashed\_id (hash of id with a certain salt)

In routes, map /:controller/:action/:hashed\_id.

But in general, this doesn’t provide anymore security than exposing  
the id does.

You could also use a reversible encryption algorithm such as DES  
combined with Base64 and encrypt the ID with it.

All of this is adding an overhead to your application which could  
prove as useful as filling the ocean with buckets of water.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/6 "2006-09-26T17:07:17Z")

</div>

On 9/26/06, Vinod K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there any easy way to encrypt the URL params that is seen in the URL.  
> I dont feel comfortable exposing the id of the models to the external  
> user.

What are you really trying to accomplish here? Why is it bad if your  
users know the IDs of your model objects?

– James

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 27, 2006, 3:02am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/7 "2006-09-27T03:02:23Z")

</div>

What I am trying to achieve is so that malicious users do not call  
controller actions in a loop with all the IDs, thereby killing the  
server.

-Vinod

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 27, 2006, 5:07am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/8 "2006-09-27T05:07:58Z")

</div>

Vinod K. wrote:

> > > Is there any easy way to encrypt the URL params that is seen in the URL.  
> > > I dont feel comfortable exposing the id of the models to the external  
> > > user.
> > 
> > What are you really trying to accomplish here? Why is it bad if your  
> > users know the IDs of your model objects?
> > 
> > – James
> > 
> > >

And what would happen if they just repeatedly threw randomly generated  
parameters at it?

\_Kevin

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 26, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/9 "2006-09-26T16:08:58Z")

</div>

I would say that this kind of security by obfuscation is normally  
unnecessary. If you encrypt the url values, what’s to stop me from  
noting the encrypted values and spoofing a form to send the encrypted  
values.

Surely the security should be in the application in that only methods  
that should be exposed are exposed to general users.

Ross

On 9/26/06, Jon C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> session[:the\_id] = @the\_id
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ross R.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [September 27, 2006, 10:16am UTC](https://www.ruby-forum.com/t/encrypt-url-params-such-as-the-id/69995/10 "2006-09-27T10:16:23Z")

</div>

In that case, try and solve the problem you actually have, rather than  
find ways to hide it.  
There are plenty of ways you can prevent malicious users breaking an  
application.

1. Log the originating IP of requests and deny access after a certain  
number of requests.
2. Create a token which is hashed and must be included in requests,  
expire these after a certain amount of time.
3. Use a captcha form or similar principle to prevent automated  
requests.

Such techniques are much more efficient since they provide security at  
the point of the problem. As others have pointed out malicious users  
can always find a way around obfuscation and you’ll find yourself  
continually fighting fires with your code.

Ross

On 9/27/06, \_Kevin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > >

–  
Ross R.  
removed\_email\_address@domain.invalid
