From: "Peña, Botp" Date: 2007-08-08T19:32:00+09:00 Subject: Re: non-constant strings From: Dmitry Bilunov [mailto:kmeaw@kmeaw.com] : as a nuby, i can only vouch for the fundamentals. so pardon me if i say something wrong here :) # command = "some_safe_command" here command var is pointing to string object "some_safe_command" # runner = SecureRunner.new(command) ^^^^^^^^^^^^^ here command ptr is passed # command.replace("evil_command") # BYPASS THE CHECK ah, you used replace. This will replace the contents to wch command var is pointing (to wch in turn you passed to securerunner). you can use instead command = "evil command" command var will now hold a new and different ptr to object string "evil command" (and lose the ptr to "safe_command" wc you passed to saferunner). it's your code :) # runner.run # runs evil_command, that is not safe there is a problem with your runner. your instance must have no knowledge of the outside. eg, this is just one stupid example, C:\temp>cat test.rb class SecureRunner def initialize(command) @command = command.dup #<-- i duped. now @command is diff object end def run #system(@command) puts "i just ran #{@command}" end end command = "some_safe_command" runner = SecureRunner.new(command) command.replace("evil_command") runner.run C:\temp>ruby test.rb i just ran some_safe_command C:\temp> now if you really do not want to change string objects. You can freeze them. But be careful, there is no mr unfreeze yet :) kind regards -botp