this fixes issue #20, seriously, no clue how I missed the missing constantize code

This commit is contained in:
Ken Johnson
2013-06-06 16:43:58 -04:00
parent 215bc8614c
commit d445e59a98
2 changed files with 32 additions and 19 deletions
+10 -2
View File
@@ -3,25 +3,32 @@ class BenefitFormsController < ApplicationController
def index
end
def download
begin
file = Rails.root.join('public', 'docs', params[:name])
path = Rails.root.join('public', 'docs', params[:name])
file = params[:type].constantize.new(path)
send_file file, :disposition => 'attachment'
rescue
redirect_to user_benefit_forms_path(:user_id => current_user.user_id)
end
end
=begin
# More secure version
def download
file_assoc = {"1" => "Health_n_Stuff.pdf", "2" => "Dental_n_Stuff.pdf"}
begin
if file_assoc.has_key?(params[:name].to_s)
file = Rails.root.join('public', 'docs', file_assoc[params[:name].to_s])
path = Rails.root.join('public', 'docs', file_assoc[params[:name].to_s])
if params[:type] == "File"
file = params[:type].constantize.new(path)
send_file file, :disposition => 'attachment'
end
else
file = Rails.root.join('public', 'docs', "Dental_n_Stuff.pdf")
send_file file, :disposition => 'attachment'
end
rescue
redirect_to user_benefit_forms_path(:user_id => current_user.user_id)
@@ -29,4 +36,5 @@ class BenefitFormsController < ApplicationController
end
=end
end
@@ -38,7 +38,8 @@
<pre class="ruby">
def download
begin
file = Rails.root.join('public', 'docs', params[:name])
<span style="background-color:yellow">path = Rails.root.join('public', 'docs', params[:name])</span>
<span style="background-color:yellow">file = params[:type].constantize.new(path)</span>
send_file file, :disposition => 'attachment'
rescue
redirect_to user_benefit_forms_path(:user_id => current_user.user_id)
@@ -46,7 +47,7 @@
end
</pre>
<p class="desc">
The location of the file to render is dynamically generated based on user input (params[:name]). This means the user controls the location of the file to be retrieved.
The location of the file to render is dynamically generated based on user input (params[:name]). This means the user controls the location of the file to be retrieved. Additionally, the params[:type] (File) is not validated to make sure it matches up with expected values.
</p>
</div>
</div>
@@ -87,13 +88,17 @@
<pre class="ruby">
# More secure version
def download
file_assoc = {"1" => "Health_n_Stuff.pdf", "2" => "Dental_n_Stuff.pdf"}
<span style="background-color:yellow">file_assoc = {"1" => "Health_n_Stuff.pdf", "2" => "Dental_n_Stuff.pdf"}</span>
begin
if file_assoc.has_key?(params[:name].to_s)
file = Rails.root.join('public', 'docs', file_assoc[params[:name].to_s])
<span style="background-color:yellow">if file_assoc.has_key?(params[:name].to_s)</span>
path = Rails.root.join('public', 'docs', file_assoc[params[:name].to_s])
<span style="background-color:yellow">if params[:type] == "File"</span>
file = params[:type].constantize.new(path)
send_file file, :disposition => 'attachment'
end
else
file = Rails.root.join('public', 'docs', "Dental_n_Stuff.pdf")
send_file file, :disposition => 'attachment'
end
rescue
redirect_to user_benefit_forms_path(:user_id => current_user.user_id)