[Hiki-dev:00748] attach_anchor で作られるリンクを JavaScript で削除

Zurück zum Archiv-Index

KOMATSU Shinichiro koma2****@lovep*****
2005年 5月 22日 (日) 23:18:38 JST


小松です。

「ファイル添付機能の脆弱性」への対策ですが、
そもそも JavaScript が無効なら危険はないわけなので、
JavaScript を使って attach_anchor で作られてるリンクを
削除してしまうというのはいかがでしょう?
# 「毒をもって毒を制す」ってやつです。;)

[Hiki-dev:00747] に書いたように、
入口でチェックして script 入りのファイルを拒否するというのが
一番有効だとは思うのですが、
運用上それが出来ないこともあると思うので、
次善の策としてこういう手もあるかと思います。

ただ、patch を見ていただければわかるように、
template 自体に手を入れてしまっているので、
このまま commit するわけにはいかないと思いますが・・・。

-- 
┏━━━━━━━━━━━━━━━━━━━━━━┓
                小松  晋一朗            
             koma2****@lovep*****
     http://bloghome.lovepeers.org/daymemo2/
┗━━━━━━━━━━━━━━━━━━━━━━┛
-------------- next part --------------
Index: misc/plugin/attach/attach.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/misc/plugin/attach/attach.rb,v
retrieving revision 1.18
diff -u -r1.18 attach.rb
--- misc/plugin/attach/attach.rb	21 May 2005 07:57:02 -0000	1.18
+++ misc/plugin/attach/attach.rb	22 May 2005 13:54:43 -0000
@@ -198,6 +198,40 @@
   s
 end
 
+def attach_deny_browser_script
+  deny_browser = @options['attach.deny_browser_re'] || \
+		 '/(Internet\s*Exploror|Konqueror)/'
+
+  <<-"EndOfScript"
+<script type="text/javascript">
+<!--
+  function hideLink() {
+    if (navigator.appName.search(#{deny_browser}) != -1) {
+      atag = document.getElementsByTagName('a');
+      for (var i=0; i<atag.length; ++i) {
+	if ( (attr = atag[i].getAttribute('href')) && (attr.indexOf(';plugin=attach_download;') != -1) ) {
+	  //atag[i].removeAttribute('href');
+	  atag[i].setAttribute('href', 'javascript:showAlert()');
+	  //atag[i].setAttribute('onClick', 'showAlert()');
+	}
+      }
+    }
+  }
+
+  function showAlert() {
+    alert('You are using dangerous browser, and should not show this link unless you turn off JavaScript.');
+  }
+//-->
+</script>
+EndOfScript
+end
+
+add_header_proc {
+  begin
+    attach_deny_browser_script if @options['attach.deny_browser_enable']
+  rescue Exception
+  end
+}
 
 add_body_leave_proc {
   begin
Index: template/view.html
===================================================================
RCS file: /cvsroot/hiki/hiki/template/view.html,v
retrieving revision 1.5
diff -u -r1.5 view.html
--- template/view.html	22 Apr 2005 01:22:31 -0000	1.5
+++ template/view.html	22 May 2005 13:54:43 -0000
@@ -6,7 +6,7 @@
 <%= @contents[:header] %>
 </head>
 
-<body>
+<body onload=hideLink()>
 <a name="top"> </a>
 <div class="<%= @contents[:view_style] %>">
   <div class="adminmenu"><%= @contents[:tools] %></div>


Hiki-dev メーリングリストの案内
Zurück zum Archiv-Index