CVE-2015-10080 (published 2023-02-20T10:15Z)

A vulnerability was found in NREL api-umbrella-web 0.7.1. It has been classified as problematic. This affects an unknown part of the component Admin Data Table Handler. The manipulation leads to cross site scripting. It is possible to initiate the attack remotely. Upgrading to version 0.8.0 is able to address this issue. The patch is named f53a9fb87e10c457f0f3dd4f2af24d3b2f21b3ca. It is recommended to upgrade the affected component. The associated identifier of this vulnerability is VDB-221487.

CVSS v3 base score: 6.1, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: The product 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.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/NREL/api-umbrella-web
commit_details: repo_url: https://github.com/NREL/api-umbrella-web
author: Nick Muerdter
author_date: 2015-04-09 22:47:52-06:00
msg: Fix XSS escaping issues in the admin data tables.

I mistakenly thought DataTables escaped things by default, but this is
not the case. Escape all data tables fields now and add capybara
integrations tests to ensure this is effective.

Setting up the Capybara tests required a slight change in the analytics
"Filter Logs" table, since the ajax request needs to be performed via
POST instead of GET. I think this is due to the length of the URL
involved in the query. This had worked in most browsers, but I'm
guessing this was broken in IE anyway, so it's probably a good idea
anyway.
repository: repo_url: https://github.com/NREL/api-umbrella-web
repo_name: NREL/api-umbrella-web
description: See the https://github.com/NREL/api-umbrella repository instead.
repo_language: Ruby
owner: NREL
file_changes: filename: app.js
change_type: ModificationType.MODIFY
diff: @@ -363,3 +363,33 @@ Admin.Save = Ember.Mixin.create({
     }, this));
   },
 });
+
+Admin.DataTablesHelpers = {
+  renderEscaped: function(value, type) {
+    if(type === 'display' && value) {
+      return _.escape(value);
+    }
+
+    return value;
+  },
+
+  renderListEscaped: function(value, type) {
+    if(type === 'display' && value) {
+      if(_.isArray(value)) {
+        return _.map(value, function(v) { return _.escape(v); }).join('<br>');
+      } else {
+        return _.escape(value);
+      }
+    }
+
+    return value;
+  },
+
+  renderTime: function(value, type) {
+    if(type === 'display' && value && value !== '-') {
+      return moment(value).format('YYYY-MM-DD HH:mm:ss');
+    }
+
+    return value;
+  },
+};

programming_language: JavaScript
filename: table_view.js
change_type: ModificationType.MODIFY
diff: @@ -26,25 +26,13 @@ Admin.AdminGroupsTableView = Ember.View.extend({
         {
           data: 'api_scope_display_names',
           title: 'API Scopes',
-          render: function(names, type) {
-            if(type === 'display' && names && names !== '-') {
-              return names.join('<br>');
-            }
-
-            return names;
-          }
+          render: Admin.DataTablesHelpers.renderListEscaped,
         },
         {
           data: 'permission_display_names',
           title: 'Access',
           defaultContent: '-',
-          render: function(names, type) {
-            if(type === 'display' && names && names !== '-') {
-              return names.join('<br>');
-            }
-
-            return names;
-          }
+          render: Admin.DataTablesHelpers.renderListEscaped,
         }
       ]
     });

programming_language: JavaScript
filename: table_view.js
change_type: ModificationType.MODIFY
diff: @@ -27,48 +27,32 @@ Admin.AdminsTableView = Ember.View.extend({
           data: 'email',
           title: 'E-mail',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'name',
           title: 'Name',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'group_names',
           title: 'Groups',
-          render: function(names, type) {
-            if(type === 'display' && names && names !== '-') {
-              return names.join('<br>');
-            }
-
-            return names;
-          }
+          render: Admin.DataTablesHelpers.renderListEscaped,
         },
         {
           data: 'last_sign_in_at',
           type: 'date',
           title: 'Last Signed In',
           defaultContent: '-',
-          render: function(time, type) {
-            if(type === 'display' && time && time !== '-') {
-              return moment(time).format('YYYY-MM-DD HH:mm:ss');
-            }
-
-            return time;
-          },
+          render: Admin.DataTablesHelpers.renderTime,
         },
         {
           data: 'created_at',
           type: 'date',
           title: 'Created',
           defaultContent: '-',
-          render: function(time, type) {
-            if(type === 'display' && time && time !== '-') {
-              return moment(time).format('YYYY-MM-DD HH:mm:ss');
-            }
-
-            return time;
-          },
+          render: Admin.DataTablesHelpers.renderTime,
         }
       ]
     });

programming_language: JavaScript
filename: table_view.js
change_type: ModificationType.MODIFY
diff: @@ -27,11 +27,13 @@ Admin.ApiScopesTableView = Ember.View.extend({
           data: 'host',
           title: 'Host',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'path_prefix',
           title: 'Path Prefix',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         }
       ]
     });

programming_language: JavaScript
filename: table_view.js
change_type: ModificationType.MODIFY
diff: @@ -27,40 +27,39 @@ Admin.ApiUsersTableView = Ember.View.extend({
           data: 'first_name',
           title: 'First Name',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'last_name',
           title: 'Last Name',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'use_description',
           title: 'Purpose',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'created_at',
           type: 'date',
           title: 'Created',
           defaultContent: '-',
-          render: function(time, type) {
-            if(type === 'display' && time && time !== '-') {
-              return moment(time).format('YYYY-MM-DD HH:mm:ss');
-            }
-
-            return time;
-          },
+          render: Admin.DataTablesHelpers.renderTime,
         },
         {
           data: 'registration_source',
           title: 'Registration Source',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'api_key_preview',
           title: 'API Key',
           defaultContent: '-',
           orderable: false,
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
       ]
     });

programming_language: JavaScript
filename: table_view.js
change_type: ModificationType.MODIFY
diff: @@ -39,17 +39,20 @@ Admin.ApisTableView = Ember.View.extend({
           data: 'frontend_host',
           title: 'Host',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'frontend_prefixes',
           title: 'Prefixes',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'sort_order',
           title: 'Matching Order',
           defaultContent: '-',
           width: 130,
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: null,

programming_language: JavaScript
filename: logs_table_view.js
change_type: ModificationType.MODIFY
diff: @@ -9,6 +9,9 @@ Admin.LogsTableView = Ember.View.extend({
       serverSide: true,
       ajax: {
         url: '/admin/stats/logs.json',
+        // Use POST for this endpoint, since the URLs can be very long and
+        // exceed URL length limits in IE (and apparently Capybara too).
+        type: 'POST',
         data: _.bind(function(data) {
           var query = this.get('controller.query.params');
           return _.extend({}, data, query);
@@ -43,28 +46,25 @@ Admin.LogsTableView = Ember.View.extend({
           type: 'date',
           title: 'Time',
           defaultContent: '-',
-          render: function(time, type) {
-            if(type === 'display' && time && time !== '-') {
-              return moment(time).format('YYYY-MM-DD HH:mm:ss');
-            }
-
-            return time;
-          },
+          render: Admin.DataTablesHelpers.renderTime,
         },
         {
           data: 'request_method',
           title: 'Method',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_host',
           title: 'Host',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_url',
           title: 'URL',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'user_email',
@@ -86,26 +86,31 @@ Admin.LogsTableView = Ember.View.extend({
           data: 'request_ip',
           title: 'IP Address',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_ip_country',
           title: 'Country',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_ip_region',
           title: 'State',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_ip_city',
           title: 'City',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'response_status',
           title: 'Status',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'response_time',
@@ -123,16 +128,19 @@ Admin.LogsTableView = Ember.View.extend({
           data: 'response_content_type',
           title: 'Content Type',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_accept_encoding',
           title: 'Accept Encoding',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'request_user_agent',
           title: 'User Agent',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
       ]
     });

programming_language: JavaScript
filename: users_table_view.js
change_type: ModificationType.MODIFY
diff: @@ -36,22 +36,20 @@ Admin.StatsUsersTableView = Ember.View.extend({
           data: 'first_name',
           title: 'First Name',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'last_name',
           title: 'Last Name',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderEscaped,
         },
         {
           data: 'created_at',
           type: 'date',
           title: 'Signed Up',
           defaultContent: '-',
-          render: function(time, type) {
-            if(type === 'display' && time && time !== '-') {
-              return moment(time).format('YYYY-MM-DD HH:mm:ss');
-            }
-          },
+          render: Admin.DataTablesHelpers.renderTime,
         },
         {
           data: 'hits',
@@ -70,18 +68,13 @@ Admin.StatsUsersTableView = Ember.View.extend({
           type: 'date',
           title: 'Last Request',
           defaultContent: '-',
-          render: function(time, type) {
-            if(type === 'display' && time && time !== '-') {
-              return moment(time).format('YYYY-MM-DD HH:mm:ss');
-            }
-
-            return time;
-          },
+          render: Admin.DataTablesHelpers.renderTime,
         },
         {
           data: 'use_description',
           title: 'Use Description',
           defaultContent: '-',
+          render: Admin.DataTablesHelpers.renderTime,
         },
       ]
     });

programming_language: JavaScript
filename: routes.rb
change_type: ModificationType.MODIFY
diff: @@ -71,6 +71,7 @@ ApiUmbrella::Application.routes.draw do
       collection do
         get "search"
         get "logs"
+        post "logs"
         get "users"
         get "map"
       end

programming_language: Ruby
filename: api_users.rb
change_type: ModificationType.MODIFY
diff: @@ -11,5 +11,12 @@ FactoryGirl.define do
     factory :invalid_api_user do
       terms_and_conditions ""
     end
+
+    factory :xss_api_user do
+      first_name '"><script class="xss-test">alert("Hello first_name");</script>'
+      last_name '"><script class="xss-test">alert("Hello last_name");</script>'
+      use_description '"><script class="xss-test">alert("Hello use_description");</script>'
+      registration_source '"><script class="xss-test">alert("Hello registration_source");</script>'
+    end
   end
 end

programming_language: Ruby
filename: log_items.rb
change_type: ModificationType.MODIFY
diff: @@ -10,11 +10,14 @@ class LogItem
   attribute :internal_gatekeeper_time, Float
   attribute :internal_response_time, Float
   attribute :proxy_overhead, Float
-  attribute :request_accept, String
+  attribute :request_accept_encoding, String
   attribute :request_at, Time
   attribute :request_hierarchy, Array
   attribute :request_host, String
   attribute :request_ip, String
+  attribute :request_ip_city, String
+  attribute :request_ip_country, String
+  attribute :request_ip_region, String
   attribute :request_method, String
   attribute :request_path, String
   attribute :request_query, Hash
@@ -47,11 +50,14 @@ FactoryGirl.define do
     internal_gatekeeper_time 1.4
     internal_response_time 1.8
     proxy_overhead 3
-    request_accept "*/*"
+    request_accept_encoding "*/*"
     request_at { Time.now }
     request_hierarchy ["0/127.0.0.1/", "1/127.0.0.1/hello"]
     request_host "127.0.0.1"
     request_ip "127.0.0.1"
+    request_ip_city "Golden"
+    request_ip_country "US"
+    request_ip_region "CO"
     request_method "GET"
     request_path "/hello/"
     request_query({ "foo" => "bar" })
@@ -71,5 +77,21 @@ FactoryGirl.define do
     user_email "test@example.com"
     user_id "4199b260-ae76-463f-8395-d30de09c1540"
     user_registration_source "web_admin"
+
+    factory :xss_log_item do
+      request_accept_encoding '"><script class="xss-test">alert("1");</script>'
+      request_host '"><script class="xss-test">alert("2");</script>'
+      request_ip_city '"><script class="xss-test">alert("3");</script>'
+      request_ip_country '"><script class="xss-test">alert("4");</script>'
+      request_ip_region '"><script class="xss-test">alert("5");</script>'
+      request_path '"><script class="xss-test">alert("6");</script>'
+      request_query({ "foo" => '"><script class="xss-test">alert("7");</script>' })
+      request_url '"><script class="xss-test">alert("8");</script>'
+      request_user_agent '"><script class="xss-test">alert("9");</script>'
+      response_content_type '"><script class="xss-test">alert("10");</script>'
+      response_server '"><script class="xss-test">alert("11");</script>'
+      user_email '"><script class="xss-test">alert("12");</script>'
+      user_registration_source '"><script class="xss-test">alert("13");</script>'
+    end
   end
 end

programming_language: Ruby
filename: api_users_spec.rb
change_type: ModificationType.MODIFY
diff: @@ -3,6 +3,35 @@ require 'spec_helper'
 describe "api users form", :js => true do
   login_admin
 
+  describe "xss" do
+    before(:all) do
+      ApiUser.where(:registration_source.ne => "seed").delete_all
+      @user = FactoryGirl.create(:xss_api_user)
+    end
+
+    it "escapes html entities in the table" do
+      visit "/admin/#/api_users"
+
+      page.should have_content(@user.email)
+      page.should_not have_selector(".xss-test", :visible => :all)
+      page.should have_content(@user.first_name)
+      page.should have_content(@user.last_name)
+      page.should have_content(@user.use_description)
+      page.should have_content(@user.registration_source)
+    end
+
+    it "escapes html entities in the form" do
+      visit "/admin/#/api_users/#{@user.id}/edit"
+
+      find_field("E-mail").value.should eql(@user.email)
+      page.should_not have_selector(".xss-test", :visible => :all)
+      find_field("First Name").value.should eql(@user.first_name)
+      find_field("Last Name").value.should eql(@user.last_name)
+      find_field("Purpose").value.should eql(@user.use_description)
+      page.should have_content(@user.registration_source)
+    end
+  end
+
   describe "api key in the save notification" do
     it "shows the api key when creating a new account" do
       visit "/admin/#/api_users/new"

programming_language: Ruby
filename: stats_logs_spec.rb
change_type: ModificationType.MODIFY
diff: @@ -11,6 +11,25 @@ describe "apis", :js => true do
     end
   end
 
+  describe "xss" do
+    it "escapes html entities in the table" do
+      log = FactoryGirl.create(:xss_log_item, :request_at => Time.parse("2015-01-16T06:06:28.816Z"), :request_method => "OPTIONS")
+      LogItem.gateway.refresh_index!
+
+      visit "/admin/#/stats/logs/tz=America%2FDenver&search=&start_at=2015-01-12&end_at=2015-01-18&interval=day"
+
+      page.should have_content(log.request_method)
+      page.should_not have_selector(".xss-test", :visible => :all)
+      page.should have_content(log.request_accept_encoding)
+      page.should have_content(log.request_ip_city)
+      page.should have_content(log.request_ip_country)
+      page.should have_content(log.request_ip_region)
+      page.should have_content(log.request_user_agent)
+      page.should have_content(log.response_content_type)
+      page.should have_content(log.user_email)
+    end
+  end
+
   describe "csv download" do
     it "updates the download link as the query parameters change" do
       FactoryGirl.create(:log_item, :request_at => Time.parse("2015-01-16T06:06:28.816Z"))

programming_language: Ruby