add safe_leve, default_safe_level ([druby-ja:120])
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1a22e46d60
commit
2681be1eed
@ -1,3 +1,10 @@
|
|||||||
|
Mon Feb 14 00:10:17 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
|
* lib/drb/drb.rb (DRbServer): add default_safe_level, safe_level,
|
||||||
|
config[:safe_level] ([druby-ja:120])
|
||||||
|
|
||||||
|
* test/drb/test_drb.rb, ut_eval.rb, ut_safe1.rb: ditto.
|
||||||
|
|
||||||
Sun Feb 13 23:13:46 2005 Kouhei Sutou <kou@cozmixng.org>
|
Sun Feb 13 23:13:46 2005 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rss/dublincore.rb (RSS::DublicCoreModel#date{,=}): added
|
* lib/rss/dublincore.rb (RSS::DublicCoreModel#date{,=}): added
|
||||||
|
@ -1186,6 +1186,7 @@ module DRb
|
|||||||
@@argc_limit = 256
|
@@argc_limit = 256
|
||||||
@@load_limit = 256 * 102400
|
@@load_limit = 256 * 102400
|
||||||
@@verbose = false
|
@@verbose = false
|
||||||
|
@@safe_level = 0
|
||||||
|
|
||||||
# Set the default value for the :argc_limit option.
|
# Set the default value for the :argc_limit option.
|
||||||
#
|
#
|
||||||
@ -1215,6 +1216,10 @@ module DRb
|
|||||||
@@idconv = idconv
|
@@idconv = idconv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.default_sefe_level(level)
|
||||||
|
@@level = level
|
||||||
|
end
|
||||||
|
|
||||||
# Set the default value of the :verbose option.
|
# Set the default value of the :verbose option.
|
||||||
#
|
#
|
||||||
# See #new(). The initial default value is false.
|
# See #new(). The initial default value is false.
|
||||||
@ -1233,7 +1238,8 @@ module DRb
|
|||||||
:verbose => @@verbose,
|
:verbose => @@verbose,
|
||||||
:tcp_acl => @@acl,
|
:tcp_acl => @@acl,
|
||||||
:load_limit => @@load_limit,
|
:load_limit => @@load_limit,
|
||||||
:argc_limit => @@argc_limit
|
:argc_limit => @@argc_limit,
|
||||||
|
:safe_level => @@safe_level
|
||||||
}
|
}
|
||||||
default_config.update(hash)
|
default_config.update(hash)
|
||||||
end
|
end
|
||||||
@ -1298,6 +1304,7 @@ module DRb
|
|||||||
|
|
||||||
@front = front
|
@front = front
|
||||||
@idconv = @config[:idconv]
|
@idconv = @config[:idconv]
|
||||||
|
@safe_level = @config[:safe_level]
|
||||||
|
|
||||||
@grp = ThreadGroup.new
|
@grp = ThreadGroup.new
|
||||||
@thread = run
|
@thread = run
|
||||||
@ -1326,6 +1333,8 @@ module DRb
|
|||||||
# The configuration of this DRbServer
|
# The configuration of this DRbServer
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
|
|
||||||
|
attr_reader :safe_level
|
||||||
|
|
||||||
# Set whether to operate in verbose mode.
|
# Set whether to operate in verbose mode.
|
||||||
#
|
#
|
||||||
# In verbose mode, failed calls are logged to stdout.
|
# In verbose mode, failed calls are logged to stdout.
|
||||||
@ -1395,7 +1404,7 @@ module DRb
|
|||||||
#
|
#
|
||||||
# These methods are not callable via dRuby.
|
# These methods are not callable via dRuby.
|
||||||
INSECURE_METHOD = [
|
INSECURE_METHOD = [
|
||||||
:__send__, :instance_eval, :module_eval, :class_eval
|
:__send__
|
||||||
]
|
]
|
||||||
|
|
||||||
# Has a method been included in the list of insecure methods?
|
# Has a method been included in the list of insecure methods?
|
||||||
@ -1440,6 +1449,7 @@ module DRb
|
|||||||
class InvokeMethod # :nodoc:
|
class InvokeMethod # :nodoc:
|
||||||
def initialize(drb_server, client)
|
def initialize(drb_server, client)
|
||||||
@drb_server = drb_server
|
@drb_server = drb_server
|
||||||
|
@safe_level = drb_server.safe_level
|
||||||
@client = client
|
@client = client
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1447,10 +1457,28 @@ module DRb
|
|||||||
@result = nil
|
@result = nil
|
||||||
@succ = false
|
@succ = false
|
||||||
setup_message
|
setup_message
|
||||||
if @block
|
|
||||||
@result = perform_with_block
|
if $SAFE < @safe_level
|
||||||
|
info = Thread.current['DRb']
|
||||||
|
if @block
|
||||||
|
@result = Thread.new {
|
||||||
|
Thread.current['DRb'] = info
|
||||||
|
$SAFE = @safe_level
|
||||||
|
perform_with_block
|
||||||
|
}.value
|
||||||
|
else
|
||||||
|
@result = Thread.new {
|
||||||
|
Thread.current['DRb'] = info
|
||||||
|
$SAFE = @safe_level
|
||||||
|
perform_without_block
|
||||||
|
}.value
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@result = perform_without_block
|
if @block
|
||||||
|
@result = perform_with_block
|
||||||
|
else
|
||||||
|
@result = perform_without_block
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@succ = true
|
@succ = true
|
||||||
if @msg_id == :to_ary
|
if @msg_id == :to_ary
|
||||||
|
@ -209,7 +209,7 @@ class TestDRbEval < Test::Unit::TestCase
|
|||||||
@ext.stop_service if @ext
|
@ext.stop_service if @ext
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_01_safe1_eval
|
def test_01_safe1_safe4_eval
|
||||||
assert_raises(SecurityError) do
|
assert_raises(SecurityError) do
|
||||||
@there.method_missing(:instance_eval, 'ENV.inspect')
|
@there.method_missing(:instance_eval, 'ENV.inspect')
|
||||||
end
|
end
|
||||||
@ -227,6 +227,19 @@ class TestDRbEval < Test::Unit::TestCase
|
|||||||
assert_raises(SecurityError) do
|
assert_raises(SecurityError) do
|
||||||
remote_class.module_eval('ENV.inspect')
|
remote_class.module_eval('ENV.inspect')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
four = @there.four
|
||||||
|
assert_equal(1, four.method_missing(:send, :eval, '1'))
|
||||||
|
|
||||||
|
remote_class = four.remote_class
|
||||||
|
|
||||||
|
assert_raises(SecurityError) do
|
||||||
|
remote_class.class_eval('ENV.inspect')
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raises(SecurityError) do
|
||||||
|
remote_class.module_eval('ENV.inspect')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,6 +2,14 @@ require 'drb/drb'
|
|||||||
require 'drb/extserv'
|
require 'drb/extserv'
|
||||||
|
|
||||||
class EvalAttack
|
class EvalAttack
|
||||||
|
def initialize
|
||||||
|
@four = DRb::DRbServer.new('druby://localhost:0', self, {:safe_level => 4})
|
||||||
|
end
|
||||||
|
|
||||||
|
def four
|
||||||
|
DRbObject.new_with_uri(@four.uri)
|
||||||
|
end
|
||||||
|
|
||||||
def remote_class
|
def remote_class
|
||||||
DRbObject.new(self.class)
|
DRbObject.new(self.class)
|
||||||
end
|
end
|
||||||
@ -17,7 +25,7 @@ if __FILE__ == $0
|
|||||||
|
|
||||||
$SAFE = 1
|
$SAFE = 1
|
||||||
|
|
||||||
DRb.start_service('druby://localhost:0', EvalAttack.new)
|
DRb.start_service('druby://localhost:0', EvalAttack.new, {:safe_level => 2})
|
||||||
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
|
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
|
||||||
DRb.thread.join
|
DRb.thread.join
|
||||||
end
|
end
|
||||||
|
@ -9,8 +9,8 @@ if __FILE__ == $0
|
|||||||
end
|
end
|
||||||
|
|
||||||
$SAFE = 1
|
$SAFE = 1
|
||||||
|
DRb.start_service('druby://localhost:0', [1, 2, 'III', 4, "five", 6],
|
||||||
DRb.start_service('druby://localhost:0', [1, 2, 'III', 4, "five", 6])
|
{:safe_level => 1})
|
||||||
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
|
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
|
||||||
DRb.thread.join
|
DRb.thread.join
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user