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 get_mail_attachments Log.add_info(request, params.inspect) email_id = params[:id] email = Email.find(email_id) if email.nil? or email.user_id != @login_user.id render(:text => '') return end download_name = "mail_attachments#{email.id}.zip" zip_file = email.zip_attachments(params[:enc]) if zip_file.nil? send_data('', :type => 'application/octet-stream;', :disposition => 'attachment;filename="'+download_name+'"') else filepath = zip_file.path send_file(filepath, :filename => download_name, :stream => true, :disposition => 'attachment') 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 from_string(string) raise Errors::InvalidObjectId.new(string) unless legal?(string) data = [] 12.times { |i| data << string[i*2, 2].to_i(16) } new data 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
it "yields all documents in the cursor" do cursor = Moped::Cursor.allocate cursor.stub(:to_enum).and_return([1, 2].to_enum) Moped::Cursor.stub(new: cursor) query.to_a.should eq [1, 2] 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.from_yaml(input) Gem.load_yaml input = normalize_yaml_input input spec = YAML.load input if spec && spec.class == FalseClass then raise Gem::EndOfYAMLException end unless Gem::Specification === spec then raise Gem::Exception, "YAML data doesn't evaluate to gem specification" end spec.specification_version ||= NONEXISTENT_SPECIFICATION_VERSION spec.reset_nil_attributes_to_default spec end
0
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
vulnerable
it "returns the document" do session.simple_query(query).should eq(a: 1) 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
it "changes the fields returned" do users.insert(documents) users.find(scope: scope).select(_id: 0).to_a.should eq documents 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_local Log.add_info(request, params.inspect) return unless request.post? begin Item.find(params[:id]).destroy rescue end # Get $Templates and its sub folders to update partial division. @tmpl_folder, @tmpl_local_folder = TemplatesHelper.get_tmpl_subfolder(TemplatesHelper::TMPL_LOCAL) render(:partial => 'ajax_local', :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 check_owner return if (params[:id].blank? or @login_user.nil?) mail_filter = MailFilter.find(params[:id]) if !@login_user.admin?(User::AUTH_MAIL) and mail_filter.mail_account.user_id != @login_user.id Log.add_check(request, '[check_owner]'+request.to_s) flash[:notice] = t('msg.need_to_be_owner') redirect_to(:controller => 'desktop', :action => 'show') end end
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 the collection" do result = session[:users].drop result["ns"].should eq "moped_test.users" 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 sanitize_string(host) if host.start_with?(".") /\A([a-z0-9-]+\.)?#{Regexp.escape(host[1..-1])}\z/i else /\A#{Regexp.escape host}\z/i end end
1
Ruby
CWE-601
URL Redirection to Untrusted Site ('Open Redirect')
A web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect. This simplifies phishing attacks.
https://cwe.mitre.org/data/definitions/601.html
safe
it "removes all matching documents" do users.insert(documents) users.find(scope: scope).remove_all users.find(scope: scope).count.should eq 0 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.destroy_by_user(user_id, add_con=nil) SqlHelper.validate_token([user_id]) con = "user_id=#{user_id}" con << " and (#{add_con})" unless add_con.nil? or add_con.empty? mail_accounts = MailAccount.where(con).to_a mail_accounts.each do |mail_account| mail_account.destroy end end
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 create_q_page Log.add_info(request, params.inspect) return unless request.post? @tmpl_folder, @tmpl_q_folder = TemplatesHelper.get_tmpl_subfolder(TemplatesHelper::TMPL_RESEARCH) unless @tmpl_q_folder.nil? @items = Folder.get_items_admin(@tmpl_q_folder.id, 'xorder ASC') if [email protected]? and @items.length >= ResearchesHelper::MAX_PAGES flash[:notice] = 'ERROR:' + t('research.max_pages') render(:partial => 'ajax_q_page', :layout => false) return end item = Item.new_research(@tmpl_q_folder.id) item.title = t('research.new_page') item.user_id = 0 item.save! @items << item else Log.add_error(request, nil, '/'+TemplatesHelper::TMPL_ROOT+'/'+TemplatesHelper::TMPL_RESEARCH+' NOT found!') end render(:partial => 'ajax_q_page', :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 "recognizes and generates #destroy" do { :delete => "/users/1" }.should route_to(:controller => "users", :action => "destroy", :id => "1") 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 create exists = true if params.has_key?(:inflated_object) params[:name] ||= params[:inflated_object].name params[:admin] ||= params[:inflated_object].admin end # We can only create clients if we're the admin or the validator. # But only allow creating admin clients if we're already an admin. if params[:admin] == true && @auth_user.admin != true raise Forbidden, "You are not allowed to take this action." end begin Chef::ApiClient.cdb_load(params[:name]) rescue Chef::Exceptions::CouchDBNotFound exists = false end raise Conflict, "Client already exists" if exists @client = Chef::ApiClient.new @client.name(params[:name]) @client.admin(params[:admin]) if params[:admin] @client.create_keys @client.cdb_save self.status = 201 headers['Location'] = absolute_url(:client, @client.name) display({ :uri => absolute_url(:client, @client.name), :private_key => @client.private_key }) 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 call(exception, locale, key, options) if exception.is_a?(MissingTranslation) # # TODO: this block is to be replaced by `exception.message` when # rescue_format is removed if options[:rescue_format] == :html if @rescue_format_deprecation $stderr.puts "[DEPRECATED] I18n's :recue_format option will be removed from a future release. All exception messages will be plain text. If you need the exception handler to return an html format please set or pass a custom exception handler." @rescue_format_deprecation = true end exception.html_message else exception.message end elsif exception.is_a?(Exception) raise exception else throw :exception, exception end 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 read_config(self, config, **kwargs): self.recaptcha_private_key = config.get("recaptcha_private_key") self.recaptcha_public_key = config.get("recaptcha_public_key") self.enable_registration_captcha = config.get( "enable_registration_captcha", False ) self.recaptcha_siteverify_api = config.get( "recaptcha_siteverify_api", "https://www.recaptcha.net/recaptcha/api/siteverify", ) self.recaptcha_template = self.read_templates( ["recaptcha.html"], autoescape=True )[0]
0
Ruby
CWE-74
Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
The software constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
https://cwe.mitre.org/data/definitions/74.html
vulnerable
def check_owner return if (params[:id].nil? or params[:id].empty? or @login_user.nil?) mail_filter = MailFilter.find(params[:id]) if !@login_user.admin?(User::AUTH_MAIL) and mail_filter.mail_account.user_id != @login_user.id Log.add_check(request, '[check_owner]'+request.to_s) flash[:notice] = t('msg.need_to_be_owner') redirect_to(:controller => 'desktop', :action => 'show') end end
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 return a second factor prompt' do get "/session/email-login/#{email_token.token}" expect(response.status).to eq(200) response_body = CGI.unescapeHTML(response.body) expect(response_body).to include(I18n.t( "login.second_factor_title" )) expect(response_body).to_not 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
def self.connect(host, port, timeout) Timeout::timeout(timeout) do new(host, port).tap do |sock| sock.set_encoding 'binary' end 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 spoofed? if has_name? && has_extension? && media_type_mismatch? && mapping_override_mismatch? Paperclip.log("Content Type Spoof: Filename #{File.basename(@name)} (#{supplied_content_type} from Headers, #{content_types_from_name} from Extension), content type discovered from file command: #{calculated_content_type}. See documentation to allow this combination.") true else false end 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 refresh info = command "admin", ismaster: 1 @refreshed_at = Time.now primary = true if info["ismaster"] secondary = true if info["secondary"] peers = [] peers.push info["primary"] if info["primary"] peers.concat info["hosts"] if info["hosts"] peers.concat info["passives"] if info["passives"] peers.concat info["arbiters"] if info["arbiters"] @peers = peers.map { |peer| Node.new(peer) } @primary, @secondary = primary, secondary if !primary && Threaded.executing?(:ensure_primary) raise Errors::ReplicaSetReconfigured, "#{inspect} is no longer the primary node." 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_node_utilization(params, reqest, session) unless allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end unless params[:node] and params[:name] return 400, 'node and name are required' end node = params[:node] name = params[:name] value = params[:value] || '' _, stderr, retval = run_cmd( session, PCS, 'node', 'utilization', node, "#{name}=#{value}" ) if retval != 0 return [400, "Unable to set utilization '#{name}=#{value}' for node " + "'#{res_id}': #{stderr.join('')}" ] end return 200 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 ensure_primary Threaded.begin :ensure_primary yield ensure Threaded.end :ensure_primary
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 update_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, true) params[:office_map].delete(:group_id) @office_map.update_attributes(params.require(:office_map).permit(OfficeMap::PERMIT_BASE)) params.delete(:office_map) flash[:notice] = t('msg.update_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
def test_nest get :nest, {:id => hostgroups(:common).id}, set_session_user assert_template 'new' 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 "inserts a single document" do document = { "_id" => Moped::BSON::ObjectId.new, "scope" => scope } session[:users].insert(document) session[:users].find(document).one.should eq document 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 "should return :file if the URI protocol is set to 'file'" do @request.expects(:protocol).returns "file" @object.select(@request).should == :file 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 self.get_by_email(mail_addr, user, book=Address::BOOK_BOTH) SqlHelper.validate_token([mail_addr]) email_con = [] email_con.push("(email1='#{mail_addr}')") email_con.push("(email2='#{mail_addr}')") email_con.push("(email3='#{mail_addr}')") con = [] con.push('('+email_con.join(' or ')+')') con.push(AddressbookHelper.get_scope_condition_for(user, book)) return Address.where(con.join(' and ')).to_a 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_folders_order Log.add_info(request, params.inspect) @folder_id = params[:id] SqlHelper.validate_token([@folder_id]) if @folder_id == '0' @folders = MailFolder.get_account_roots_for(@login_user) else mail_folder = MailFolder.find(@folder_id) if mail_folder.user_id == @login_user.id @folders = MailFolder.get_childs(@folder_id, false, true) end end render(:partial => 'ajax_folders_order', :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 generate(type, str) case type when :md5 attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp! when :sha attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp! when :ssha srand; salt = SecureRandom.random_bytes(16) attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp! else raise Net::LDAP::HashTypeUnsupportedError, "Unsupported password-hash type (#{type})" end
1
Ruby
CWE-916
Use of Password Hash With Insufficient Computational Effort
The software generates a hash for a password, but it uses a scheme that does not provide a sufficient level of computational effort that would make password cracking attacks infeasible or expensive.
https://cwe.mitre.org/data/definitions/916.html
safe
it "returns an enumerator" do cursor = mock(Moped::Cursor) Moped::Cursor.stub(new: cursor) query.each.should be_a Enumerator 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 redirect_url return "/" unless member_login_node member_login_node.redirect_url || "/" end
0
Ruby
CWE-601
URL Redirection to Untrusted Site ('Open Redirect')
A web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect. This simplifies phishing attacks.
https://cwe.mitre.org/data/definitions/601.html
vulnerable
def remote_node_available(params, request, session) if (not ISRHEL6 and File.exist?(Cfgsync::CorosyncConf.file_path)) or (ISRHEL6 and File.exist?(Cfgsync::ClusterConf.file_path)) or File.exist?("/var/lib/pacemaker/cib/cib.xml") return JSON.generate({:node_available => false}) end return JSON.generate({:node_available => true}) 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 "removes all matching documents" do session.should_receive(:with, :consistency => :strong). and_yield(session) session.should_receive(:execute).with do |delete| delete.flags.should eq [] delete.selector.should eq query.operation.selector end query.remove_all 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 "drops the current database" do session.with(database: "moped_test_2") do |session| session.drop.should eq("dropped" => "moped_test_2", "ok" => 1) 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 auth_seeds [ENV["MONGOHQ_SINGLE_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 self.get_using_size(mail_account_id, add_con=nil) SqlHelper.validate_token([mail_account_id]) con = [] con << "(mail_account_id=#{mail_account_id.to_i})" con << "(#{add_con})" unless add_con.nil? or add_con.empty? return (Email.count_by_sql("select SUM(size) from emails where #{con.join(' and ')}") || 0) 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 email_login raise Discourse::NotFound if !SiteSetting.enable_local_logins_via_email second_factor_token = params[:second_factor_token] second_factor_method = params[:second_factor_method].to_i token = params[:token] valid_token = !!EmailToken.valid_token_format?(token) user = EmailToken.confirmable(token)&.user if valid_token && user&.totp_enabled? if !second_factor_token.present? @second_factor_required = true @backup_codes_enabled = true if user&.backup_codes_enabled? return render layout: 'no_ember' elsif !user.authenticate_second_factor(second_factor_token, second_factor_method) RateLimiter.new(nil, "second-factor-min-#{request.remote_ip}", 3, 1.minute).performed! @error = I18n.t('login.invalid_second_factor_code') return render layout: 'no_ember' end end if user = EmailToken.confirm(token) if login_not_approved_for?(user) @error = login_not_approved[:error] elsif payload = login_error_check(user) @error = payload[:error] else log_on_user(user) return redirect_to path("/") end else @error = I18n.t('email_login.invalid_token') end render layout: 'no_ember' end
0
Ruby
NVD-CWE-noinfo
null
null
null
vulnerable
it "should choose :rest when a server is specified" do @request.stubs(:protocol).returns "puppet" @request.expects(:server).returns "foo" @object.select(@request).should == :rest 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 check_owner return if (params[:id].blank? or @login_user.nil?) address = Address.find(params[:id]) if !@login_user.admin?(User::AUTH_ADDRESSBOOK) and address.owner_id != @login_user.id Log.add_check(request, '[check_owner]'+request.to_s) flash[:notice] = t('msg.need_to_be_owner') redirect_to(:controller => 'desktop', :action => 'show') end end
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 down? @down_at 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_project_type(project_type_name) check_write_access! mytype = DbProjectType.find_by_name(project_type_name) return false unless mytype self.type_id = mytype.id self.save! return true 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
it "sets the current database" do session.should_receive(:set_current_database).with(:admin) session.use :admin 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 sanitize_key(key) case key when Symbol then "--#{key.to_s.tr("_", "-")}" else key end
0
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
vulnerable
def end(name) stack(name).pop 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 send_local_configs_to_nodes( session, nodes, force=false, clear_local_permissions=false ) configs = Cfgsync::get_configs_local(true) if clear_local_permissions pcs_config = PCSConfig.new(configs[Cfgsync::PcsdSettings.name].text()) pcs_config.permissions_local = Permissions::PermissionsSet.new([]) configs[Cfgsync::PcsdSettings.name].text = pcs_config.text() end publisher = Cfgsync::ConfigPublisher.new( session, configs.values(), nodes, $cluster_name ) return publisher.send(force) 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 redirect_back_or_default(default, options={}) back_url = params[:back_url].to_s if back_url.present? begin uri = URI.parse(back_url) # do not redirect user to another host or to the login or register page if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) redirect_to(back_url) return end rescue URI::InvalidURIError logger.warn("Could not redirect to invalid URL #{back_url}") # redirect to default end elsif options[:referer] redirect_to_referer_or default return end redirect_to default false 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 generate(time, inc = 0) pid = Process.pid % 0xFFFF [ time >> 24 & 0xFF, # 4 bytes time (network order) time >> 16 & 0xFF, time >> 8 & 0xFF, time & 0xFF, @machine_id[0], # 3 bytes machine @machine_id[1], @machine_id[2], pid >> 8 & 0xFF, # 2 bytes process id pid & 0xFF, inc >> 16 & 0xFF, # 3 bytes increment inc >> 8 & 0xFF, inc & 0xFF, ] 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 remove_acl_permission(session, acl_perm_id) stdout, stderror, retval = run_cmd( session, PCS, "acl", "permission", "delete", acl_perm_id.to_s ) if retval != 0 if stderror.empty? return "Error removing permission" 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 "removes the first matching document" do users.insert(documents) users.find(scope: scope).remove users.find(scope: scope).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 "memoizes the database" do database = session.current_database session.current_database.should equal(database) 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 verify_signature(string, signature) if signature.nil? fail InvalidSignature, "missing \"signature\" param" elsif signature != generate_signature(string) fail InvalidSignature, "provided signature does not match the calculated signature" end end
0
Ruby
CWE-208
Observable Timing Discrepancy
Two separate operations in a product require different amounts of time to complete, in a way that is observable to an actor and reveals security-relevant information about the state of the product, such as whether a particular operation was successful or not.
https://cwe.mitre.org/data/definitions/208.html
vulnerable
def remove_constraint_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end if params[:constraint_id] retval = remove_constraint(session, params[:constraint_id]) if retval == 0 return "Constraint #{params[:constraint_id]} removed" else return [400, "Error removing constraint: #{params[:constraint_id]}"] end else return [400,"Bad Constraint Options"] 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 setup FactoryGirl.create(:host, :location => 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 render_notification(notification) uniqueid = notification[:uniqueid] data = convert_to_hash(notification[:data]) # In case data[:name] is invalid data[:email] = User.find(data[:user_id]).email case data[:type] when /comment/ then comment_link(uniqueid, data) when /accepted_ally_request/ then accepted_ally_link(uniqueid, data) when /new_ally_request/ then new_ally_request_link(uniqueid, data) when /group/ then group_link(uniqueid, data) when /meeting/ then meeting_link(uniqueid, data) end
0
Ruby
NVD-CWE-Other
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
https://nvd.nist.gov/vuln/categories
vulnerable
def process # We don't want any tracking back in the fs. Unlikely, but there # you go. if host =~ Regexp.union(/[#{SEPARATOR}]/, /\A\.\.?\Z/) raise ArgumentError, "Invalid node name #{host.inspect}" end dir = File.join(Puppet[:reportdir], host) if ! FileTest.exists?(dir) FileUtils.mkdir_p(dir) FileUtils.chmod_R(0750, dir) end # Now store the report. now = Time.now.gmtime name = %w{year month day hour min}.collect do |method| # Make sure we're at least two digits everywhere "%02d" % now.send(method).to_s end.join("") + ".yaml" file = File.join(dir, name) f = Tempfile.new(name, dir) begin begin f.chmod(0640) f.print to_yaml ensure f.close end FileUtils.mv(f.path, file) rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.warning "Could not write report for #{host} at #{file}: #{detail}" end # Only testing cares about the return value file end
1
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
safe
def get_project_application(item_id) SqlHelper.validate_token([item_id]) con = "(item_id=#{item_id}) and (user_id=#{self.id}) and (xtype='#{Comment::XTYPE_APPLY}')" begin comment = Comment.where(con).first rescue end return comment 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_group_users Log.add_info(request, params.inspect) @group_id = nil if !params[:thetisBoxSelKeeper].nil? @group_id = params[:thetisBoxSelKeeper].split(':').last elsif !params[:group_id].nil? and !params[:group_id].empty? @group_id = params[:group_id] end submit_url = url_for(:controller => 'desktop', :action => 'get_group_users') render(:partial => 'common/select_users', :layout => false, :locals => {:target_attr => :id, :submit_url => submit_url}) end
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 remote_pcsd_restart(params, request, session) pcsd_restart() return [200, 'success'] 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 "returns an enumerator" do cursor = mock(Moped::Cursor) Moped::Cursor.stub(new: cursor) query.each.should be_a Enumerator 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 drop_on_exit Log.add_info(request, params.inspect) return unless request.post? SqlHelper.validate_token([params[:id]]) unless @login_user.nil? Location.destroy(params[:id]) end render(:text => 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 destroy Log.add_info(request, params.inspect) return unless request.post? if params[:check_filter].nil? list render(:action => 'list', :layout => !request.xhr?) return end count = 0 params[:check_filter].each do |filter_id, value| if value == '1' begin filter = MailFilter.find(filter_id) filter.destroy if filter.editable?(@login_user) rescue => evar filter = nil Log.add_error(request, evar) end count += 1 end end flash[:notice] = t('address.deleted', :count => count) list render(:action => 'list', :layout => !request.xhr?) 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_id) SqlHelper.validate_token([user_id]) return Research.where("user_id=#{user_id.to_i}").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 insert(database, collection, documents) process Protocol::Insert.new(database, collection, documents) 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 _marshal(val, options) yield marshal?(options) ? Marshal.dump(val) : val end
0
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
vulnerable
def set_sync_options(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end options = [ 'sync_thread_pause', 'sync_thread_resume', 'sync_thread_disable', 'sync_thread_enable', ] if params.keys.count { |key| options.include?(key) } != 1 return [400, 'Exactly one option has to be specified'] end if params['sync_thread_disable'] if Cfgsync::ConfigSyncControl.sync_thread_disable($semaphore_cfgsync) return 'sync thread disabled' else return [400, 'sync thread disable error'] end end if params['sync_thread_enable'] if Cfgsync::ConfigSyncControl.sync_thread_enable() return 'sync thread enabled' else return [400, 'sync thread enable error'] end end if params['sync_thread_resume'] if Cfgsync::ConfigSyncControl.sync_thread_resume() return 'sync thread resumed' else return [400, 'sync thread resume error'] end end if params['sync_thread_pause'] if Cfgsync::ConfigSyncControl.sync_thread_pause( $semaphore_cfgsync, params['sync_thread_pause'] ) return 'sync thread paused' else return [400, 'sync thread pause error'] end end return [400, 'Exactly one option has to be specified'] 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 week Log.add_info(request, params.inspect) date_s = params[:date] if date_s.nil? or date_s.empty? @date = Date.today else @date = Date.parse(date_s) end params[:display] = 'week' 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(database, collection, selector, change, options = {}) with_node do |node| if safe? node.pipeline do node.update(database, collection, selector, change, options) node.command("admin", { getlasterror: 1 }.merge(safety)) end else node.update(database, collection, selector, change, 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
def add_acl_role(session, name, description) cmd = [PCS, "acl", "role", "create", name.to_s] if description.to_s != "" cmd << "description=#{description.to_s}" end stdout, stderror, retval = run_cmd(session, *cmd) if retval != 0 return stderror.join("\n").strip 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
def self.save_sync_new_version(config, nodes, cluster_name, fetch_on_conflict, tokens={}) if not cluster_name or cluster_name.empty? # we run on a standalone host, no config syncing config.version += 1 config.save() return true, {} else # we run in a cluster so we need to sync the config publisher = ConfigPublisher.new( PCSAuth.getSuperuserSession(), [config], nodes, cluster_name, tokens ) old_configs, node_responses = publisher.publish() if old_configs.include?(config.class.name) if fetch_on_conflict fetcher = ConfigFetcher.new( PCSAuth.getSuperuserSession(), [config.class], nodes, cluster_name ) cfgs_to_save, _ = fetcher.fetch() cfgs_to_save.each { |cfg_to_save| cfg_to_save.save() if cfg_to_save.class == config.class } end return false, node_responses end return true, node_responses 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 simple_query(query) query.limit = -1 query(query).documents.first 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 destroy Log.add_info(request, params.inspect) return unless request.post? begin Item.destroy(params[:id]) rescue => evar Log.add_error(request, evar) end if params[:from_action].nil? render(:text => params[:id]) else flash[:notice] = t('msg.delete_success') self.send(params[:from_action]) 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 test_update_invalid put :update, {:id => Hostgroup.first, :hostgroup => { :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 cluster_enable(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'cluster_enable', true ) else if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end success = enable_cluster(session) if not success return JSON.generate({"error" => "true"}) end return "Cluster Enabled" 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 copy Log.add_info(request, params.inspect) return unless request.post? tmpl_id = params[:thetisBoxSelKeeper].split(':').last tmpl_item = Item.find(tmpl_id) item = tmpl_item.copy(@login_user.id, @login_user.get_my_folder.id) if item.public != false item.update_attribute(:public, false) end redirect_to(:controller => 'items', :action => 'edit', :id => item.id) rescue => evar Log.add_error(request, evar) redirect_to(:controller => 'items', :action => 'new') 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 escape_for_shell(str) # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? str = str.dup # Process as a single byte sequence because not all shell # implementations are multibyte aware. str.gsub!(/([^A-Za-z0-9_\s\+\-.,:\/@\n])/n, "\\\\\\1") # A LF cannot be escaped with a backslash because a backslash + LF # combo is regarded as line continuation and simply ignored. str.gsub!(/\n/, "'\n'") return str 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 "should reject a wildcard subject" do @request.content.stubs(:subject). returns(OpenSSL::X509::Name.new([["CN", "*.local"]])) expect { @ca.sign(@name) }.to raise_error( Puppet::SSL::CertificateAuthority::CertificateSigningError, /subject contains a wildcard/ ) 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
def self.find_term(user_id, start_date, end_date) SqlHelper.validate_token([user_id]) start_s = start_date.strftime(Schedule::SYS_DATE_FORM) end_s = end_date.strftime(Schedule::SYS_DATE_FORM) con = "(user_id=#{user_id}) and (date >= '#{start_s}') and (date <= '#{end_s}')" ary = Timecard.where(con).order('date ASC').to_a timecards_h = Hash.new unless ary.nil? ary.each do |timecard| timecards_h[timecard.date.strftime(Schedule::SYS_DATE_FORM)] = timecard end end return timecards_h 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 "should escape evil haxxor attemptes" do Mail.defaults do delivery_method :exim, :arguments => nil end mail = Mail.new do from '"foo\";touch /tmp/PWNED;\""@blah.com' to '[email protected]' subject 'invalid RFC2822' end Mail::Exim.should_receive(:call).with('/usr/sbin/exim', "-f \"\\\"foo\\\\\\\"\\;touch /tmp/PWNED\\;\\\\\\\"\\\"@blah.com\"", '[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 kill_cursors(cursor_ids) process Protocol::KillCursors.new(cursor_ids) 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 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-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 activity_user user = current_user.pref[:activity_user] if user && user != "all_users" user = if user =~ /@/ # email User.where(:email => user).first else # first_name middle_name last_name any_name name_query = if user.include?(" ") user.name_permutations.map{ |first, last| "(upper(first_name) LIKE upper('%#{first}%') AND upper(last_name) LIKE upper('%#{last}%'))" }.join(" OR ") else "upper(first_name) LIKE upper('%#{user}%') OR upper(last_name) LIKE upper('%#{user}%')" end User.where(name_query).first end
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 calculated_type_mismatch? !media_types_from_name.include?(calculated_media_type) 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 cluster_status_gui(session, cluster_name, dont_update_config=false) cluster_nodes = get_cluster_nodes(cluster_name) status = cluster_status_from_nodes(session, cluster_nodes, cluster_name) unless status return 403, 'Permission denied' end new_cluster_nodes = [] new_cluster_nodes += status[:corosync_offline] if status[:corosync_offline] new_cluster_nodes += status[:corosync_online] if status[:corosync_online] new_cluster_nodes += status[:pacemaker_offline] if status[:pacemaker_offline] new_cluster_nodes += status[:pacemaker_online] if status[:pacemaker_online] new_cluster_nodes.uniq! if new_cluster_nodes.length > 0 config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text()) if !(dont_update_config or config.cluster_nodes_equal?(cluster_name, new_cluster_nodes)) old_cluster_nodes = config.get_nodes(cluster_name) $logger.info("Updating node list for: #{cluster_name} #{old_cluster_nodes}->#{new_cluster_nodes}") config.update_cluster(cluster_name, new_cluster_nodes) sync_config = Cfgsync::PcsdSettings.from_text(config.text()) # on version conflict just go on, config will be corrected eventually # by displaying the cluster in the web UI Cfgsync::save_sync_new_version( sync_config, get_corosync_nodes(), $cluster_name, true ) return cluster_status_gui(session, cluster_name, true) end end return JSON.generate(status) 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_group_users Log.add_info(request, params.inspect) SqlHelper.validate_token([params[:id]]) begin @folder = Folder.find(params[:id]) rescue => evar Log.add_error(request, evar) end @group_id = nil if !params[:thetisBoxSelKeeper].nil? @group_id = params[:thetisBoxSelKeeper].split(':').last elsif !params[:group_id].blank? @group_id = params[:group_id] end SqlHelper.validate_token([@group_id]) @users = Group.get_users(@group_id) render(:partial => 'ajax_select_users', :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_condtions_for(user, mail_account_ids) SqlHelper.validate_token([mail_account_ids]) if mail_account_ids.nil? or mail_account_ids.empty? return "(user_id=#{user.id} and (mail_account_id is null))" else return "(user_id=#{user.id} and (mail_account_id is null or mail_account_id in (#{mail_account_ids.join(',')})))" 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 build_query(path, details) query = @pattern.dup prefix = path.prefix.empty? ? "" : "#{escape_entry(path.prefix)}\\1" query.gsub!(/\:prefix(\/)?/, prefix) partial = escape_entry(path.partial? ? "_#{path.name}" : path.name) query.gsub!(/\:action/, partial) details.each do |ext, variants| query.gsub!(/\:#{ext}/, "{#{variants.compact.uniq.join(',')}}") end File.expand_path(query, @path) 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_next_revision(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
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 write(operations) buf = "" operations.each do |operation| operation.request_id = (@request_id += 1) operation.serialize(buf) end @sock.write buf 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 'is possible to return errors in jsonapi format' do get '/' expect(last_response.body).to eq('{"error":"rain!"}') 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 "with dofollowify enabled, links should be nofollowed" do @blog.dofollowify = true @blog.save expect(nofollowify_links('<a href="http://myblog.net">my blog</a>')). to eq('<a href="http://myblog.net">my blog</a>') 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 "sanitizes Fixnum array param value" do cl = subject.build("true", nil => [1]) expect(cl).to eq "true 1" 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
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 email_login raise Discourse::NotFound if !SiteSetting.enable_local_logins_via_email second_factor_token = params[:second_factor_token] second_factor_method = params[:second_factor_method].to_i token = params[:token] valid_token = !!EmailToken.valid_token_format?(token) user = EmailToken.confirmable(token)&.user if valid_token && user&.totp_enabled? if !second_factor_token.present? @second_factor_required = true @backup_codes_enabled = true if user&.backup_codes_enabled? return render layout: 'no_ember' elsif !user.authenticate_second_factor(second_factor_token, second_factor_method) RateLimiter.new(nil, "second-factor-min-#{request.remote_ip}", 3, 1.minute).performed! @error = I18n.t('login.invalid_second_factor_code') return render layout: 'no_ember' end end if user = EmailToken.confirm(token) if login_not_approved_for?(user) @error = login_not_approved[:error] elsif payload = login_error_check(user) @error = payload[:error] else log_on_user(user) return redirect_to path("/") end else @error = I18n.t('email_login.invalid_token') end render layout: 'no_ember' 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 actions if params[:media_action] != 'crop_url' authorize! :manage, :media end params[:folder] = params[:folder].gsub("//", "/") if params[:folder].present? case params[:media_action] when "new_folder" params[:folder] = slugify_folder(params[:folder]) render partial: "render_file_item", locals: {files: [cama_uploader.add_folder(params[:folder])]} when "del_folder" cama_uploader.delete_folder(params[:folder]) render inline: "" when "del_file" cama_uploader.delete_file(params[:folder].gsub("//", "/")) render inline: "" when 'crop_url' unless params[:url].start_with?('data:') params[:url] = (params[:url].start_with?('http') ? '' : current_site.the_url(locale: nil)) + params[:url] end r = cama_tmp_upload( params[:url], formats: params[:formats], name: params[:name]) unless r[:error].present? params[:file_upload] = r[:file_path] sett = {remove_source: true} sett[:same_name] = true if params[:same_name].present? sett[:name] = params[:name] if params[:name].present? upload(sett) else render inline: r[:error] end 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 cluster_destroy(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end out, errout, retval = run_cmd(session, PCS, "cluster", "destroy") if retval == 0 return [200, "Successfully destroyed cluster"] else return [400, "Error destroying cluster:\n#{out}\n#{errout}\n#{retval}\n"] 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 do_project_copy( params ) # set user if nil, needed for delayed job in Package model User.current ||= User.find_by_login(params[:user]) check_write_access! # copy entire project in the backend begin path = "/source/#{URI.escape(self.name)}" path << Suse::Backend.build_query_from_hash(params, [:cmd, :user, :comment, :oproject, :withbinaries, :withhistory, :makeolder]) Suse::Backend.post path, nil rescue Suse::Backend::HTTPError => e logger.debug "copy failed: #{e.message}" # we need to check results of backend in any case (also timeout error eg) end # restore all package meta data objects in DB backend_pkgs = Collection.find :package, :match => "@project='#{self.name}'" backend_pkgs.each_package do |package| path = "/source/#{URI.escape(self.name)}/#{package.name}/_meta" p = self.packages.new(name: package.name) p.update_from_xml(Xmlhash.parse(Suse::Backend.get(path).body)) p.save! # do not store end packages.each { |p| p.sources_changed } 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 with_primary(retry_on_failure = true, &block) if node = nodes.find(&:primary?) begin node.ensure_primary do return yield node.apply_auth(auth) end rescue Errors::ConnectionFailure, Errors::ReplicaSetReconfigured # Fall through to the code below if our connection was dropped or the # node is no longer the primary. end end if retry_on_failure # We couldn't find a primary node, so refresh the list and try again. refresh with_primary(false, &block) else raise Errors::ConnectionFailure, "Could not connect to a primary node for replica set #{inspect}" 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 call(exception, locale, key, options) if exception.is_a?(MissingTranslation) options[:rescue_format] == :html ? exception.html_message : exception.message elsif exception.is_a?(Exception) raise exception else throw :exception, exception 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