Project

General

Profile

Actions

Bug #5279

closed

$SAFEが3以上の時にString#encodeがSecurityErrorを発生させるケースがある

Added by sorah (Sorah Fukumori) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
-
Backport:
[ruby-dev:44469]

Description

sora_hです.

twitter
@hsbt (Hiroshi SHIBATA) さんがこのような事を言っていたので調査してみました:
http://twitter.com/#!/hsbt/status/110700488667832320

調査したところ,どうやらString#encodeは内部的にrequireしていて,
セーフレベル3から全てのオブジェクトが汚染されるので,rb_require_safeに渡るStringが汚染されるため,
rb_requireでSecurityErrorが発生します.

なので,以下の場合はSecurityErrorが発生しますが,

$SAFE = 3
"a".encode("UTF-16")

以下の場合は発生しません.

"a".encode("UTF-16")
$SAFE = 3
"a".encode("UTF-16")

これを修正するパッチを書いてみましたが(チケット末尾に貼り付け),
果たしてrb_require_safeの第二引数に0を渡しても問題ないのか自信がありません.
これはセキュリティ周りの問題なので,合意を取ってからコミット,もしくはパッチに
含む問題を修正し合意が取れてからコミットしようと思います.

以下patch

diff --git a/ChangeLog b/ChangeLog
index a16e823..07f76a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Sep 6 08:56:06 2011 Shota Fukumori
+

  •   * transcode.c: Use rb_require_safe() to load transcoder.
    
  •     Because if $SAFE is higher than 3, rb_require() raises SecurityError.
    

Mon Sep 5 20:59:30 2011 CHIKANAGA Tomoyuki

    * insns.def: change encoding pragma for emacs (shift_jis to utf-8).

diff --git a/transcode.c b/transcode.c
index 2c188b6..0651aec 100644
--- a/transcode.c
+++ b/transcode.c
@@ -375,7 +375,7 @@ load_transcoder_entry(transcoder_entry_t *entry)
return NULL;
memcpy(path, transcoder_lib_prefix, sizeof(transcoder_lib_prefix) - 1);
memcpy(path + sizeof(transcoder_lib_prefix) - 1, lib, len + 1);

  •    if (!rb_require(path))
    
  •    if (!rb_require_safe(rb_str_new2(path), 0))
           return NULL;
    
    }

Related issues 1 (0 open1 closed)

Has duplicate Backport193 - Backport #5564: 1.9.3 regression with encoding conversionClosedyugui (Yuki Sonoda)11/04/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0