code
stringlengths 12
2.05k
| label
int64 0
1
| programming_language
stringclasses 9
values | cwe_id
stringlengths 6
14
| cwe_name
stringlengths 5
103
⌀ | description
stringlengths 36
1.23k
⌀ | url
stringlengths 36
48
⌀ | label_name
stringclasses 2
values |
---|---|---|---|---|---|---|---|
def primary?
@primary
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
def stop
@manager.shutdown
@nodes.each &:stop
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
it "queries a secondary node" do
stats = Support::Stats.collect do
session.with(consistency: :eventual)[:users].find(scope: scope).entries
end
stats[:secondary].grep(Moped::Protocol::Query).count.should eq 1
stats[:primary].should be_empty
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def read_body(socket, block)
return unless socket
if tc = self['transfer-encoding']
case tc
when /chunked/io then read_chunked(socket, block)
else raise HTTPStatus::NotImplemented, "Transfer-Encoding: #{tc}."
end
elsif self['content-length'] || @remaining_size
@remaining_size ||= self['content-length'].to_i
while @remaining_size > 0
sz = [@buffer_size, @remaining_size].min
break unless buf = read_data(socket, sz)
@remaining_size -= buf.bytesize
block.call(buf)
end
if @remaining_size > 0 && @socket.eof?
raise HTTPStatus::BadRequest, "invalid body size."
end
elsif BODY_CONTAINABLE_METHODS.member?(@request_method) && [email protected]
raise HTTPStatus::LengthRequired
end | 0 | Ruby | CWE-444 | Inconsistent Interpretation of HTTP Requests ('HTTP Request/Response Smuggling') | The product acts as an intermediary HTTP agent
(such as a proxy or firewall) in the data flow between two
entities such as a client and server, but it does not
interpret malformed HTTP requests or responses in ways that
are consistent with how the messages will be processed by
those entities that are at the ultimate destination. | https://cwe.mitre.org/data/definitions/444.html | vulnerable |
it "executes a simple query" do
session.should_receive(:simple_query).with(query.operation)
query.one
end | 0 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | vulnerable |
def self.save_value(user_id, category, key, value)
SqlHelper.validate_token([user_id, category, key])
con = []
con << "(user_id=#{user_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.user_id = user_id
setting.category = category
setting.xkey = key
setting.xvalue = value
setting.save!
else
setting.update_attribute(:xvalue, value)
end
end
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def self.get_for_user(user)
return [] if user.nil?
toys = Toy.where("user_id=#{user.id}").to_a
deleted_arr = []
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_arr << toy
next
end
Toy.copy(toy, item)
when Toy::XTYPE_COMMENT
comment = Comment.find_by_id(toy.target_id)
if comment.nil?
deleted_arr << toy
next
end
Toy.copy(toy, comment)
when Toy::XTYPE_WORKFLOW
workflow = Workflow.find_by_id(toy.target_id)
if workflow.nil?
deleted_arr << toy
next
end
Toy.copy(toy, workflow)
when Toy::XTYPE_SCHEDULE
schedule = Schedule.find_by_id(toy.target_id)
if schedule.nil?
deleted_arr << toy
next
end
Toy.copy(toy, schedule)
when Toy::XTYPE_FOLDER
folder = Folder.find_by_id(toy.target_id)
if folder.nil?
deleted_arr << toy
next
end
Toy.copy(toy, folder)
end
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def get_auth_users
Log.add_info(request, params.inspect)
folder_id = params[:id]
SqlHelper.validate_token([folder_id])
begin
@folder = Folder.find(folder_id)
rescue
@folder = nil
end
@users = []
session[:folder_id] = folder_id
if !@login_user.nil? and (@login_user.admin?(User::AUTH_FOLDER) or ([email protected]? and @folder.in_my_folder_of?(@login_user.id)))
render(:partial => 'ajax_auth_users', :layout => false)
else
render(:partial => 'ajax_auth_disp', :layout => false)
end
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def connection
@connection ||= Connection.new
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def create_label
Log.add_info(request, params.inspect)
return unless request.post?
if params[:thetisBoxEdit].empty?
render(:partial => 'ajax_label', :layout => false)
return
end
@toy = Toy.new
@toy.xtype = Toy::XTYPE_LABEL
@toy.message = params[:thetisBoxEdit]
if @login_user.nil?
t = Time.now
@toy.id = (t.hour.to_s + t.min.to_s + t.sec.to_s).to_i
@toy.x, @toy.y = DesktopsHelper.find_empty_block(@login_user)
else
@toy.user_id = @login_user.id
@toy.x, @toy.y = DesktopsHelper.find_empty_block(@login_user)
@toy.save!
end
render(:partial => 'ajax_label', :layout => false)
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def self.get_for(mail_account_id, enabled=nil, trigger=nil)
return [] if mail_account_id.nil?
SqlHelper.validate_token([mail_account_id, trigger])
con = []
con << "(mail_account_id=#{mail_account_id})"
con << "(enabled=#{(enabled)?(1):(0)})" unless enabled.nil?
con << SqlHelper.get_sql_like([:triggers], "|#{trigger}|") unless trigger.nil?
return MailFilter.where(con.join(' and ')).order('(xorder is null) ASC, xorder ASC, id ASC').to_a
end | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
def update(change, flags = nil)
update = Protocol::Update.new(
operation.database,
operation.collection,
operation.selector,
change,
flags: flags
)
session.with(consistency: :strong) do |session|
session.execute update
end
end | 0 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | vulnerable |
def clean_text(text)
text.gsub(/[\000-\b\v-\f\016-\037\177]/, ".".freeze)
end | 1 | Ruby | CWE-94 | Improper Control of Generation of Code ('Code Injection') | The software constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. | https://cwe.mitre.org/data/definitions/94.html | safe |
def annotate(path, identifier=nil)
p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
blame = Annotate.new
hg 'rhannotate', '-ncu', '-r', CGI.escape(hgrev(identifier)), '--', hgtarget(p) do |io|
io.each_line do |line|
line.force_encoding('ASCII-8BIT')
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
:identifier => $3)
blame.add_line($4.rstrip, r)
end
end
blame
rescue HgCommandAborted
# means not found or cannot be annotated
Annotate.new
end | 0 | Ruby | NVD-CWE-noinfo | null | null | null | vulnerable |
def build_gem_lines(conservative_versioning)
@deps.map do |d|
name = d.name.dump
requirement = if conservative_versioning
", \"#{conservative_version(@definition.specs[d.name][0])}\""
else
", #{d.requirement.as_list.map(&:dump).join(", ")}"
end
if d.groups != Array(:default)
group = d.groups.size == 1 ? ", :group => #{d.groups.first.inspect}" : ", :groups => #{d.groups.inspect}"
end
source = ", :source => \"#{d.source}\"" unless d.source.nil?
git = ", :git => \"#{d.git}\"" unless d.git.nil?
branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil?
require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil?
%(gem #{name}#{requirement}#{group}#{source}#{git}#{branch}#{require_path})
end.join("\n") | 1 | Ruby | CWE-88 | Improper Neutralization of Argument Delimiters in a Command ('Argument Injection') | The software constructs a string for a command to executed by a separate component
in another control sphere, but it does not properly delimit the
intended arguments, options, or switches within that command string. | https://cwe.mitre.org/data/definitions/88.html | safe |
def cluster_stop(params, request, session)
if params[:name]
params_without_name = params.reject {|key, value|
key == "name" or key == :name
}
code, response = send_request_with_token(
session, params[:name], 'cluster_stop', true, params_without_name
)
else
if not allowed_for_local_cluster(session, Permissions::WRITE)
return 403, 'Permission denied'
end
options = []
if params.has_key?("component")
if params["component"].downcase == "pacemaker"
options << "--pacemaker"
elsif params["component"].downcase == "corosync"
options << "--corosync"
end
end
options << "--force" if params["force"]
$logger.info "Stopping Daemons"
stdout, stderr, retval = run_cmd(session, PCS, "cluster", "stop", *options)
if retval != 0
return [400, stderr.join]
else
return stdout.join
end
end
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def get_cib_dom(session)
begin
stdout, _, retval = run_cmd(session, 'cibadmin', '-Q', '-l')
if retval == 0
return REXML::Document.new(stdout.join("\n"))
end
rescue
$logger.error 'Failed to parse cib.'
end
return nil
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def test_update_invalid
Domain.any_instance.stubs(:valid?).returns(false)
put :update, {:id => Domain.first.to_param, :domain => {:name => Domain.first.name }}, set_session_user
assert_template 'edit'
end | 0 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | vulnerable |
def resource_cleanup(params, request, session)
if not allowed_for_local_cluster(session, Permissions::WRITE)
return 403, 'Permission denied'
end
stdout, stderr, retval = run_cmd(
session, PCS, "resource", "cleanup", params[:resource]
)
if retval == 0
return JSON.generate({"success" => "true"})
else
return JSON.generate({"error" => "true", "stdout" => stdout, "stderror" => stderr})
end
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
it 'should return the right response' do
email_token.update!(created_at: 999.years.ago)
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(200)
expect(CGI.unescapeHTML(response.body)).to match(
I18n.t('email_login.invalid_token')
)
end | 0 | Ruby | CWE-287 | Improper Authentication | When an actor claims to have a given identity, the software does not prove or insufficiently proves that the claim is correct. | https://cwe.mitre.org/data/definitions/287.html | vulnerable |
def add_file_signed name, mode, signer
digest_algorithms = [
signer.digest_algorithm,
Digest::SHA512,
].compact.uniq
digests = add_file_digest name, mode, digest_algorithms do |io|
yield io
end
signature_digest = digests.values.compact.find do |digest|
digest_name =
if digest.respond_to? :name then
digest.name
else
/::([^:]+)$/ =~ digest.class.name
$1
end
digest_name == signer.digest_name
end
raise "no #{signer.digest_name} in #{digests.values.compact}" unless signature_digest
if signer.key then
signature = signer.sign signature_digest.digest
add_file_simple "#{name}.sig", 0444, signature.length do |io|
io.write signature
end
end
digests
end | 1 | Ruby | CWE-347 | Improper Verification of Cryptographic Signature | The software does not verify, or incorrectly verifies, the cryptographic signature for data. | https://cwe.mitre.org/data/definitions/347.html | safe |
def self.get_tree(klass, tree, conditions, node_id, order_by)
SqlHelper.validate_token([node_id])
if conditions.nil?
con = ''
else
con = Marshal.load(Marshal.dump(conditions)) + ' and '
end
con << "(parent_id=#{node_id})"
tree[node_id] = klass.where(con).order(order_by).to_a
tree[node_id].each do |node|
tree = klass.get_tree(tree, conditions, node.id.to_s)
end
return tree
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def self.included(context)
context.before :all do
@replica_set = ReplicaSetSimulator.new
@replica_set.start
@primary, @secondaries = @replica_set.initiate
end
context.after :all do
@replica_set.stop
end
context.after :each do
@replica_set.nodes.each &:restart
end
context.let :seeds do
@replica_set.nodes.map &:address
end
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def spec_summary entry, spec
entry << "\n\n" << format_text(spec.summary, 68, 4)
end | 0 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | vulnerable |
def replica_set_seeds
[ENV["MONGOHQ_REPL_1_URL"], ENV["MONGOHQ_REPL_2_URL"]]
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
def add_acl_usergroup(session, acl_role_id, user_group, name)
if (user_group == "user") or (user_group == "group")
stdout, stderr, retval = run_cmd(
session, PCS, "acl", user_group, "create", name.to_s, acl_role_id.to_s
)
if retval == 0
return ""
end
if not /^error: (user|group) #{name.to_s} already exists$/i.match(stderr.join("\n").strip)
return stderr.join("\n").strip
end
end
stdout, stderror, retval = run_cmd(
session, PCS, "acl", "role", "assign", acl_role_id.to_s, name.to_s
)
if retval != 0
if stderror.empty?
return "Error adding #{user_group}"
else
return stderror.join("\n").strip
end
end
return ""
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
it "respects custom options" do
expect(app.as_json(except: :secret)).not_to include("secret")
expect(app.as_json(only: :id)).to match("id" => app.id)
end | 0 | Ruby | CWE-862 | Missing Authorization | The software does not perform an authorization check when an actor attempts to access a resource or perform an action. | https://cwe.mitre.org/data/definitions/862.html | vulnerable |
def add_node_attr(session, node, key, value)
stdout, stderr, retval = run_cmd(
session, PCS, "property", "set", "--node", node, key.to_s + '=' + value.to_s
)
return retval
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def team
Log.add_info(request, params.inspect)
date_s = params[:date]
if date_s.blank?
@date = Date.today
else
@date = Date.parse(date_s)
end
begin
team = Team.find(params[:id])
team_users = team.get_users_a
rescue => evar
Log.add_error(request, evar)
end
@user_schedule_hash = {}
unless team_users.nil?
@holidays = Schedule.get_holidays
team_users.each do |user_id|
@user_schedule_hash[user_id] = Schedule.get_somebody_week(@login_user, user_id, @date, @holidays)
end
end
params[:display] = params[:action] + '_' + params[:id]
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
def address
"#{@host}:#{@port}"
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
it "applies the cached authentication" do
cluster.stub(:sync) { cluster.servers << server }
socket.should_receive(:apply_auth).with(cluster.auth)
cluster.socket_for(:write)
end | 0 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | vulnerable |
def logout(database)
command = Protocol::Command.new(database, logout: 1)
connection.write [command]
result = connection.read.documents.first
raise Errors::OperationFailure.new(command, result) unless result["ok"] == 1
auth.delete(database)
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def connected?
connection.connected?
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def primaries
servers.select(&:primary?)
end | 0 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | vulnerable |
def parse_memory(data, encoding = "UTF-8")
raise ArgumentError unless data
return if data.empty?
ctx = ParserContext.memory(data, encoding)
yield ctx if block_given?
ctx.parse_with(self)
end | 0 | Ruby | CWE-241 | Improper Handling of Unexpected Data Type | The software does not handle or incorrectly handles when a particular element is not the expected type, e.g. it expects a digit (0-9) but is provided with a letter (A-Z). | https://cwe.mitre.org/data/definitions/241.html | vulnerable |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
def get_cluster_name()
if ISRHEL6
stdout, stderror, retval = run_cmd(
PCSAuth.getSuperuserSession, COROSYNC_CMAPCTL, "cluster"
)
if retval == 0
stdout.each { |line|
match = /^cluster\.name=(.*)$/.match(line)
return match[1] if match
}
end
begin
cluster_conf = Cfgsync::ClusterConf.from_file().text()
rescue
return ''
end
conf_dom = REXML::Document.new(cluster_conf)
if conf_dom.root and conf_dom.root.name == 'cluster'
return conf_dom.root.attributes['name']
end
return ''
end
stdout, stderror, retval = run_cmd(
PCSAuth.getSuperuserSession, COROSYNC_CMAPCTL, "totem.cluster_name"
)
if retval != 0 and not ISRHEL6
# Cluster probably isn't running, try to get cluster name from
# corosync.conf
begin
corosync_conf = CorosyncConf::parse_string(
Cfgsync::CorosyncConf.from_file().text()
)
# mimic corosync behavior - the last cluster_name found is used
cluster_name = nil
corosync_conf.sections('totem').each { |totem|
totem.attributes('cluster_name').each { |attrib|
cluster_name = attrib[1]
}
}
return cluster_name if cluster_name
rescue
return ''
end
return ""
else
return stdout.join().gsub(/.*= /,"").strip
end
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def add_to_group
Log.add_info(request, params.inspect)
return unless request.post?
if params[:thetisBoxSelKeeper].blank?
render(:partial => 'ajax_groups', :layout => false)
return
end
group_id = params[:thetisBoxSelKeeper].split(':').last
unless group_id == '0' # '0' for ROOT
begin
group = Group.find(group_id)
rescue => evar
Log.add_error(request, evar)
ensure
if group.nil?
render(:partial => 'ajax_groups', :layout => false)
return
end
end
end
begin
@user = User.find(params[:user_id])
rescue => evar
Log.add_error(request, evar)
end
unless @user.nil?
is_modified = false
# Change, not simply Add
unless params[:current_id].blank?
if @user.exclude_from(params[:current_id])
is_modified = true
end
end
is_modified = true if @user.add_to(group_id)
if is_modified == true
@user.save!
if @user.id == @login_user.id
@login_user = @user
end
end
end
render(:partial => 'ajax_groups', :layout => false)
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
it 'should only print each format once with an exception' do
lambda do
@klass.format :foobar
end.should raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: html, json, plain, xml, yaml")
end | 0 | Ruby | CWE-264 | Permissions, Privileges, and Access Controls | Weaknesses in this category are related to the management of permissions, privileges, and other security features that are used to perform access control. | https://cwe.mitre.org/data/definitions/264.html | vulnerable |
it "reconnects without raising an exception" do
node.ensure_connected do
node.command("admin", ping: 1)
end.should eq("ok" => 1)
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
def field
_, @value = split(@raw_value) if @raw_value && !@value
@field ||= create_field(@name, @value, @charset)
end | 1 | Ruby | CWE-93 | Improper Neutralization of CRLF Sequences ('CRLF Injection') | The software uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes CRLF sequences from inputs. | https://cwe.mitre.org/data/definitions/93.html | safe |
def self.get_for_group(group_id)
SqlHelper.validate_token([group_id])
if group_id.nil?
con = 'group_id is null'
else
con = "group_id=#{group_id}"
end
Location.do_expire(con)
return Location.where(con).to_a
end | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
it "yields a session with the provided options" do
session.with(safe: true) do |safe|
safe.options[:safe].should eq true
end
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
def destroy
Log.add_info(request, params.inspect)
return unless request.post?
if params[:check_address].nil?
list
render(:action => 'list')
return
end
count = 0
params[:check_address].each do |address_id, value|
if value == '1'
begin
address = Address.find(address_id)
address.destroy if address.editable?(@login_user)
rescue => evar
Log.add_error(request, evar)
end
count += 1
end
end
flash[:notice] = t('address.deleted', :count => count)
list
render(:action => 'list')
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def to_xml(options = nil)
[name].to_xml
end | 1 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | safe |
def destroy_all
Log.add_info(request, params.inspect)
return unless request.post?
ZeptairXlog.delete_all
flash[:notice] = t('msg.delete_success')
redirect_to(:action => 'list')
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def check_gui_status_of_nodes(session, nodes, check_mutuality=false, timeout=10)
options = {}
options[:check_auth_only] = '' if not check_mutuality
threads = []
not_authorized_nodes = []
online_nodes = []
offline_nodes = []
nodes = nodes.uniq.sort
nodes.each { |node|
threads << Thread.new {
code, response = send_request_with_token(
session, node, 'check_auth', false, options, true, nil, timeout
)
if code == 200
if check_mutuality
begin
parsed_response = JSON.parse(response)
if parsed_response['node_list'] and parsed_response['node_list'].uniq.sort == nodes
online_nodes << node
else
not_authorized_nodes << node
end
rescue
not_authorized_nodes << node
end
else
online_nodes << node
end
else
begin
parsed_response = JSON.parse(response)
if parsed_response['notauthorized'] or parsed_response['notoken']
not_authorized_nodes << node
else
offline_nodes << node
end
rescue JSON::ParserError
end
end
}
}
threads.each { |t| t.join }
return online_nodes, offline_nodes, not_authorized_nodes
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def data=(data)
@raw_data = data
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
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 | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def test_update_valid
Medium.any_instance.stubs(:valid?).returns(true)
put :update, {:id => Medium.first, :medium => {:name => "MyUpdatedMedia"}}, set_session_user
assert_redirected_to media_url
end | 0 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | vulnerable |
def self.update_for(user_id, fiscal_year, num)
SqlHelper.validate_token([user_id, fiscal_year])
if num <= 0
con = []
con << "(user_id=#{user_id})"
con << "(year=#{fiscal_year})"
PaidHoliday.destroy_all(con.join(' and '))
return
end
paid_holiday = PaidHoliday.get_for(user_id, fiscal_year)
if paid_holiday.nil?
paid_holiday = PaidHoliday.new
paid_holiday.user_id = user_id
paid_holiday.year = fiscal_year
paid_holiday.num = num
paid_holiday.save!
else
paid_holiday.update_attribute(:num, num)
end
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def ensure_primary
Threaded.begin :ensure_primary
yield
ensure
Threaded.end :ensure_primary | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
def self.new string_or_io
from_document Nokogiri::XML(string_or_io)
end | 0 | Ruby | CWE-611 | Improper Restriction of XML External Entity Reference | The software processes an XML document that can contain XML entities with URIs that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output. | https://cwe.mitre.org/data/definitions/611.html | vulnerable |
it "sets the query operation's limit field" do
query.limit(5)
query.operation.limit.should eq 5
end | 0 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | vulnerable |
def self.search_by_params(key, operator, value)
key_name = key.sub(/^.*\./,'')
condition = sanitize_sql_for_conditions(["name = ? and value #{operator} ?", key_name, value_to_sql(operator, value)])
opts = {:conditions => condition, :order => :priority}
p = Parameter.all(opts)
return {:conditions => '1 = 0'} if p.blank?
max = p.first.priority
condition = sanitize_sql_for_conditions(["name = ? and NOT(value #{operator} ?) and priority > ?",key_name,value_to_sql(operator, value), max])
negate_opts = {:conditions => condition, :order => :priority}
n = Parameter.all(negate_opts)
conditions = param_conditions(p)
negate = param_conditions(n)
conditions += " AND " unless conditions.blank? || negate.blank?
conditions += " NOT(#{negate})" unless negate.blank?
return {:conditions => conditions}
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def protected!
gui_request = ( # these are URLs for web pages
request.path == '/' or
request.path == '/manage' or
request.path == '/permissions' or
request.path.match('/managec/.+/main')
)
if request.path.start_with?('/remote/') or request.path == '/run_pcs'
@auth_user = PCSAuth.loginByToken(cookies)
unless @auth_user
halt [401, '{"notauthorized":"true"}']
end
else #/managec/* /manage/* /permissions
if !gui_request and
request.env['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest'
then
# Accept non GUI requests only with header
# "X_REQUESTED_WITH: XMLHttpRequest". (check if they are send via AJAX).
# This prevents CSRF attack.
halt [401, '{"notauthorized":"true"}']
elsif not PCSAuth.isLoggedIn(session)
if gui_request
session[:pre_login_path] = request.path
redirect '/login'
else
halt [401, '{"notauthorized":"true"}']
end
end
end
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
it "gets more and closes cursors" do
11.times do
users.insert(scope: scope, large_field: "a"*1_000_000)
end
stats = Support::Stats.collect do
users.find(scope: scope).limit(10).entries
end
stats[:primary].grep(Moped::Protocol::GetMore).count.should eq 1
stats[:primary].grep(Moped::Protocol::KillCursors).count.should eq 1
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
it "inserts a document" do
users.find(scope: scope).upsert("$inc" => { counter: 1 })
users.find(scope: scope).one["counter"].should eq 1
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
it "returns the socket" do
cluster.stub(:sync) { cluster.servers << server }
cluster.socket_for(:write).should eq socket
end | 0 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | vulnerable |
def quote_column_name(name) #:nodoc:
@quoted_column_names[name] ||= "`#{name.to_s.gsub('`', '``')}`"
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def setup
FactoryGirl.create(:host, :organization => nil)
end | 1 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | safe |
def base_api_url
computed_api_endpoint = "https://#{get_data_center_from_api_key(self.api_key)}api.mailchimp.com"
raise Gibbon::GibbonError, "SSRF attempt" unless URI(computed_api_endpoint).host.include?("api.mailchimp.com")
"#{self.api_endpoint || computed_api_endpoint}/3.0/"
end | 0 | Ruby | CWE-918 | Server-Side Request Forgery (SSRF) | The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination. | https://cwe.mitre.org/data/definitions/918.html | vulnerable |
def initialize(session, config_classes, nodes, cluster_name)
@config_classes = config_classes
@nodes = nodes
@cluster_name = cluster_name
@session = session
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def update_image_info
Log.add_info(request, params.inspect)
return unless request.post?
image = Image.find(params[:image_id])
# Getting Item at first for the case of resetting the db connection by an error.
@item = Item.find(image.item_id)
unless @item.check_user_auth(@login_user, 'w', true)
raise t('msg.need_to_be_owner')
end
if !params[:image][:file].nil? and params[:image][:file].size == 0
params[:image].delete(:file)
end
unless image.update_attributes(params.require(:image).permit(Image::PERMIT_BASE))
@image = image
render(:partial => 'ajax_item_image', :layout => false)
return
end
@item = Item.find(image.item_id)
@item.update_attribute(:updated_at, Time.now)
render(:partial => 'ajax_item_image', :layout => false)
rescue => evar
Log.add_error(request, evar)
@image = Image.new
@image.errors.add_to_base(evar.to_s[0, 256])
render(:partial => 'ajax_item_image', :layout => false)
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def has_cookie?
[email protected]?
end | 0 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | vulnerable |
def self.map_library_name(lib)
# Mangle the library name to reflect the native library naming conventions
lib = lib.to_s unless lib.kind_of?(String)
lib = Library::LIBC if lib == 'c'
if lib && File.basename(lib) == lib
lib = Platform::LIBPREFIX + lib unless lib =~ /^#{Platform::LIBPREFIX}/
r = Platform::IS_GNU ? "\\.so($|\\.[1234567890]+)" : "\\.#{Platform::LIBSUFFIX}$"
lib += ".#{Platform::LIBSUFFIX}" unless lib =~ /#{r}/
end
lib
end | 0 | Ruby | CWE-426 | Untrusted Search Path | The application searches for critical resources using an externally-supplied search path that can point to resources that are not under the application's direct control. | https://cwe.mitre.org/data/definitions/426.html | vulnerable |
it "returns a hex string representation of the id" do
Moped::BSON::ObjectId.new(bytes).to_s.should eq "4e4d66343b39b68407000001"
end | 0 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | vulnerable |
it "creates an index with a generated name" do
indexes.create(key)
indexes[key]["name"].should eq "location.latlong_2d_name_1_age_-1"
end | 0 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | vulnerable |
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 | 0 | Ruby | CWE-94 | Improper Control of Generation of Code ('Code Injection') | The software constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. | https://cwe.mitre.org/data/definitions/94.html | vulnerable |
def show_tree
if params[:action] == 'show_tree'
Log.add_info(request, params.inspect)
end
con = []
con << "(user_id=#{@login_user.id})"
account_xtype = params[:mail_account_xtype]
SqlHelper.validate_token([account_xtype])
unless account_xtype.blank?
con << "(xtype='#{account_xtype}')"
end
@mail_accounts = MailAccount.find_all(con.join(' and '))
mail_account_ids = []
@mail_accounts.each do |mail_account|
mail_account_ids << mail_account.id
if MailFolder.where("mail_account_id=#{mail_account.id}").count <= 0
@login_user.create_default_mail_folders(mail_account.id)
end
Email.destroy_by_user(@login_user.id, "status='#{Email::STATUS_TEMPORARY}'")
end
@folder_tree = MailFolder.get_tree_for(@login_user, mail_account_ids)
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
it "gets more and closes cursors" do
11.times do
users.insert(scope: scope, large_field: "a"*1_000_000)
end
stats = Support::Stats.collect do
users.find(scope: scope).limit(10).entries
end
stats[:primary].grep(Moped::Protocol::GetMore).count.should eq 1
stats[:primary].grep(Moped::Protocol::KillCursors).count.should eq 1
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def insert(documents)
documents = [documents] unless documents.is_a? Array
database.session.with(consistency: :strong) do |session|
session.context.insert(database.name, name, documents)
end
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
it "drops the collection" do
result = session[:users].drop
result["ns"].should eq "moped_test.users"
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
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 | 0 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | vulnerable |
def index
valid_http_methods :get, :post
# 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
if request.get?
pass_to_backend
return
end
if @http_user.is_admin?
# check for a local package instance
DbPackage.get_by_project_and_name( params[:project], params[:package], follow_project_links=false )
pass_to_backend
else
render_error :status => 403, :errorcode => "execute_cmd_no_permission",
:message => "Upload of binaries is only permitted for administrators"
end
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
it 'does not log in with incorrect backup code' do
post "/session/email-login/#{email_token.token}", params: {
second_factor_token: "0000",
second_factor_method: UserSecondFactor.methods[:backup_codes]
}
expect(response.status).to eq(200)
expect(CGI.unescapeHTML(response.body)).to include(I18n.t(
"login.invalid_second_factor_code"
))
end | 0 | Ruby | CWE-287 | Improper Authentication | When an actor claims to have a given identity, the software does not prove or insufficiently proves that the claim is correct. | https://cwe.mitre.org/data/definitions/287.html | vulnerable |
it "respects #skip" do
users.find(scope: scope).skip(1).one.should eq documents.last
end | 1 | Ruby | CWE-400 | Uncontrolled Resource Consumption | The software does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. | https://cwe.mitre.org/data/definitions/400.html | safe |
it "queries the primary node" do
stats = Support::Stats.collect do
session.with(consistency: :eventual)[:users].find(scope: scope).entries
end
stats[:primary].grep(Moped::Protocol::Query).count.should eq 1
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def as_json(options = {})
hash = super
hash["secret"] = plaintext_secret if hash.key?("secret")
hash
end | 0 | Ruby | CWE-862 | Missing Authorization | The software does not perform an authorization check when an actor attempts to access a resource or perform an action. | https://cwe.mitre.org/data/definitions/862.html | vulnerable |
def stack(name)
Thread.current["[moped]:#{name}-stack"] ||= []
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
it "converts to Punycode URI" do
expect(subject.process_uri(uri).to_s).to eq 'http://xn--eckwd4c7cu47r2wf.jp/test.jpg'
end | 0 | Ruby | CWE-918 | Server-Side Request Forgery (SSRF) | The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination. | https://cwe.mitre.org/data/definitions/918.html | vulnerable |
def self.parse_csv_row(row, book, idxs, user)
imp_id = (idxs[0].nil? or row[idxs[0]].nil?)?(nil):(row[idxs[0]].strip)
SqlHelper.validate_token([imp_id])
unless imp_id.blank?
begin
org_address = Address.find(imp_id)
rescue => evar
org_address = nil
end
end
if org_address.nil?
address = Address.new
else
address = org_address
end
address.id = imp_id
attr_names = [
:name,
:name_ruby,
:nickname,
:screenname,
:email1,
:email2,
:email3,
:postalcode,
:address,
:tel1_note,
:tel1,
:tel2_note,
:tel2,
:tel3_note,
:tel3,
:fax,
:url,
:organization,
:title,
:memo,
:xorder,
:groups,
:teams
]
attr_names.each_with_index do |attr_name, idx|
row_idx = idxs[idx+1]
break if row_idx.nil?
val = (row[row_idx].nil?)?(nil):(row[row_idx].strip)
address.send(attr_name.to_s + '=', val)
end
if (address.groups == Address::EXP_IMP_FOR_ALL) \
or (book == Address::BOOK_COMMON and address.groups.blank? and address.teams.blank?)
address.groups = nil
address.teams = nil
address.owner_id = 0
elsif !address.groups.blank? or !address.teams.blank?
address.owner_id = 0
else
address.owner_id = user.id
end
return address
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def read_checksums gem
Gem.load_yaml
@checksums = gem.seek 'checksums.yaml.gz' do |entry|
Zlib::GzipReader.wrap entry do |gz_io|
Gem::SafeYAML.safe_load gz_io.read
end
end
end | 1 | Ruby | CWE-502 | Deserialization of Untrusted Data | The application deserializes untrusted data without sufficiently verifying that the resulting data will be valid. | https://cwe.mitre.org/data/definitions/502.html | safe |
def duplicate
Log.add_info(request, params.inspect)
return unless request.post?
copies_folder = ItemsHelper.get_copies_folder(@login_user.id)
item = Item.find(params[:id])
if item.is_a_copy?
flash[:notice] = 'ERROR:' + t('msg.system_error')
else
item.xtype = Item::XTYPE_INFO
item.public = false
item.title += ItemsHelper.get_next_revision(@login_user.id, item.id)
copied_item = item.copy(@login_user.id, copies_folder.id, [:image, :attachment])
flash[:notice] = "#{t('msg.save_success')}#{t('cap.suffix')}<br/>#{copied_item.title}"
end
render(:partial => 'common/flash_notice', :layout => false)
end | 1 | Ruby | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
def query(operation)
reply = session.query operation
@get_more_op.limit -= reply.count if limited?
@get_more_op.cursor_id = reply.cursor_id
@kill_cursor_op.cursor_ids = [reply.cursor_id]
reply.documents
end | 0 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | vulnerable |
it "returns the index with the provided key" do
indexes[name: 1]["name"].should eq "name_1"
end | 0 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | vulnerable |
it "doesn't log in the user when not approved" do
SiteSetting.must_approve_users = true
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(200)
expect(CGI.unescapeHTML(response.body)).to include(
I18n.t("login.not_approved")
)
end | 0 | Ruby | CWE-287 | Improper Authentication | When an actor claims to have a given identity, the software does not prove or insufficiently proves that the claim is correct. | https://cwe.mitre.org/data/definitions/287.html | vulnerable |
def test_update_valid
AuthSourceLdap.any_instance.stubs(:valid?).returns(true)
put :update, {:id => AuthSourceLdap.unscoped.first, :auth_source_ldap => {:name => AuthSourceLdap.unscoped.first.name} }, set_session_user
assert_redirected_to auth_source_ldaps_url
end | 1 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | safe |
def getok(reqline)
validate_line reqline
res = critical {
@socket.writeline reqline
recv_response()
}
check_response res
res
end | 1 | Ruby | CWE-93 | Improper Neutralization of CRLF Sequences ('CRLF Injection') | The software uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes CRLF sequences from inputs. | https://cwe.mitre.org/data/definitions/93.html | safe |
def kill_cursors(cursor_ids)
process Protocol::KillCursors.new(cursor_ids)
end | 1 | Ruby | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def run_cmd(session, *args)
options = {}
return run_cmd_options(session, options, *args)
end | 0 | Ruby | CWE-384 | Session Fixation | Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. | https://cwe.mitre.org/data/definitions/384.html | vulnerable |
def decode_compact_serialized(input, public_key_or_secret, algorithms = nil, allow_blank_payload = false)
unless input.count('.') + 1 == NUM_OF_SEGMENTS
raise InvalidFormat.new("Invalid JWS Format. JWS should include #{NUM_OF_SEGMENTS} segments.")
end
header, claims, signature = input.split('.', JWS::NUM_OF_SEGMENTS).collect do |segment|
Base64.urlsafe_decode64 segment.to_s
end
header = JSON.parse(header).with_indifferent_access
if allow_blank_payload && claims == ''
claims = nil
else
claims = JSON.parse(claims).with_indifferent_access
end
jws = new claims
jws.header = header
jws.signature = signature
jws.signature_base_string = input.split('.')[0, JWS::NUM_OF_SEGMENTS - 1].join('.')
jws.verify! public_key_or_secret, algorithms unless public_key_or_secret == :skip_verification
jws
end | 0 | Ruby | CWE-287 | Improper Authentication | When an actor claims to have a given identity, the software does not prove or insufficiently proves that the claim is correct. | https://cwe.mitre.org/data/definitions/287.html | vulnerable |
def show_owners name
response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request|
request.add_field "Authorization", api_key
end
with_response response do |resp|
owners = Gem::SafeYAML.load resp.body
say "Owners for gem: #{name}"
owners.each do |owner|
say "- #{owner['email'] || owner['handle'] || owner['id']}"
end
end
end | 1 | Ruby | CWE-502 | Deserialization of Untrusted Data | The application deserializes untrusted data without sufficiently verifying that the resulting data will be valid. | https://cwe.mitre.org/data/definitions/502.html | safe |
def test_update_valid
put :update, {:id => Hostgroup.first, :hostgroup => { :name => Hostgroup.first.name }}, set_session_user
assert_redirected_to hostgroups_url
end | 0 | Ruby | CWE-200 | Exposure of Sensitive Information to an Unauthorized Actor | The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. | https://cwe.mitre.org/data/definitions/200.html | vulnerable |
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 | 0 | Ruby | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The software does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | vulnerable |
Subsets and Splits