Aru*_*hit 15 ruby taint taint-checking ruby-1.9
什么时候Ruby对象需要被污染,什么时候应该解开它们?受污染对象的概念如何使Ruby脚本以安全模式运行?任何人都可以详细说明这一点,以便用一些代码片段清楚地理解这个概念吗?
Tod*_*obs 17
根据定义,用户输入受到污染.例如:
string = gets
string.tainted?
# => true
Run Code Online (Sandbox Code Playgroud)
您也可以手动污染对象.
string = 'Not yet tainted.'
string.tainted?
# => false
(string = 'Explicitly taint me!').taint
string.tainted?
# => true
Run Code Online (Sandbox Code Playgroud)
通常,只有在验证和/或清理对象后才能对对象进行解开.对于某些您不希望在不受信任的字符串或其他对象上运行的操作,或者当您的安全级别需要未受污染的对象执行所需操作时,取消对象标记为"安全".
解开对象的最简单方法是在其上调用Object#untaint方法.例如,如果您的字符串变量包含受污染的对象,则:
(string = "Let's taint this string!").taint
string.untaint.tainted?
# => false
Run Code Online (Sandbox Code Playgroud)
您可以在Ruby 编程的安全章节中找到有关受污染Ruby的更多信息.