code
stringlengths 12
2.05k
| label_name
stringlengths 6
8
| label
int64 0
95
|
---|---|---|
def include_allowed?(target, reader)
doc = reader.document
return false if doc.safe >= ::Asciidoctor::SafeMode::SECURE
return false if doc.attributes.fetch('max-include-depth', 64).to_i < 1
return false if target_uri?(target) && !doc.attributes.key?('allow-uri-read')
true
end | CWE-78 | 6 |
def validate_each(record, attribute, value)
adapter = Paperclip.io_adapters.for(value)
if Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename).spoofed?
record.errors.add(attribute, :spoofed_media_type)
end
end | CWE-79 | 1 |
def self.get_copies_folder(user_id)
my_folder = User.get_my_folder(user_id)
unless my_folder.nil?
con = "(parent_id=#{my_folder.id}) and (name='#{Item.copies_folder}')"
begin
copies_folder = Folder.where(con).first
rescue
end
if copies_folder.nil?
folder = Folder.new
folder.name = Item.copies_folder
folder.parent_id = my_folder.id
folder.owner_id = user_id.to_i
folder.xtype = nil
folder.read_users = '|' + user_id.to_s + '|'
folder.write_users = '|' + user_id.to_s + '|'
folder.save!
copies_folder = folder
end
end
return copies_folder
end | CWE-89 | 0 |
def verify_signature(string, signature)
if signature.nil?
fail InvalidSignature, "missing \"signature\" param"
elsif signature != generate_signature(string)
fail InvalidSignature, "provided signature does not match the calculated signature"
end
end | CWE-203 | 38 |
def create
Log.add_info(request, params.inspect)
if params[:thetisBoxEdit].nil? or params[:thetisBoxEdit].empty?
@group = nil
else
@group = Group.new
@group.name = params[:thetisBoxEdit]
@group.parent_id = params[:selectedGroupId]
@group.save!
@group.create_group_folder
end
render(:partial => 'ajax_group_entry', :layout => false)
end | CWE-89 | 0 |
def test_execute_details_cleans_text
spec_fetcher do |fetcher|
fetcher.spec 'a', 2 do |s|
s.summary = 'This is a lot of text. ' * 4
s.authors = ["Abraham Lincoln \u0001", "\u0002 Hirohito"]
s.homepage = "http://a.example.com/\u0003"
end
fetcher.legacy_platform
end
@cmd.handle_options %w[-r -d]
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
*** REMOTE GEMS ***
a (2)
Authors: Abraham Lincoln ., . Hirohito
Homepage: http://a.example.com/.
This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text.
pl (1)
Platform: i386-linux
Author: A User
Homepage: http://example.com
this is a summary
EOF
assert_equal expected, @ui.output
assert_equal '', @ui.error
end | CWE-94 | 14 |
def team_organize
Log.add_info(request, params.inspect)
team_id = params[:team_id]
unless team_id.blank?
begin
@team = Team.find(team_id)
rescue
@team = nil
ensure
if @team.nil?
flash[:notice] = t('msg.already_deleted', :name => Team.model_name.human)
return
end
end
users = @team.get_users_a
end
team_members = params[:team_members]
created = false
modified = false
if team_members.nil? or team_members.empty?
unless team_id.blank?
# @team must not be nil.
@team.save if modified = @team.clear_users
end
else
if team_members != users
if team_id.blank?
item = Item.find(params[:id])
created = true
@team = Team.new
@team.name = item.title
@team.item_id = params[:id]
@team.status = Team::STATUS_STANDBY
else
@team.clear_users
end
@team.add_users team_members
@team.save
@team.remove_application team_members
modified = true
end
end
if created
@team.create_team_folder
end
@item = @team.item
if modified
flash[:notice] = t('msg.register_success')
end
render(:partial => 'ajax_team_info', :layout => false)
rescue => evar
Log.add_error(request, evar)
render(:partial => 'ajax_team_info', :layout => false)
end | CWE-89 | 0 |
def verify_signature(jwt)
head = token_head(jwt)
# Make sure the algorithm is supported and get the decode key.
if head[:alg] == 'RS256'
[rs256_decode_key(head[:kid]), head[:alg]]
elsif head[:alg] == 'HS256'
[@client_secret, head[:alg]]
else
raise OmniAuth::Auth0::TokenValidationError.new("Signature algorithm of #{head[:alg]} is not supported. Expected the ID token to be signed with RS256 or HS256")
end
end | CWE-347 | 25 |
def update_by_ajax
Log.add_info(request, params.inspect)
cat_h = {:desktop => User::AUTH_DESKTOP, :user => User::AUTH_USER, :log => User::AUTH_LOG}
yaml = ApplicationHelper.get_config_yaml
cat_h.keys.each do |cat|
next if params[cat].nil? or params[cat].empty?
unless @login_user.admin?(cat_h[cat])
render(:text => t('msg.need_to_be_admin'))
return
end
yaml[cat] ||= {}
params[cat].each do |key, val|
yaml[cat][key] = val
end
end
ApplicationHelper.save_config_yaml(yaml)
render(:text => '')
end | CWE-89 | 0 |
def html_postprocess(_field, html)
helper = ContentTextHelpers.new
helper.sanitize(helper.auto_link(html))
end | CWE-94 | 14 |
def get_auth_teams
Log.add_info(request, params.inspect)
begin
@folder = Folder.find(params[:id])
rescue
@folder = nil
end
target_user_id = (@login_user.admin?(User::AUTH_TEAM))?(nil):(@login_user.id)
@teams = Team.get_for(target_user_id, true)
session[:folder_id] = params[:id]
render(:partial => 'ajax_auth_teams', :layout => false)
end | CWE-89 | 0 |
def setup
@namespace = "theplaylist"
@store = Redis::Store.new :namespace => @namespace, :marshalling => false # TODO remove mashalling option
@client = @store.instance_variable_get(:@client)
@rabbit = "bunny"
@default_store = Redis::Store.new
@other_namespace = 'other'
@other_store = Redis::Store.new :namespace => @other_namespace
end | CWE-502 | 15 |
def test_should_allow_anchors
assert_sanitized %(<a href="foo" onclick="bar"><script>baz</script></a>), %(<a href=\"foo\"></a>)
end
def test_video_poster_sanitization
assert_sanitized %(<video src="videofile.ogg" autoplay poster="posterimage.jpg"></video>), %(<video src="videofile.ogg" poster="posterimage.jpg"></video>)
assert_sanitized %(<video src="videofile.ogg" poster=javascript:alert(1)></video>), %(<video src="videofile.ogg"></video>)
end
# RFC 3986, sec 4.2
def test_allow_colons_in_path_component
assert_sanitized "<a href=\"./this:that\">foo</a>"
end | CWE-79 | 1 |
def self.from(stream)
header = stream.read 512
empty = (header == "\0" * 512)
fields = header.unpack UNPACK_FORMAT
new :name => fields.shift,
:mode => fields.shift.oct,
:uid => fields.shift.oct,
:gid => fields.shift.oct,
:size => fields.shift.oct,
:mtime => fields.shift.oct,
:checksum => fields.shift.oct,
:typeflag => fields.shift,
:linkname => fields.shift,
:magic => fields.shift,
:version => fields.shift.oct,
:uname => fields.shift,
:gname => fields.shift,
:devmajor => fields.shift.oct,
:devminor => fields.shift.oct,
:prefix => fields.shift,
:empty => empty
end | CWE-835 | 42 |
def check_owner
return if params[:id].nil? or params[:id].empty? or @login_user.nil?
email = Email.find(params[:id])
if !@login_user.admin?(User::AUTH_MAIL) and email.user_id != @login_user.id
Log.add_check(request, '[check_owner]'+request.to_s)
flash[:notice] = t('msg.need_to_be_owner')
redirect_to(:controller => 'desktop', :action => 'show')
end
end | CWE-89 | 0 |
def show
Log.add_info(request, params.inspect)
@group_id = params[:group_id]
official_title_id = params[:id]
unless official_title_id.nil? or official_title_id.empty?
@official_title = OfficialTitle.find(official_title_id)
end
render(:layout => (!request.xhr?))
end | CWE-89 | 0 |
it 'is possible to return hash errors in jsonapi format' do
get '/'
expect(['{"error":"rain!","detail":"missing widget"}',
'{"detail":"missing widget","error":"rain!"}']).to include(last_response.body)
end | CWE-79 | 1 |
it "handles Symbol keys" do
cl = subject.build_command_line("true", :abc => "def")
expect(cl).to eq "true --abc def"
end | CWE-78 | 6 |
def index
valid_http_methods :get, :post, :put
# for permission check
if params[:package] and not ["_repository", "_jobhistory"].include?(params[:package])
pkg = DbPackage.get_by_project_and_name( params[:project], params[:package], use_source=false )
else
prj = DbProject.get_by_name params[:project]
end
pass_to_backend
end | CWE-434 | 5 |
def calculated_media_type
@calculated_media_type ||= calculated_content_type.split("/").first
end | CWE-79 | 1 |
def properly_encode(fragment, options)
fragment.xml? ? fragment.to_xml(options) : fragment.to_html(options)
end | CWE-79 | 1 |
def comment_link(uniqueid, data)
comment = comment_for_type(data)
i18n_key = data[:cutoff] ? 'truncated' : 'full'
notification = t(
"notifications.comment.#{i18n_key}",
name: data[:user],
comment: strip_tags(data[:comment]),
typename: data[:typename]
)
notification_link(uniqueid, comment[:path], notification)
end | CWE-79 | 1 |
def deliver!(mail)
if ::File.respond_to?(:makedirs)
::File.makedirs settings[:location]
else
::FileUtils.mkdir_p settings[:location]
end
mail.destinations.uniq.each do |to|
::File.open(::File.join(settings[:location], to), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
end
end | CWE-22 | 2 |
it "handles Symbol keys with underscore and tailing '='" do
cl = subject.build_command_line("true", :abc_def= => "ghi")
expect(cl).to eq "true --abc-def=ghi"
end | CWE-78 | 6 |
def set_auth_teams
Log.add_info(request, params.inspect)
@folder = Folder.find(params[:id])
if Folder.check_user_auth(@folder.id, @login_user, 'w', true)
read_teams = []
write_teams = []
teams_auth = params[:teams_auth]
unless teams_auth.nil?
teams_auth.each do |auth_param|
user_id = auth_param.split(':').first
auths = auth_param.split(':').last.split('+')
if auths.include?('r')
read_teams << user_id
end
if auths.include?('w')
write_teams << user_id
end
end
end
@folder.set_read_teams read_teams
@folder.set_write_teams write_teams
@folder.save
flash[:notice] = t('msg.register_success')
else
flash[:notice] = 'ERROR:' + t('folder.need_auth_to_modify')
end
target_user_id = (@login_user.admin?(User::AUTH_TEAM))?(nil):(@login_user.id)
@teams = Team.get_for(target_user_id, true)
render(:partial => 'ajax_auth_teams', :layout => false)
rescue => evar
Log.add_error(request, evar)
render(:partial => 'ajax_auth_teams', :layout => false)
end | CWE-89 | 0 |
def filename_from_header
return nil unless file.meta.include? 'content-disposition'
match = file.meta['content-disposition'].match(/filename=(?:"([^"]+)"|([^";]+))/)
return nil unless match
match[1].presence || match[2].presence
end | CWE-918 | 16 |
def check_owner
return if (params[:id].nil? or params[:id].empty? or @login_user.nil?)
address = Address.find(params[:id])
if !@login_user.admin?(User::AUTH_ADDRESSBOOK) and address.owner_id != @login_user.id
Log.add_check(request, '[check_owner]'+request.to_s)
flash[:notice] = t('msg.need_to_be_owner')
redirect_to(:controller => 'desktop', :action => 'show')
end
end | CWE-89 | 0 |
def make_rs256_token(payload = nil)
payload = { sub: 'abc123' } if payload.nil?
JWT.encode payload, rsa_private_key, 'RS256', kid: jwks_kid
end | CWE-347 | 25 |
def remove_application(users)
return if users.nil? or users.empty?
array = ["(xtype='#{Comment::XTYPE_APPLY}')"]
array << "(item_id=#{self.item_id})"
user_con_a = []
users.each do |user_id|
user_con_a << "(user_id=#{user_id})"
end
array << '(' + user_con_a.join(' or ') + ')'
Comment.destroy_all(array.join(' and '))
end | CWE-89 | 0 |
it "returns default error message for spoofed media type" do
build_validator
file = File.new(fixture_file("5k.png"), "rb")
@dummy.avatar.assign(file)
detector = mock("detector", :spoofed? => true)
Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(detector)
@validator.validate(@dummy)
assert_equal "has an extension that does not match its contents", @dummy.errors[:avatar].first
end | CWE-79 | 1 |
def self.open(path_or_url, ext = nil, options = {})
options, ext = ext, nil if ext.is_a?(Hash)
ext ||=
if File.exist?(path_or_url)
File.extname(path_or_url)
else
File.extname(URI(path_or_url).path)
end
ext.sub!(/:.*/, '') # hack for filenames or URLs that include a colon
Kernel.open(path_or_url, "rb", options) do |file|
read(file, ext)
end
end | CWE-78 | 6 |
def self.exists_copies_folder?(user_id)
my_folder = User.get_my_folder(user_id)
unless my_folder.nil?
con = "(parent_id=#{my_folder.id}) and (name='#{Item.copies_folder}')"
begin
copies_folder = Folder.where(con).first
rescue
end
end
return !copies_folder.nil?
end | CWE-89 | 0 |
def get_group_equipment
Log.add_info(request, params.inspect)
@group_id = nil
if !params[:thetisBoxSelKeeper].nil?
@group_id = params[:thetisBoxSelKeeper].split(':').last
elsif !params[:group_id].nil? and !params[:group_id].empty?
@group_id = params[:group_id]
end
submit_url = url_for(:controller => 'schedules', :action => 'get_group_equipment')
render(:partial => 'common/select_equipment', :layout => false, :locals => {:target_attr => :id, :submit_url => submit_url})
end | CWE-89 | 0 |
def self.execute_action_move(mail_filter, email, val)
mail_folder_id = val
mail_folder = MailFolder.find_by_id(mail_folder_id)
if !mail_folder.nil? and (mail_folder.user_id == email.user_id)
email.update_attribute(:mail_folder_id, mail_folder_id)
end
return true
end | CWE-89 | 0 |
it 'sets file extension based on content-type if missing' do
expect(subject.original_filename).to eq "test.jpeg"
end | CWE-918 | 16 |
def self.using(file, name)
new(file, name)
end | CWE-79 | 1 |
def accepts?(env)
session = session env
token = session[:csrf] ||= session['_csrf_token'] || random_string
safe?(env) ||
env['HTTP_X_CSRF_TOKEN'] == token ||
Request.new(env).params[options[:authenticity_param]] == token
end | CWE-203 | 38 |
def self.destroy_by_user(user_id, add_con=nil)
SqlHelper.validate_token([user_id])
con = "user_id=#{user_id}"
con << " and (#{add_con})" unless add_con.nil? or add_con.empty?
emails = Email.where(con).to_a
emails.each do |email|
email.destroy
end
end | CWE-89 | 0 |
def sanitize(html, options = {})
return unless html
return html if html.empty?
Loofah.fragment(html).tap do |fragment|
remove_xpaths(fragment, XPATHS_TO_REMOVE)
end.text(options)
end | CWE-79 | 1 |
it 'should return nil if the key ID is invalid' do
expect(jwt_validator.jwks_key(:alg, "#{jwks_kid}_invalid")).to eq(nil)
end | CWE-347 | 25 |
it 'returns all campaigns belonging to the inbox to administrators' do
# create a random campaign
create(:campaign, account: account)
get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/campaigns",
headers: administrator.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
body = JSON.parse(response.body, symbolize_names: true)
expect(body.first[:id]).to eq(campaign.display_id)
expect(body.length).to eq(1)
end | CWE-79 | 1 |
def format_object(object, html=true, &block)
if block_given?
object = yield object
end
case object.class.name
when 'Array'
object.map {|o| format_object(o, html)}.join(', ').html_safe
when 'Time'
format_time(object)
when 'Date'
format_date(object)
when 'Fixnum'
object.to_s
when 'Float'
sprintf "%.2f", object
when 'User'
html ? link_to_user(object) : object.to_s
when 'Project'
html ? link_to_project(object) : object.to_s
when 'Version'
html ? link_to_version(object) : object.to_s
when 'TrueClass'
l(:general_text_Yes)
when 'FalseClass'
l(:general_text_No)
when 'Issue'
object.visible? && html ? link_to_issue(object) : "##{object.id}"
when 'Attachment'
html ? link_to_attachment(object) : object.filename
when 'CustomValue', 'CustomFieldValue'
if object.custom_field
f = object.custom_field.format.formatted_custom_value(self, object, html)
if f.nil? || f.is_a?(String)
f
else
format_object(f, html, &block)
end
else
object.value.to_s
end
else
html ? h(object) : object.to_s
end | CWE-79 | 1 |
def html_message
key = keys.last.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
%(<span class="translation_missing" title="translation missing: #{keys.join('.')}">#{key}</span>) | CWE-79 | 1 |
def unfolded_header
@unfolded_header ||= unfold(raw_source)
end | CWE-93 | 33 |
def self.destroy_by_user(user_id, add_con=nil)
SqlHelper.validate_token([user_id])
con = "user_id=#{user_id}"
con << " and (#{add_con})" unless add_con.nil? or add_con.empty?
mail_accounts = MailAccount.where(con).to_a
mail_accounts.each do |mail_account|
mail_account.destroy
end
end | CWE-89 | 0 |
it 'supports passing read options to RMagick' do
expect_any_instance_of(::Magick::Image::Info).to receive(:density=).with(10)
expect_any_instance_of(::Magick::Image::Info).to receive(:size=).with("200x200")
instance.manipulate! :read => {
:density => 10,
:size => %{"200x200"}
}
end | CWE-94 | 14 |
it "sanitizes Fixnum array param value" do
cl = subject.build_command_line("true", nil => [1])
expect(cl).to eq "true 1"
end | CWE-78 | 6 |
def get_group_users
Log.add_info(request, params.inspect)
@group_id = nil
if !params[:thetisBoxSelKeeper].nil?
@group_id = params[:thetisBoxSelKeeper].split(':').last
elsif !params[:group_id].nil? and !params[:group_id].empty?
@group_id = params[:group_id]
end
submit_url = url_for(:controller => 'desktop', :action => 'get_group_users')
render(:partial => 'common/select_users', :layout => false, :locals => {:target_attr => :id, :submit_url => submit_url})
end | CWE-89 | 0 |
def split_header
self.fields = unfolded_header.split(CRLF)
end | CWE-93 | 33 |
it "converts the comment markup to HTML" do
expect(comment.generate_html(:body)).to match(%r{<em>italic</em>})
expect(comment.generate_html(:body)).to match(%r{<strong>bold</strong>})
end | CWE-79 | 1 |
def new_ally_request_link(uniqueid, data)
link = "/profile?uid=#{data[:uid]}"
link_html = "<a href=\"#{link}\">#{data[:user]}</a>"
# rubocop:disable Layout/LineLength
"<div id=\"#{uniqueid}\"><div>#{t('notifications.ally.sent_html', link_to_user: link_html)}</div>#{request_actions(data[:user_id])}</div>"
# rubocop:enable Layout/LineLength
end | CWE-79 | 1 |
def target_uri?(target)
::Asciidoctor::Helpers.uriish?(target)
end | CWE-78 | 6 |
it 'should return an x5c key' do
expect(jwt_validator.jwks_key(:x5c, jwks_kid).length).to eq(1)
end | CWE-347 | 25 |
def file_list io # :nodoc:
header = String.new
read_until_dashes io do |line|
header << line
end
YAML.load header
end | CWE-502 | 15 |
def do_execute
Log.add_info(request, params.inspect)
mail_account = MailAccount.find_by_id(params[:mail_account_id])
mail_folder = MailFolder.find_by_id(params[:mail_folder_id])
if mail_account.user_id != @login_user.id \
or mail_folder.user_id != @login_user.id
render(:text => t('msg.need_to_be_owner'))
return
end
mail_filters = MailFilter.get_for(mail_account.id, true, MailFilter::TRIGGER_MANUAL)
emails = MailFolder.get_mails(mail_folder.id, mail_folder.user_id)
filter_next = true
emails.each do |email|
mail_filters.each do |filter|
filter_next = filter.execute(email)
break unless filter_next
end
break unless filter_next
end
render(:text => '')
end | CWE-89 | 0 |
def rename_title
Log.add_info(request, params.inspect)
org_title = params[:org_title]
new_title = params[:new_title]
if org_title.nil? or new_title.nil? or org_title == new_title
render(:partial => 'ajax_title', :layout => false)
return
end
titles = User.get_config_titles
unless titles.nil?
if titles.include?(new_title)
flash[:notice] = 'ERROR:' + t('user.title_duplicated')
else
idx = titles.index(org_title)
unless idx.nil?
titles[idx] = new_title
User.save_config_titles titles
User.rename_title(org_title, new_title)
User.update_xorder(new_title, idx)
end
end
end
render(:partial => 'ajax_title', :layout => false)
end | CWE-89 | 0 |
def stub_dummy_jwks
stub_request(:get, 'https://example.org/.well-known/jwks.json')
.to_return(
headers: { 'Content-Type' => 'application/json' },
body: rsa_token_jwks,
status: 200
)
end | CWE-347 | 25 |
it 'should escape the content of removed `plaintext` elements' do
Sanitize.fragment('<plaintext>hello! <script>alert(0)</script>')
.must_equal 'hello! <script>alert(0)</script>'
end | CWE-79 | 1 |
def sanitize_string(host)
if host.start_with?(".")
/\A(.+\.)?#{Regexp.escape(host[1..-1])}\z/i
else
/\A#{Regexp.escape host}\z/i
end
end | CWE-601 | 11 |
def paginate_by_sql(model, sql, per_page, options={})
if options[:count]
if options[:count].is_a?(Integer)
total = options[:count]
else
total = model.count_by_sql(options[:count])
end
else
total = model.count_by_sql_wrapping_select_query(sql)
end
object_pages = model.paginate_by_sql(sql, {:page => params['page'], :per_page => per_page})
#objects = model.find_by_sql_with_limit(sql, object_pages.current.to_sql[1], per_page)
return [object_pages, object_pages, total]
end | CWE-89 | 0 |
def team_organize
Log.add_info(request, params.inspect)
team_id = params[:team_id]
unless team_id.blank?
begin
@team = Team.find(team_id)
rescue
@team = nil
ensure
if @team.nil?
flash[:notice] = t('msg.already_deleted', :name => Team.model_name.human)
return
end
end
users = @team.get_users_a
end
team_members = params[:team_members]
SqlHelper.validate_token([team_members])
created = false
modified = false
if team_members.nil? or team_members.empty?
unless team_id.blank?
# @team must not be nil.
@team.save if modified = @team.clear_users
end
else
if team_members != users
if team_id.blank?
item = Item.find(params[:id])
created = true
@team = Team.new
@team.name = item.title
@team.item_id = params[:id]
@team.status = Team::STATUS_STANDBY
else
@team.clear_users
end
@team.add_users(team_members)
@team.save
@team.remove_application(team_members)
modified = true
end
end
if created
@team.create_team_folder
end
@item = @team.item
if modified
flash[:notice] = t('msg.register_success')
end
render(:partial => 'ajax_team_info', :layout => false)
rescue => evar
Log.add_error(request, evar)
render(:partial => 'ajax_team_info', :layout => false)
end | CWE-89 | 0 |
def test_sanitize_script
assert_sanitized "a b c<script language=\"Javascript\">blah blah blah</script>d e f", "a b cd e f"
end | CWE-79 | 1 |
def create
Log.add_info(request, params.inspect)
parent_id = params[:selectedFolderId]
unless Folder.check_user_auth(parent_id, @login_user, 'w', true)
flash[:notice] = 'ERROR:' + t('folder.need_auth_to_modify')
render(:partial => 'ajax_folder_entry', :layout => false)
return
end
if params[:thetisBoxEdit].nil? or params[:thetisBoxEdit].empty?
@folder = nil
else
@folder = Folder.new
@folder.name = params[:thetisBoxEdit]
@folder.xorder = Folder.get_order_max(parent_id) + 1
@folder.parent_id = parent_id
@folder.inherit_parent_auth
@folder.save!
end
render(:partial => 'ajax_folder_entry', :layout => false)
end | CWE-89 | 0 |
def meeting_link(uniqueid, data)
notification = t(
"notifications.meeting.#{data[:type]}",
name: data[:user],
group_name: data[:group],
meeting_name: data[:typename]
)
link = specific_meeting_link(data[:type], data[:typeid], data[:group_id])
notification_link(uniqueid, link, notification)
end | CWE-79 | 1 |
def _process_user_attrs(user, attrs)
if attrs[:birthday].nil?
begin
attrs[:birthday] = attrs[:birthday_y] + '-' + attrs[:birthday_m] + '-' + attrs[:birthday_d]
rescue
end
attrs.delete(:birthday_y)
attrs.delete(:birthday_m)
attrs.delete(:birthday_d)
end
if !attrs[:name].nil? or !attrs[:password].nil?
user_name = attrs[:name]
user_name ||= user.name unless user.nil?
password = attrs[:password]
if password.nil? or password.empty?
password = UsersHelper.generate_password
attrs[:password] = password
end
attrs[:pass_md5] = UsersHelper.generate_digest_pass(user_name, password)
end
return attrs
end | CWE-89 | 0 |
def unfold(string)
string.gsub(/#{CRLF}#{WSP}+/, ' ').gsub(/#{WSP}+/, ' ')
end | CWE-93 | 33 |
def activity_user
user = current_user.pref[:activity_user]
if user && user != "all_users"
user = if user =~ /@/ # email
User.where(:email => user).first
else # first_name middle_name last_name any_name
name_query = if user.include?(" ")
user.name_permutations.map{ |first, last|
"(upper(first_name) LIKE upper('%#{first}%') AND upper(last_name) LIKE upper('%#{last}%'))"
}.join(" OR ")
else
"upper(first_name) LIKE upper('%#{user}%') OR upper(last_name) LIKE upper('%#{user}%')"
end
User.where(name_query).first
end | CWE-89 | 0 |
def html_postprocess(_field, html)
html
end | CWE-79 | 1 |
def setup
@store = Redis::Store.new :marshalling => true
@rabbit = OpenStruct.new :name => "bunny"
@white_rabbit = OpenStruct.new :color => "white"
@store.set "rabbit", @rabbit
@store.del "rabbit2"
end | CWE-502 | 15 |
def self.save_group_value(group_id, category, key, value)
SqlHelper.validate_token([group_id, category, key])
con = []
con << "(group_id=#{group_id})"
con << "(category='#{category}')"
con << "(xkey='#{key}')"
setting = Setting.where(con.join(' and ')).first
if value.nil?
unless setting.nil?
setting.destroy
end
else
if setting.nil?
setting = Setting.new
setting.group_id = group_id
setting.category = category
setting.xkey = key
setting.xvalue = value
setting.save!
else
setting.update_attribute(:xvalue, value)
end
end
end | CWE-89 | 0 |
it "with params as nil" do
cl = subject.build_command_line("true", nil)
expect(cl).to eq "true"
end | CWE-78 | 6 |
def send_password
Log.add_info(request, params.inspect)
mail_addr = params[:thetisBoxEdit]
SqlHelper.validate_token([mail_addr], ['@-'])
begin
users = User.where("email='#{mail_addr}'").to_a
rescue => evar
end
if users.nil? or users.empty?
Log.add_error(request, evar)
flash[:notice] = 'ERROR:' + t('email.address_not_found')
else
user_passwords_h = {}
users.each do |user|
newpass = UsersHelper.generate_password
user.update_attribute(:pass_md5, UsersHelper.generate_digest_pass(user.name, newpass))
user_passwords_h[user] = newpass
end
NoticeMailer.password(user_passwords_h, ApplicationHelper.root_url(request)).deliver;
flash[:notice] = t('email.sent')
end
render(:controller => 'login', :action => 'index')
end | CWE-89 | 0 |
def quote_column_name(name) #:nodoc:
@quoted_column_names[name] ||= "`#{name}`"
end | CWE-89 | 0 |
def ffi_lib(*names)
raise LoadError.new("library names list must not be empty") if names.empty?
lib_flags = defined?(@ffi_lib_flags) ? @ffi_lib_flags : FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL
ffi_libs = names.map do |name|
if name == FFI::CURRENT_PROCESS
FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)
else
libnames = (name.is_a?(::Array) ? name : [ name ]).map(&:to_s).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
lib = nil
errors = {}
libnames.each do |libname|
begin
orig = libname
lib = FFI::DynamicLibrary.open(libname, lib_flags)
break if lib
rescue Exception => ex
ldscript = false
if ex.message =~ /(([^ \t()])+\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short|invalid file format)/
if File.read($1) =~ /(?:GROUP|INPUT) *\( *([^ \)]+)/
libname = $1
ldscript = true
end
end
if ldscript
retry
else
# TODO better library lookup logic
unless libname.start_with?("/")
path = ['/usr/lib/','/usr/local/lib/'].find do |pth|
File.exist?(pth + libname)
end
if path
libname = path + libname
retry
end
end
libr = (orig == libname ? orig : "#{orig} #{libname}")
errors[libr] = ex
end
end
end
if lib.nil?
raise LoadError.new(errors.values.join(".\n"))
end
# return the found lib
lib
end
end
@ffi_libs = ffi_libs
end | CWE-426 | 70 |
def authenticate(*credentials, &block)
raise ArgumentError, 'at least 2 arguments required' if credentials.size < 2
if credentials[0].blank?
return authentication_response(return_value: false, failure: :invalid_login, &block)
end
if @sorcery_config.downcase_username_before_authenticating
credentials[0].downcase!
end
user = sorcery_adapter.find_by_credentials(credentials)
unless user
return authentication_response(failure: :invalid_login, &block)
end
set_encryption_attributes
unless user.valid_password?(credentials[1])
return authentication_response(user: user, failure: :invalid_password, &block)
end
if user.respond_to?(:active_for_authentication?) && !user.active_for_authentication?
return authentication_response(user: user, failure: :inactive, &block)
end
@sorcery_config.before_authenticate.each do |callback|
success, reason = user.send(callback)
unless success
return authentication_response(user: user, failure: reason, &block)
end
end
authentication_response(user: user, return_value: user, &block)
end | CWE-307 | 26 |
def accepted_ally_link(uniqueid, data)
notification = t(
'notifications.ally.accepted',
name: data[:user]
)
link = "/profile?uid=#{data[:uid]}"
notification_link(uniqueid, link, notification)
end | CWE-79 | 1 |
def build_command_line(command, params = nil)
return command.to_s if params.nil? || params.empty?
"#{command} #{assemble_params(sanitize(params))}"
end | CWE-78 | 6 |
def self.get_for_group(group_id, category=nil)
SqlHelper.validate_token([group_id, category])
con = []
con << "(group_id=#{group_id})"
con << "(category='#{category}')" unless category.nil?
settings = Setting.where(con.join(' and ')).to_a
return nil if settings.nil? or settings.empty?
hash = Hash.new
settings.each do |setting|
hash[setting.xkey] = setting.xvalue
end
return hash
end | CWE-89 | 0 |
def destroy
Log.add_info(request, params.inspect)
if params[:check_user].nil?
list
render(:action => 'list')
return
end
count = 0
params[:check_user].each do |user_id, value|
if value == '1'
begin
User.destroy(user_id)
rescue => evar
Log.add_error(request, evar)
end
count += 1
end
end
flash[:notice] = count.to_s + t('user.deleted')
redirect_to(:action => 'list')
end | CWE-89 | 0 |
def cama_current_user
return @cama_current_user if defined?(@cama_current_user)
# api current user...
@cama_current_user = cama_calc_api_current_user
return @cama_current_user if @cama_current_user
return nil unless cookies[:auth_token].present?
c = cookies[:auth_token].split("&")
return nil unless c.size == 3
@cama_current_user = current_site.users_include_admins.find_by_auth_token(c[0]).try(:decorate)
end | CWE-613 | 7 |
def parse(socket=nil)
@socket = socket
begin
@peeraddr = socket.respond_to?(:peeraddr) ? socket.peeraddr : []
@addr = socket.respond_to?(:addr) ? socket.addr : []
rescue Errno::ENOTCONN
raise HTTPStatus::EOFError
end
read_request_line(socket)
if @http_version.major > 0
read_header(socket)
@header['cookie'].each{|cookie|
@cookies += Cookie::parse(cookie)
}
@accept = HTTPUtils.parse_qvalues(self['accept'])
@accept_charset = HTTPUtils.parse_qvalues(self['accept-charset'])
@accept_encoding = HTTPUtils.parse_qvalues(self['accept-encoding'])
@accept_language = HTTPUtils.parse_qvalues(self['accept-language'])
end
return if @request_method == "CONNECT"
return if @unparsed_uri == "*"
begin
setup_forwarded_info
@request_uri = parse_uri(@unparsed_uri)
@path = HTTPUtils::unescape(@request_uri.path)
@path = HTTPUtils::normalize_path(@path)
@host = @request_uri.host
@port = @request_uri.port
@query_string = @request_uri.query
@script_name = ""
@path_info = @path.dup
rescue
raise HTTPStatus::BadRequest, "bad URI `#{@unparsed_uri}'."
end
if /close/io =~ self["connection"]
@keep_alive = false
elsif /keep-alive/io =~ self["connection"]
@keep_alive = true
elsif @http_version < "1.1"
@keep_alive = false
else
@keep_alive = true
end
end | CWE-444 | 41 |
def self.search_by_host(key, operator, value)
conditions = "hosts.name #{operator} '#{value_to_sql(operator, value)}'"
direct = Puppetclass.all(:conditions => conditions, :joins => :hosts, :select => 'puppetclasses.id').map(&:id).uniq
hostgroup = Hostgroup.joins(:hosts).where(conditions).first
indirect = HostgroupClass.where(:hostgroup_id => hostgroup.path_ids).pluck(:puppetclass_id).uniq
return { :conditions => "1=0" } if direct.blank? && indirect.blank?
puppet_classes = (direct + indirect).uniq
{ :conditions => "puppetclasses.id IN(#{puppet_classes.join(',')})" }
end | CWE-89 | 0 |
it 'is possible to return errors in jsonapi format' do
get '/'
expect(last_response.body).to eq('{"error":"rain!"}')
end | CWE-79 | 1 |
def self.get_for(user_id, date_s)
SqlHelper.validate_token([user_id, date_s])
begin
con = "(user_id=#{user_id}) and (date='#{date_s}')"
return Timecard.where(con).first
rescue
end
return nil
end | CWE-89 | 0 |
def group
Log.add_info(request, params.inspect)
date_s = params[:date]
if date_s.nil? or date_s.empty?
@date = Date.today
else
@date = Date.parse(date_s)
end
@group_id = params[:id]
group_users = Group.get_users(params[:id])
@user_schedule_hash = {}
unless group_users.nil?
@holidays = Schedule.get_holidays
group_users.each do |user|
@user_schedule_hash[user.id.to_s] = Schedule.get_somebody_week(@login_user, user.id, @date, @holidays)
end
end
params[:display] = params[:action] + '_' + params[:id]
end | CWE-89 | 0 |
def create_workflow
Log.add_info(request, params.inspect)
@tmpl_folder, @tmpl_workflows_folder = TemplatesHelper.get_tmpl_subfolder(TemplatesHelper::TMPL_WORKFLOWS)
@group_id = params[:group_id]
if @group_id.nil? or @group_id.empty?
@group_id = '0' # '0' for ROOT
elsif @group_id == '0'
;
else
group = nil
begin
group = Group.find(@group_id)
rescue
end
if group.nil?
render(:text => 'ERROR:' + t('msg.already_deleted', :name => Group.model_name.human))
return
end
end
unless @tmpl_workflows_folder.nil?
item = Item.new_workflow(@tmpl_workflows_folder.id)
item.title = t('workflow.new')
item.user_id = 0
item.save!
workflow = Workflow.new
workflow.item_id = item.id
workflow.user_id = 0
workflow.status = Workflow::STATUS_NOT_APPLIED
if @group_id == '0'
workflow.groups = nil
else
workflow.groups = '|' + @group_id + '|'
end
workflow.save!
else
Log.add_error(request, nil, '/'+TemplatesHelper::TMPL_ROOT+'/'+TemplatesHelper::TMPL_WORKFLOWS+' NOT found!')
end
render(:partial => 'groups/ajax_group_workflows', :layout => false)
end | CWE-89 | 0 |
def get_group_users
Log.add_info(request, params.inspect)
@group_id = nil
if !params[:thetisBoxSelKeeper].nil?
@group_id = params[:thetisBoxSelKeeper].split(':').last
elsif !params[:group_id].nil? and !params[:group_id].empty?
@group_id = params[:group_id]
end
submit_url = url_for(:controller => 'send_mails', :action => 'get_group_users')
render(:partial => 'common/select_users', :layout => false, :locals => {:target_attr => :email, :submit_url => submit_url})
end | CWE-89 | 0 |
def destroy
Log.add_info(request, params.inspect)
return unless request.post?
begin
Item.destroy(params[:id])
rescue => evar
Log.add_error(request, evar)
end
if params[:from_action].nil?
render(:text => params[:id])
else
params.delete(:controller)
params.delete(:action)
params.delete(:id)
flash[:notice] = t('msg.delete_success')
params[:action] = params[:from_action]
redirect_to(params)
end
end | CWE-89 | 0 |
def self.get_for_user(user)
return [] if user.nil?
toys = Toy.where("user_id=#{user.id}").to_a
deleted_ary = []
return [] if toys.nil?
toys.each do |toy|
case toy.xtype
when Toy::XTYPE_ITEM
item = Item.find_by_id(toy.target_id)
if item.nil?
deleted_ary << toy
next
end
Toy.copy(toy, item)
when Toy::XTYPE_COMMENT
comment = Comment.find_by_id(toy.target_id)
if comment.nil?
deleted_ary << toy
next
end
Toy.copy(toy, comment)
when Toy::XTYPE_WORKFLOW
workflow = Workflow.find_by_id(toy.target_id)
if workflow.nil?
deleted_ary << toy
next
end
Toy.copy(toy, workflow)
when Toy::XTYPE_SCHEDULE
schedule = Schedule.find_by_id(toy.target_id)
if schedule.nil?
deleted_ary << toy
next
end
Toy.copy(toy, schedule)
when Toy::XTYPE_FOLDER
folder = Folder.find_by_id(toy.target_id)
if folder.nil?
deleted_ary << toy
next
end
Toy.copy(toy, folder)
end
end | CWE-89 | 0 |
def get_group_users
Log.add_info(request, params.inspect)
begin
@folder = Folder.find(params[:id])
rescue => evar
Log.add_error(request, evar)
end
@group_id = nil
if !params[:thetisBoxSelKeeper].nil?
@group_id = params[:thetisBoxSelKeeper].split(':').last
elsif !params[:group_id].nil? and !params[:group_id].empty?
@group_id = params[:group_id]
end
@users = Group.get_users @group_id
render(:partial => 'ajax_select_users', :layout => false)
end | CWE-89 | 0 |
def get_mail_attachment
Log.add_info(request, params.inspect)
attached_id = params[:id].to_i
mail_attach = MailAttachment.find_by_id(attached_id)
if mail_attach.nil?
redirect_to(THETIS_RELATIVE_URL_ROOT + '/404.html')
return
end
email = Email.find_by_id(mail_attach.email_id)
if email.nil? or email.user_id != @login_user.id
render(:text => '')
return
end
mail_attach_name = mail_attach.name
agent = request.env['HTTP_USER_AGENT']
unless agent.nil?
ie_ver = nil
agent.scan(/\sMSIE\s?(\d+)[.](\d+)/){|m|
ie_ver = m[0].to_i + (0.1 * m[1].to_i)
}
mail_attach_name = CGI::escape(mail_attach_name) unless ie_ver.nil?
end
filepath = mail_attach.get_path
if FileTest.exist?(filepath)
send_file(filepath, :filename => mail_attach_name, :stream => true, :disposition => 'attachment')
else
send_data('', :type => 'application/octet-stream;', :disposition => 'attachment;filename="'+mail_attach_name+'"')
end
end | CWE-89 | 0 |
def self.run_gpg(*args)
fragments = [
'gpg',
'--no-default-keyring'
] + args
command_line = fragments.join(' ')
output_file = Tempfile.new('gpg-output')
begin
output_file.close
result = system("#{command_line} > #{output_file.path} 2>&1")
ensure
output_file.unlink
end
raise RuntimeError.new('gpg failed') unless result
end | CWE-94 | 14 |
it "should be an error instance if file was downloaded" do
stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
@instance.remote_image_url = "http://www.example.com/test.jpg"
e = @instance.image_integrity_error
expect(e).to be_an_instance_of(CarrierWave::IntegrityError)
expect(e.message.lines.grep(/^You are not allowed to upload/)).to be_truthy
end | CWE-918 | 16 |
def create_info_block(options)
return nil unless options
assignments = options.map { |k, v| "img.#{k} = #{v}" }
code = "lambda { |img| " + assignments.join(";") + "}"
eval code
end | CWE-94 | 14 |
def update_order
Log.add_info(request, params.inspect)
mail_account_id = params[:mail_account_id]
order_ary = params[:mail_filters_order]
@mail_account = MailAccount.find_by_id(mail_account_id)
if @mail_account.user_id != @login_user.id
render(:text => 'ERROR:' + t('msg.need_to_be_owner'))
return
end
filters = MailFilter.get_for(mail_account_id)
# filters must be ordered by xorder ASC.
filters.sort! { |filter_a, filter_b|
id_a = filter_a.id.to_s
id_b = filter_b.id.to_s
idx_a = order_ary.index(id_a)
idx_b = order_ary.index(id_b)
if idx_a.nil? or idx_b.nil?
idx_a = filters.index(id_a)
idx_b = filters.index(id_b)
end
idx_a - idx_b
}
idx = 1
filters.each do |filter|
next if filter.mail_account_id != mail_account_id.to_i
filter.update_attribute(:xorder, idx)
idx += 1
end
render(:text => '')
end | CWE-89 | 0 |
def group
Log.add_info(request, params.inspect)
date_s = params[:date]
if date_s.nil? or date_s.empty?
@date = Date.today
date_s = @date.strftime(Schedule::SYS_DATE_FORM)
else
@date = Date.parse date_s
end
if params[:display] == 'mine'
redirect_to(:action => 'month')
else
display_type = params[:display].split('_').first
display_id = params[:display].split('_').last
@selected_users = Group.get_users(display_id)
@group_id = display_id
if !@login_user.get_groups_a.include?(@group_id.to_s) and !@login_user.admin?(User::AUTH_TIMECARD)
Log.add_check(request, '[User.get_groups_a.include?]'+request.to_s)
redirect_to(:controller => 'frames', :action => 'http_error', :id => '401')
return
end
end
end | CWE-89 | 0 |
def scope_allowed_tags(tags)
Rails::Html::WhiteListSanitizer.allowed_tags = tags
yield Rails::Html::WhiteListSanitizer.new
ensure
Rails::Html::WhiteListSanitizer.allowed_tags = nil
end | CWE-79 | 1 |
def scope_allowed_attributes(attributes)
Rails::Html::WhiteListSanitizer.allowed_attributes = attributes
yield Rails::Html::WhiteListSanitizer.new
ensure
Rails::Html::WhiteListSanitizer.allowed_attributes = nil
end | CWE-79 | 1 |
def update
Log.add_info(request, params.inspect)
@equipment = Equipment.find(params[:id])
if (params[:groups].nil? or params[:groups].empty?)
params[:equipment][:groups] = nil
else
params[:equipment][:groups] = '|' + params[:groups].join('|') + '|'
end
if (params[:teams].nil? or params[:teams].empty?)
params[:equipment][:teams] = nil
else
params[:equipment][:teams] = '|' + params[:teams].join('|') + '|'
end
if @equipment.update_attributes(params.require(:equipment).permit(Equipment::PERMIT_BASE))
flash[:notice] = t('msg.update_success')
list
render(:action => 'list')
else
render(:controller => 'equipment', :action => 'edit', :id => params[:id])
end
end | CWE-89 | 0 |
def self.get_next_revision(user_id, source_id)
SqlHelper.validate_token([user_id, source_id])
copied_items = Item.where("user_id=#{user_id} and source_id=#{source_id}").order('created_at DESC').to_a
rev = 0
copied_items.each do |item|
rev_ary = item.title.scan(/[#](\d\d\d)$/)
next if rev_ary.nil?
rev = rev_ary.first.to_a.first.to_i
break
end
return ('#' + sprintf('%03d', rev+1))
end | CWE-89 | 0 |