# Using DRB as a secure interface

**URL:** <https://www.ruby-forum.com/t/using-drb-as-a-secure-interface/196383>\
**Category:** Ruby\
**Created:** [October 12, 2010, 2:34pm UTC](https://www.ruby-forum.com/t/using-drb-as-a-secure-interface/196383 "2010-10-12T14:34:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinkaku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@shinkaku](https://www.ruby-forum.com/u/shinkaku)\
**Post date:** [October 12, 2010, 2:34pm UTC](https://www.ruby-forum.com/t/using-drb-as-a-secure-interface/196383/1 "2010-10-12T14:34:54Z")

</div>

Is it possible to implement a secure interface exposed to the internet  
using DRB?

I want to pass complex structures through an external API and DRB seems  
like an obvious choice, but I’m concerned that DRB will allow code to  
pass as well as the data, or methods to be called that I didn’t want to  
be exposed.

Are my concerns well founded and if so, is there a way to secure the  
interface?

From my simple tests, any modifications to a standard class are not  
passed, and non-standard classes are not passed either.

I tie down the interface class by creating an “EmptyClass” and  
subclassing the interface class from that.

class EmptyClass  
safe\_methods =  
[: **send** ,: **id** ,:inspect,:respond\_to?,:to\_s,:private\_methods,:protected\_methods,:object\_id]

(instance\_methods - safe\_methods).each do |method|  
undef\_method method  
end  
end

I also carefully check the data in the arguments too. I tried to use  
$SAFE, but it got in the way rather than helped.

Could anybody provide advice on securing DRB and the proper use of $SAFE  
for argument checking?

thanks,

Anthony W…

---

<div class="post-metadata">

**Author:** ![shinkaku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@shinkaku](https://www.ruby-forum.com/u/shinkaku)\
**Post date:** [October 12, 2010, 3:06pm UTC](https://www.ruby-forum.com/t/using-drb-as-a-secure-interface/196383/2 "2010-10-12T15:06:20Z")

</div>

On Tue, Oct 12, 2010 at 2:34 PM, Anthony W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> From my simple tests, any modifications to a standard class are not passed,  
> and non-standard classes are not passed either.

Code is never passed. DRb uses Marshal underneath and since that is a  
data format only without any code you are safe with regard to  
modifications in client programs.

> end  
> You could use BasicObject for that - depending on the Ruby version you  
> are on.

irb(main):001:0\> Object.ancestors  
=\> [Object, Kernel, BasicObject]  
irb(main):002:0\> BasicObject.instance\_methods  
=\> [:==, :equal?, :!, :!=, :instance\_eval, :instance\_exec, : **send**]

> I also carefully check the data in the arguments too. I tried to use $SAFE,  
> but it got in the way rather than helped.
> 
> Could anybody provide advice on securing DRB and the proper use of $SAFE for  
> argument checking?

You would do it as with any API. DRb really only adds remote method  
invocation. IMHO your approach to limit the API which is exposed is  
the first step to get this done. However, you need to do this for  
_all_ classes that you expose via the API which might be quite  
tedious.

Initially I thought you just wanted communication secured (e.g. via  
SSL). But since you seem to be more concerned with API functionality  
there is probably only the manual way as described above. However, it  
is quite unusual to be so restrictive (remember, you can even easily  
get around “private”) so Ruby is probably not too helpful in this  
area.

If you want to allow particular clients only then you might be able to  
restrict client IP via firewall rules. But that of course depends on  
your usage scenario.

After all the question is: how much security do you want and what are  
you willing to pay for it (in terms of effort, money or what)?

Kind regards

robert
