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 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]
unless account_xtype.blank?
SqlHelper.validate_token([account_xtype])
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 | 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 check_write_access!
return if Rails.env.test? and User.current.nil? # for unit tests
# the can_create_check is inconsistent with package class check_write_access! check
unless User.current.can_modify_project?(self) || User.current.can_create_project?(self.name)
raise WritePermissionError, "No permission to modify project '#{self.name}' for user '#{User.current.login}'"
end
end | 1 | Ruby | CWE-275 | Permission Issues | Weaknesses in this category are related to improper assignment or handling of permissions. | https://cwe.mitre.org/data/definitions/275.html | safe |
def initialize(name, value = nil, charset = 'utf-8')
case
when name =~ /:/ # Field.new("field-name: field data")
@charset = value.blank? ? charset : value
@name, @value = split(name)
when name !~ /:/ && value.blank? # Field.new("field-name")
@name = name
@value = nil
@charset = charset
else # Field.new("field-name", "value")
@name = name
@value = value
@charset = charset
end | 0 | 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 | vulnerable |
it "allows you to create an account and redeems the invite successfully even if must_approve_users is enabled" do
SiteSetting.must_approve_users = true
login_with_sso_and_invite
expect(response.status).to eq(302)
expect(response).to redirect_to("/")
expect(invite.reload.redeemed?).to eq(true)
user = User.find_by_email("[email protected]")
expect(user.active).to eq(true)
end | 0 | Ruby | CWE-863 | Incorrect Authorization | The software performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check. This allows attackers to bypass intended access restrictions. | https://cwe.mitre.org/data/definitions/863.html | vulnerable |
def auth_credentials
[ENV["MONGOHQ_SINGLE_USER"], ENV["MONGOHQ_SINGLE_PASS"]]
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 "updates the record matching selector with change" do
session.should_receive(:with, :consistency => :strong).
and_yield(session)
session.should_receive(:execute).with do |update|
update.flags.should eq []
update.selector.should eq query.operation.selector
update.update.should eq change
end
query.update change
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.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 | 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_post
uri = URI('http://localhost:6470/makeme')
req = Net::HTTP::Post.new(uri)
# Set the headers the way we want them.
req['Accept-Encoding'] = '*'
req['Accept'] = 'application/json'
req['User-Agent'] = 'Ruby'
res = Net::HTTP.start(uri.hostname, uri.port) { |h|
h.request(req)
}
assert_equal(Net::HTTPNoContent, res.class)
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 |
def build_command_line(command, params = nil)
CommandLineBuilder.new.build(command, params)
end | 1 | Ruby | CWE-78 | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/78.html | safe |
def update_patchinfo(patchinfo, opts = {})
check_write_access!
opts[:enfore_issue_update] ||= false
# collect bugnumbers from diff
self.packages.each do |p|
# create diff per package
next if p.package_kinds.find_by_kind 'patchinfo'
p.package_issues.each do |i|
if i.change == "added"
unless patchinfo.has_element?("issue[(@id='#{i.issue.name}' and @tracker='#{i.issue.issue_tracker.name}')]")
e = patchinfo.add_element "issue"
e.set_attribute "tracker", i.issue.issue_tracker.name
e.set_attribute "id" , i.issue.name
patchinfo.category.text = "security" if i.issue.issue_tracker.kind == "cve"
end
end
end
end
# update informations of empty issues
patchinfo.each_issue do |i|
if i.text.blank? and not i.name.blank?
issue = Issue.find_or_create_by_name_and_tracker(i.name, i.tracker)
if issue
if opts[:enfore_issue_update]
# enforce update from issue server
issue.fetch_updates()
end
i.text = issue.summary
end
end
end
return patchinfo
end | 1 | Ruby | CWE-275 | Permission Issues | Weaknesses in this category are related to improper assignment or handling of permissions. | https://cwe.mitre.org/data/definitions/275.html | safe |
def handle_unverified_request
super
raise ActionController::InvalidAuthenticityToken
end | 1 | Ruby | CWE-352 | Cross-Site Request Forgery (CSRF) | The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request. | https://cwe.mitre.org/data/definitions/352.html | safe |
def primaries
servers.select(&:primary?)
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 "merges the old and new session's options" do
session.with(new_options) do |new_session|
new_session.options.should eq options.merge(new_options)
end
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 test_update_valid
Medium.any_instance.stubs(:valid?).returns(true)
put :update, {:id => @model, :medium => {:name => "MyUpdatedMedia"}}, set_session_user
assert_redirected_to media_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 |
it 'fails when local logins via email is disabled' do
SiteSetting.enable_local_logins_via_email = false
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(404)
end | 0 | Ruby | NVD-CWE-noinfo | null | null | null | vulnerable |
def self.getSuperuserSession()
return {
:username => SUPERUSER,
:usergroups => [],
}
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 generate(time, counter = 0)
process_thread_id = "#{Process.pid}#{Thread.current.object_id}".hash % 0xFFFF
[ time, machine_id, process_thread_id, counter << 8 ].pack("N NX lXX NX")
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
if params[:user]
roles = params[:user].delete("spree_role_ids")
end
@user = Spree::User.new(params[:user])
if @user.save
if roles
@user.spree_roles = roles.reject(&:blank?).collect{|r| Spree::Role.find(r)}
end
flash.now[:notice] = t(:created_successfully)
render :edit
else
render :new
end
end | 1 | 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 | safe |
def self.validate_token(tokens, extra_chars=nil)
extra_chars = Regexp.escape((extra_chars || []).join())
regexp = Regexp.new("^[ ]*[a-zA-Z0-9_.#{extra_chars}]+[ ]*$")
[tokens].flatten.each do |token|
next if token.blank?
if token.to_s.match(regexp).nil?
raise("[ERROR] SqlHelper.validate_token failed: #{token}")
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 setup_user(operation, type = "", search = nil, user = :one)
@one = users(user)
as_admin do
permission = Permission.find_by_name("#{operation}_#{type}") || FactoryGirl.create(:permission, :name => "#{operation}_#{type}")
filter = FactoryGirl.build(:filter, :search => search)
filter.permissions = [ permission ]
role = Role.where(:name => "#{operation}_#{type}").first_or_create
role.filters = [ filter ]
role.save!
filter.role = role
filter.save!
@one.roles << role
yield(@one) if block_given?
@one.save!
end
User.current = @one
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 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].blank?
@group_id = params[:group_id]
end
SqlHelper.validate_token([@group_id])
submit_url = url_for(:controller => 'schedules', :action => 'get_group_users')
render(:partial => 'common/select_users', :layout => false, :locals => {:target_attr => :id, :submit_url => submit_url})
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 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 | 0 | Ruby | CWE-434 | Unrestricted Upload of File with Dangerous Type | The software allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | vulnerable |
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 | 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 logout(database)
auth.delete(database.to_s)
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 nodes_in_branch(branch, options={})
hg_args = ['rhlog', '--template', '{node}\n', '--rhbranch', CGI.escape(branch)]
hg_args << '--from' << CGI.escape(branch)
hg_args << '--to' << '0'
hg_args << '--limit' << options[:limit] if options[:limit]
hg(*hg_args) { |io| io.readlines.map { |e| e.chomp } }
end | 0 | Ruby | NVD-CWE-noinfo | null | null | null | vulnerable |
def test_rcptto
sock = FakeSocket.new
smtp = Net::SMTP.new 'localhost', 25
smtp.instance_variable_set :@socket, sock
assert smtp.rcptto("[email protected]").success?
assert_equal "RCPT TO:<[email protected]>\r\n", sock.write_io.string
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 __bson_load__(io)
new io.read(12).unpack('C*')
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.get_for(user_id)
SqlHelper.validate_token([user_id])
return Research.where("user_id=#{user_id}").first
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 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 | 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 set_description
Log.add_info(request, params.inspect)
return unless request.post?
if params[:id].blank?
@item = Item.new_info(0)
@item.attributes = params.require(:item).permit(Item::PERMIT_BASE)
@item.user_id = @login_user.id
@item.title = t('paren.no_title')
@item.save
else
@item = Item.find(params[:id])
@item.update_attributes(params.require(:item).permit(Item::PERMIT_BASE))
end
render(:partial => 'ajax_item_description', :layout => false)
rescue => evar
Log.add_error(request, evar)
render(:partial => 'ajax_item_description', :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 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 |
it 'returns json error' do
subject.content_type :json, 'application/json'
subject.default_error_formatter :json
subject.get '/something' do
'foo'
end
get '/something'
expect(last_response.status).to eq(406)
expect(last_response.body).to eq("{\"error\":\"The requested format 'txt' is not supported.\"}")
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 |
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 | 0 | Ruby | CWE-613 | Insufficient Session Expiration | According to WASC, "Insufficient Session Expiration is when a web site permits an attacker to reuse old session credentials or session IDs for authorization." | https://cwe.mitre.org/data/definitions/613.html | vulnerable |
def destroy_comment
Log.add_info(request, params.inspect)
return unless request.post?
comment = Comment.find(params[:comment_id])
@item = comment.item
unless @login_user.admin?(User::AUTH_ITEM) or \
comment.user_id == @login_user.id or \
@item.user_id == @login_user.id
render(:text => 'ERROR:' + t('msg.need_to_be_admin'))
return
end
comment.destroy
case @item.xtype
when Item::XTYPE_PROJECT
if comment.xtype == Comment::XTYPE_APPLY
flash[:notice] = t('msg.cancel_success')
render(:partial => 'ajax_team_apply')
else
render(:text => '')
end
else
render(:text => '')
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 "raises a connection failure exception" do
cluster.sync_server(server).should be_empty
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 add_order_set_constraint(
session, resource_set_list, force=false, autocorrect=true
)
command = [PCS, "constraint", "order"]
resource_set_list.each { |resource_set|
command << "set"
command.concat(resource_set)
}
command << '--force' if force
command << '--autocorrect' if autocorrect
stdout, stderr, retval = run_cmd(session, *command)
return retval, stderr.join(' ')
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_should_sanitize_illegal_style_properties
raw = %(display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;)
expected = %(display: block; width: 100%; height: 100%; background-color: black; background-x: center; background-y: center;)
assert_equal expected, sanitize_css(raw)
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 |
def replica_set_credentials
[ENV["MONGOHQ_REPL_USER"], ENV["MONGOHQ_REPL_PASS"]]
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 Schema string_or_io
Schema.new(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 "includes plaintext secret" do
expect(app.as_json).to include("secret" => "123123123")
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 html_postprocess(_field, html)
html
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 |
def login(database, username, password)
getnonce = Protocol::Command.new(database, getnonce: 1)
connection.write [getnonce]
result = connection.read.documents.first
raise Errors::OperationFailure.new(getnonce, result) unless result["ok"] == 1
authenticate = Protocol::Commands::Authenticate.new(database, username, password, result["nonce"])
connection.write [authenticate]
result = connection.read.documents.first
raise Errors::AuthenticationFailure.new(authenticate, result) unless result["ok"] == 1
auth[database] = [username, password]
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 test_update_valid
AuthSourceLdap.any_instance.stubs(:valid?).returns(true)
put :update, {:id => AuthSourceLdap.first, :auth_source_ldap => {:name => AuthSourceLdap.first.name} }, set_session_user
assert_redirected_to auth_source_ldaps_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 |
it "returns the number of matching document" do
users.insert(documents)
users.find(scope: scope).count.should eq 2
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 query(database, collection, selector, options = {})
if consistency == :eventual
options[:flags] ||= []
options[:flags] |= [:slave_ok]
end
with_node do |node|
node.query(database, collection, selector, options)
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 |
it "returns a new indexes instance" do
collection.indexes.should be_an_instance_of Moped::Indexes
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 needs_refresh?(time)
!@refreshed_at || @refreshed_at < time
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 write(operations)
buf = ""
operations.each do |operation|
operation.request_id = (@request_id += 1)
operation.serialize(buf)
end
@sock.write buf
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 reset
Log.add_info(request, params.inspect)
return unless request.post?
Research.delete_all
render(:text => '')
rescue => evar
Log.add_error(request, evar)
render(:text => evar.to_s)
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 login(database, username, password)
cluster.auth[database.to_s] = [username, password]
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 empty
Log.add_info(request, params.inspect)
return unless request.post?
@folder_id = params[:id]
mail_account_id = params[:mail_account_id]
SqlHelper.validate_token([@folder_id, mail_account_id])
trash_folder = MailFolder.get_for(@login_user, mail_account_id, MailFolder::XTYPE_TRASH)
mail_folder = MailFolder.find(@folder_id)
emails = (MailFolder.get_mails(mail_folder.id, @login_user) || [])
if mail_folder.id == trash_folder.id \
or mail_folder.get_parents(false).include?(trash_folder.id.to_s)
emails.each do |email|
email.destroy
end
flash[:notice] = t('msg.delete_success')
else
emails.each do |email|
email.update_attribute(:mail_folder_id, trash_folder.id)
end
flash[:notice] = t('msg.moved_to_trash')
end
get_mails
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 next_client
throw :shutdown if @shutdown
begin
servers = @servers.reject &:closed?
clients = @clients.reject &:closed?
Moped.logger.debug "replica_set: selecting on connections"
readable, _, errors = Kernel.select(servers + clients, nil, clients, @timeout)
rescue IOError, Errno::EBADF, TypeError
# Looks like we hit a bad file descriptor or closed connection.
Moped.logger.debug "replica_set: io error, retrying"
retry
end
return unless readable || errors
errors.each do |client|
client.close
@clients.delete client
end
clients, servers = readable.partition { |s| s.class == TCPSocket }
servers.each do |server|
Moped.logger.debug "replica_set: accepting new client for #{server.port}"
@clients << server.accept
end
Moped.logger.debug "replica_set: closing dead clients"
closed, open = clients.partition &:eof?
closed.each { |client| @clients.delete client }
if client = open.shift
Moped.logger.debug "replica_set: finding server for client"
server = lookup_server(client)
Moped.logger.debug "replica_set: sending client #{client.inspect} to #{server.port}"
return server, client
else
nil
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 remove(database, collection, selector, options = {})
with_node do |node|
if safe?
node.pipeline do
node.remove(database, collection, selector, options)
node.command("admin", { getlasterror: 1 }.merge(safety))
end
else
node.remove(database, collection, selector, options)
end
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 "connects and yields the primary node" do
replica_set.with_primary do |node|
node.address.should eq @primary.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 set_admin
User.current = users(:admin)
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 refresh(nodes_to_refresh = @nodes)
refreshed_nodes = []
seen = {}
# Set up a recursive lambda function for refreshing a node and it's peers.
refresh_node = ->(node) do
return if seen[node]
seen[node] = true
# Add the node to the global list of known nodes.
@nodes << node unless @nodes.include?(node)
begin
node.refresh
# This node is good, so add it to the list of nodes to return.
refreshed_nodes << node unless refreshed_nodes.include?(node)
# Now refresh any newly discovered peer nodes.
(node.peers - @nodes).each &refresh_node
rescue Errors::ConnectionFailure
# We couldn't connect to the node, so don't do anything with it.
end
end
nodes_to_refresh.each &refresh_node
refreshed_nodes.to_a
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 bulk_unread_topic_ids
topic_query = TopicQuery.new(current_user)
if inbox = params[:private_message_inbox]
filter = private_message_filter(topic_query, inbox)
topic_query.options[:limit] = false
topics = topic_query.filter_private_messages_unread(current_user, filter)
else
topics = TopicQuery.unread_filter(topic_query.joined_topic_user, staff: guardian.is_staff?).listable_topics
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
if params[:category_id]
if params[:include_subcategories]
topics = topics.where(<<~SQL, category_id: params[:category_id])
category_id in (select id FROM categories WHERE parent_category_id = :category_id) OR
category_id = :category_id
SQL
else
topics = topics.where('category_id = ?', params[:category_id])
end
end
if params[:tag_name].present?
topics = topics.joins(:tags).where("tags.name": params[:tag_name])
end
end
topics.pluck(:id)
end | 0 | Ruby | CWE-863 | Incorrect Authorization | The software performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check. This allows attackers to bypass intended access restrictions. | https://cwe.mitre.org/data/definitions/863.html | vulnerable |
it "returns only published articles" do
article = create(:article)
create(:comment, article: article)
unpublished_article = create(:article, state: "draft")
create(:comment, article: unpublished_article)
expect(described_class.published).to eq([article])
expect(described_class.bestof).to eq([article])
end | 0 | Ruby | CWE-863 | Incorrect Authorization | The software performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check. This allows attackers to bypass intended access restrictions. | https://cwe.mitre.org/data/definitions/863.html | vulnerable |
def more?
@get_more_op.cursor_id != 0
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 initialize(attribute = nil, direction = nil)
@attribute = attribute
@direction = direction || :asc
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 send an email using exim" do
Mail.defaults do
delivery_method :exim
end
mail = Mail.new do
from '[email protected]'
to '[email protected], [email protected]'
subject 'invalid RFC2822'
end
Mail::Exim.should_receive(:call).with('/usr/sbin/exim',
'-i -t -f "[email protected]"',
'[email protected] [email protected]',
mail)
mail.deliver!
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 test_update_valid
Realm.any_instance.stubs(:valid?).returns(true)
realm_id = Realm.unscoped.first.id
proxy_id = SmartProxy.unscoped.first.id
put :update, {:id => realm_id,
:realm => { :realm_proxy_id => proxy_id } }, set_session_user
assert_equal proxy_id, Realm.unscoped.find(realm_id).realm_proxy_id
assert_redirected_to realms_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 socket_for(mode)
sync unless primaries.any? || (secondaries.any? && mode == :read)
server = nil
while primaries.any? || (secondaries.any? && mode == :read)
if mode == :write || secondaries.empty?
server = primaries.sample
else
server = secondaries.sample
end
if server
socket = server.socket
socket.connect unless socket.connection
if socket.alive?
break server
else
remove server
end
end
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 receive_replies(operations)
operations.map do |operation|
read if operation.is_a?(Protocol::Query) || operation.is_a?(Protocol::GetMore)
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 self.get_childs(klass, node_id, recursive, ret_obj)
SqlHelper.validate_token([node_id])
array = []
if recursive
tree = klass.get_tree(Hash.new, nil, node_id)
return array if tree.nil?
tree.each do |parent_id, childs|
if ret_obj
array |= childs
else
childs.each do |node|
node_id = node.id.to_s
array << node_id unless array.include?(node_id)
end
end
end
else
nodes = klass.where("parent_id=#{node_id}").order('xorder ASC, id ASC').to_a
if ret_obj
array = nodes
else
nodes.each do |node|
array << node.id.to_s
end
end
end
return array
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 self.get_group_value(group_id, category, key)
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
return setting.xvalue unless setting.nil?
return nil
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 "has an empty list of dynamic seeds" do
cluster.dynamic_seeds.should be_empty
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 test_attr_wrapper
assert_equal("<p strange=*attrs*></p>\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*'))
assert_equal("<p escaped='quo\"te'></p>\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"'))
assert_equal("<p escaped=\"quo'te\"></p>\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"'))
assert_equal("<p escaped=\"q'uo"te\"></p>\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"'))
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"', :format => :xhtml))
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 |
def kill
@node.kill_cursors [@cursor_id]
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 right response' do
get "/session/email-login/adasdad"
expect(response.status).to eq(200)
expect(CGI.unescapeHTML(response.body)).to match(
I18n.t('email_login.invalid_token')
)
end | 0 | Ruby | NVD-CWE-noinfo | null | null | null | vulnerable |
def self.get_for(user, mail_account_id, xtype)
return nil if user.nil? or mail_account_id.blank?
if user.kind_of?(User)
user_id = user.id
else
user_id = user.to_s
end
SqlHelper.validate_token([user_id, mail_account_id, xtype])
con = []
con << "(user_id=#{user_id.to_i})"
con << "(mail_account_id=#{mail_account_id.to_i})"
con << "(xtype='#{xtype}')"
return MailFolder.where(con.join(' and ')).first
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 add_colocation_constraint(
session, resourceA, resourceB, score, force=false, autocorrect=true
)
if score == "" or score == nil
score = "INFINITY"
end
command = [
PCS, "constraint", "colocation", "add", resourceA, resourceB, score
]
command << '--force' if force
command << '--autocorrect' if autocorrect
stdout, stderr, retval = run_cmd(session, *command)
return retval, stderr.join(' ')
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 delete_map
Log.add_info(request, params.inspect)
return unless request.post?
group_id = params[:group_id]
SqlHelper.validate_token([group_id])
@office_map = OfficeMap.get_for_group(group_id, false)
begin
@office_map.destroy
rescue => evar
Log.add_error(request, evar)
end
@office_map = OfficeMap.get_for_group(group_id, false)
flash[:notice] = t('msg.delete_success')
render(:partial => 'groups/ajax_group_map', :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 |
it 'returns a list of all private messages that has been archived' do
UserArchivedMessage.archive!(user_2.id, private_message)
GroupArchivedMessage.archive!(user_2.id, group_message)
topics = TopicQuery.new(nil).list_private_messages_all_archive(user_2).topics
expect(topics).to contain_exactly(private_message, group_message)
end | 0 | Ruby | CWE-863 | Incorrect Authorization | The software performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check. This allows attackers to bypass intended access restrictions. | https://cwe.mitre.org/data/definitions/863.html | vulnerable |
def legal?(string)
string.to_s =~ /^[0-9a-f]{24}$/i ? true : false
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 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 | 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 |
it "drops all indexes" do
indexes.create name: 1
indexes.create age: 1
indexes.drop
indexes[name: 1].should be_nil
indexes[age: 1].should be_nil
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 delete_attachment
Log.add_info(request, params.inspect)
return unless request.post?
begin
attachment = MailAttachment.find(params[:attachment_id])
@email = Email.find(params[:id])
if attachment.email_id == @email.id
attachment.destroy
update_attrs = ActionController::Parameters.new({updated_at: Time.now})
if @email.status == Email::STATUS_TEMPORARY
update_attrs[:status] = Email::STATUS_DRAFT
end
@email.update_attributes(update_attrs.permit(Email::PERMIT_BASE))
end
rescue => evar
Log.add_error(request, evar)
end
render(:partial => 'ajax_mail_attachments', :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 each
cursor = Cursor.new(session, operation)
cursor.to_enum.tap do |enum|
enum.each do |document|
yield document
end if block_given?
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 initialize(session)
@session = session
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 spree_current_user
@spree_current_user ||= Spree.user_class.find_by(id: doorkeeper_token.resource_owner_id) if doorkeeper_token
end | 0 | Ruby | CWE-613 | Insufficient Session Expiration | According to WASC, "Insufficient Session Expiration is when a web site permits an attacker to reuse old session credentials or session IDs for authorization." | https://cwe.mitre.org/data/definitions/613.html | vulnerable |
def remove_role(what, role)
check_write_access!
if what.kind_of? Group
rel = self.project_group_role_relationships.where(bs_group_id: what.id)
else
rel = self.project_user_role_relationships.where(bs_user_id: what.id)
end
rel = rel.where(role_id: role.id) if role
self.transaction do
rel.delete_all
write_to_backend
end
end | 1 | Ruby | CWE-275 | Permission Issues | Weaknesses in this category are related to improper assignment or handling of permissions. | https://cwe.mitre.org/data/definitions/275.html | safe |
def test_new_attribute_interpolation
assert_equal("<a href='12'>bar</a>\n", render('%a(href="1#{1 + 1}") bar'))
assert_equal("<a href='2: 2, 3: 3'>bar</a>\n", render(%q{%a(href='2: #{1 + 1}, 3: #{foo}') bar}, :locals => {:foo => 3}))
assert_equal(%Q{<a href='1\#{1 + 1}'>bar</a>\n}, render('%a(href="1\#{1 + 1}") bar'))
end
def test_truthy_new_attributes
assert_equal("<a href='href'>bar</a>\n", render("%a(href) bar", :format => :xhtml))
assert_equal("<a bar='baz' href>bar</a>\n", render("%a(href bar='baz') bar", :format => :html5))
assert_equal("<a href>bar</a>\n", render("%a(href=true) bar"))
assert_equal("<a>bar</a>\n", render("%a(href=false) bar"))
end
def test_new_attribute_parsing
assert_equal("<a a2='b2'>bar</a>\n", render("%a(a2=b2) bar", :locals => {:b2 => 'b2'}))
assert_equal(%Q{<a a='foo"bar'>bar</a>\n}, render(%q{%a(a="#{'foo"bar'}") bar})) #'
assert_equal(%Q{<a a="foo'bar">bar</a>\n}, render(%q{%a(a="#{"foo'bar"}") bar})) #'
assert_equal(%Q{<a a='foo"bar'>bar</a>\n}, render(%q{%a(a='foo"bar') bar}))
assert_equal(%Q{<a a="foo'bar">bar</a>\n}, render(%q{%a(a="foo'bar") bar}))
assert_equal("<a a:b='foo'>bar</a>\n", render("%a(a:b='foo') bar"))
assert_equal("<a a='foo' b='bar'>bar</a>\n", render("%a(a = 'foo' b = 'bar') bar"))
assert_equal("<a a='foo' b='bar'>bar</a>\n", render("%a(a = foo b = bar) bar", :locals => {:foo => 'foo', :bar => 'bar'}))
assert_equal("<a a='foo'>(b='bar')</a>\n", render("%a(a='foo')(b='bar')"))
assert_equal("<a a='foo)bar'>baz</a>\n", render("%a(a='foo)bar') baz"))
assert_equal("<a a='foo'>baz</a>\n", render("%a( a = 'foo' ) baz"))
end
def test_new_attribute_escaping
assert_equal(%Q{<a a='foo " bar'>bar</a>\n}, render(%q{%a(a="foo \" bar") bar}))
assert_equal(%Q{<a a='foo \\" bar'>bar</a>\n}, render(%q{%a(a="foo \\\\\" bar") bar})) | 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 |
it "delegates to the current database" do
database = mock(Moped::Database)
session.should_receive(:current_database).and_return(database)
database.should_receive(:drop)
session.drop
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 test_html5_data_attributes_without_hyphenation
assert_equal("<div data-author_id='123' data-biz='baz' data-foo='bar'></div>\n",
render("%div{:data => {:author_id => 123, :foo => 'bar', :biz => 'baz'}}",
:hyphenate_data_attrs => false))
assert_equal("<div data-one_plus_one='2'></div>\n",
render("%div{:data => {:one_plus_one => 1+1}}",
:hyphenate_data_attrs => false))
assert_equal("<div data-foo='Here's a \"quoteful\" string.'></div>\n",
render(%{%div{:data => {:foo => %{Here's a "quoteful" string.}}}}, | 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 |
def move_in_team_folder
Log.add_info(request, params.inspect)
return unless request.post?
@item = Item.find(params[:id])
team_folder = @item.team.get_team_folder
@item.update_attribute(:folder_id, team_folder.id)
flash[:notice] = t('msg.move_success')
render(:partial => 'ajax_move_in_team_folder', :layout => false)
rescue => evar
Log.add_error(request, evar)
render(:partial => 'ajax_move_in_team_folder', :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 call(env)
return @app.call(env) unless env['PATH_INFO'].start_with? "#{@bus.base_route}message-bus/_diagnostics"
route = env['PATH_INFO'].split("#{@bus.base_route}message-bus/_diagnostics")[1]
if @bus.is_admin_lookup.nil? || [email protected]_admin_lookup.call(env)
return [403, {}, ['not allowed']]
end
return index unless route
if route == '/discover'
user_id = @bus.user_id_lookup.call(env)
@bus.publish('/_diagnostics/discover', user_id: user_id)
return [200, {}, ['ok']]
end
if route =~ /^\/hup\//
hostname, pid = route.split('/hup/')[1].split('/')
@bus.publish('/_diagnostics/hup', hostname: hostname, pid: pid.to_i)
return [200, {}, ['ok']]
end
asset = route.split('/assets/')[1]
if asset && !asset !~ /\//
content = asset_contents(asset)
return [200, { 'Content-Type' => 'application/javascript;charset=UTF-8' }, [content]]
end
[404, {}, ['not found']]
end | 0 | Ruby | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The software uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the software does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. | https://cwe.mitre.org/data/definitions/22.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-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)
return unless request.post?
if params[:check_user].nil?
list
render(:action => 'list')
return
end
count = 0
params[:check_user].each do |user_id, value|
if value == '1'
SqlHelper.validate_token([user_id])
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 | 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 "drops all indexes" do
indexes.create name: 1
indexes.create age: 1
indexes.drop
indexes[name: 1].should be_nil
indexes[age: 1].should be_nil
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(database, collection, documents)
with_node do |node|
if safe?
node.pipeline do
node.insert(database, collection, documents)
node.command("admin", { getlasterror: 1 }.merge(safety))
end
else
node.insert(database, collection, documents)
end
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 initialize
# Generate and cache 3 bytes of identifying information from the current
# machine.
@machine_id = Digest::MD5.digest(Socket.gethostname).unpack("N")[0]
@mutex = Mutex.new
@counter = 0
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 fast_forward_to_first_boundary
loop do
read_buffer = @io.gets
break if read_buffer == full_boundary
raise EOFError, "bad content body" if read_buffer.nil?
end
end | 0 | Ruby | CWE-119 | Improper Restriction of Operations within the Bounds of a Memory Buffer | The software performs operations on a memory buffer, but it can read from or write to a memory location that is outside of the intended boundary of the buffer. | https://cwe.mitre.org/data/definitions/119.html | vulnerable |
it "has an empty list of servers" do
cluster.servers.should be_empty
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 filename_extension
File.extname(@name.to_s.downcase).sub(/^\./, '').to_sym
end | 1 | 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 | safe |
def to_bson
repair!(@data) if defined?(@data)
@raw_data ||= @@generator.next
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 ismaster_command?(incoming_message)
data = StringIO.new(incoming_message)
data.read(20) # header and flags
data.gets("\x00") # collection name
data.read(8) # skip/limit
selector = Moped::BSON::Document.deserialize(data)
selector == { "ismaster" => 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 add_acl_role_remote(params, request, session)
if not allowed_for_local_cluster(session, Permissions::GRANT)
return 403, 'Permission denied'
end
retval = add_acl_role(session, params["name"], params["description"])
if retval == ""
return [200, "Successfully added ACL role"]
else
return [
400,
retval.include?("cib_replace failed") ? "Error adding ACL role" : retval
]
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 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 | 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 getResourceAgents(session)
resource_agent_list = {}
stdout, stderr, retval = run_cmd(session, PCS, "resource", "list", "--nodesc")
if retval != 0
$logger.error("Error running 'pcs resource list --nodesc")
$logger.error(stdout + stderr)
return {}
end
agents = stdout
agents.each { |a|
ra = ResourceAgent.new
ra.name = a.chomp
resource_agent_list[ra.name] = ra
}
return resource_agent_list
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 |
Subsets and Splits