We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
attach.cgiがうまく動きません。
まずそのまま動かす(「ファイルの添付」ボタンを押す)と、エラーログに以下のように出て怒られます。
AH01215: /home/murashin/public_html/hiki/attach.cgi:9:in `symlink?': Insecure operation: -r (SecurityError), referer: http://localhost/~murashin/hiki/?c=edit;p=FrontPage
適当に__FILE__ → __FILE__.untaintと変更して回ると、次は
__FILE__
__FILE__.untaint
AH01215: : undefined method `read' for ["FrontPage", "FrontPage"]:Array(NoMethodError), referer: http://localhost/~murashin/hiki/?c=edit;p=FrontPage
などと怒られます。
よくわからないのですが、適当にparams['hoge']などとなっているところをparams['hoge'][0]などに変更して回ると、今度は
params['hoge']
params['hoge'][0]
no content body
と言われるようになりました。 この状態でもファイルをアップロードすることはできているようです。
どうするのが正しいのでしょうか?
以下が試した変更です。
--- misc/plugin/attach/attach.cgi 2013-11-06 05:12:30.689109000 +0900 +++ attach.cgi 2013-12-03 22:21:30.408524979 +0900 @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/local/bin/ruby20 # $Id: attach.cgi,v 1.20 2008-01-24 15:42:11 znz Exp $ # Copyright (C) 2003 TAKEUCHI Hitoshi <hitoshi@namaraii.com> @@ -6,10 +6,10 @@ $SAFE = 1 -if FileTest.symlink?( __FILE__ ) then - org_path = File.dirname( File.expand_path( File.readlink( __FILE__ ) ) ) +if FileTest.symlink?( __FILE__.untaint ) then + org_path = File.dirname( File.expand_path( File.readlink( __FILE__.untaint ) ) ) else - org_path = File.dirname( File.expand_path( __FILE__ ) ) + org_path = File.dirname( File.expand_path( __FILE__.untaint ) ) end $:.unshift( org_path.untaint, "#{org_path.untaint}/hiki" ) $:.delete(".") if File.writable?(".") @@ -26,29 +26,28 @@ cgi = CGI.new params = cgi.params - page = params['p'] ? params['p'].read : 'FrontPage' - command = params['command'] ? params['command'].read : 'view' + page = params['p'][0] ? params['p'][0].read : 'FrontPage' + command = params['command'][0] ? params['command'][0].read : 'view' command = 'view' unless ['view', 'edit'].index(command) r = '' max_size = @conf.options['attach_size'] || 1048576 - if cgi.params['attach'] + if cgi.params['attach'][0] begin - raise 'Invalid request.' unless params['p'] && params['attach_file'] - - filename = File.basename(params['attach_file'].original_filename.gsub(/\\/, '/')) + raise 'Invalid request.' unless params['p'][0] && params['attach_file'][0] + filename = File.basename(params['attach_file'][0].original_filename.gsub(/\\/, '/')) cache_path = "#{@conf.cache_path}/attach" Dir.mkdir(cache_path) unless test(?e, cache_path.untaint) attach_path = "#{cache_path}/#{escape(page)}" Dir.mkdir(attach_path) unless test(?e, attach_path.untaint) path = "#{attach_path}/#{escape(filename.to_euc)}" - if params['attach_file'].size > max_size + if params['attach_file'][0].size > max_size raise "File size is larger than limit (#{max_size} bytes)." end unless filename.empty? - content = params['attach_file'].read + content = params['attach_file'][0].read if (!@conf.options['attach.allow_script']) && (/<script\b/i =~ content) raise "You cannot attach a file that contains scripts." else @@ -65,14 +64,14 @@ print cgi.header( 'type' => 'text/plain' ) puts ex.message end - elsif cgi.params['detach'] then + elsif cgi.params['detach'][0] then attach_path = "#{@conf.cache_path}/attach/#{escape(page)}" begin Dir.foreach(attach_path) do |file| - next unless params["file_#{file}"] + next unless params["file_#{file}"][0] path = "#{attach_path}/#{file}" - if FileTest.file?(path.untaint) and params["file_#{file}"].read + if FileTest.file?(path.untaint) and params["file_#{file}"][0].read File.unlink(path) r << "FILE = #{File.basename(path)}\n" end
The text was updated successfully, but these errors were encountered:
正直CGIは捨てたいです。。。 ちゃんとやるなら Hiki::Request と Hiki::Response を使って再実装するのがいいと思いますが、たぶん結構大変です。 あと FILE で相対的にパスを探しているのもよくないので、やめて設定ファイルから読み込めるようにするのがいいと思います。
Sorry, something went wrong.
なるほど、お返事ありがとうございます。
update atom.xml for Rubyist Magazine hiki#51 issue release
1cb39c7
No branches or pull requests
attach.cgiがうまく動きません。
まずそのまま動かす(「ファイルの添付」ボタンを押す)と、エラーログに以下のように出て怒られます。
適当に
__FILE__
→__FILE__.untaint
と変更して回ると、次はなどと怒られます。
よくわからないのですが、適当に
params['hoge']
などとなっているところをparams['hoge'][0]
などに変更して回ると、今度はと言われるようになりました。
この状態でもファイルをアップロードすることはできているようです。
どうするのが正しいのでしょうか?
以下が試した変更です。
The text was updated successfully, but these errors were encountered: