CVE-2014-2235 (published 2014-03-05T16:37Z)

Cross-site scripting (XSS) vulnerability in Askbot before 0.7.49 allows remote attackers to inject arbitrary web script or HTML via vectors related to the question search form.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:P/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/ASKBOT/askbot-devel
commit_details: repo_url: https://github.com/ASKBOT/askbot-devel
author: Evgeny Fadeev
author_date: 2013-03-31 03:27:43-04:00
msg: added instant search to the tags page
repository: repo_url: https://github.com/ASKBOT/askbot-devel
repo_name: ASKBOT/askbot-devel
description: Askbot is a Django/Python Q&A forum. **Contributors README**: https://github.com/ASKBOT/askbot-devel#how-to-contribute. Commercial hosting of Askbot and support are available at https://askbot.com
repo_language: Python
owner: ASKBOT
file_changes: filename: changelog.rst
change_type: ModificationType.MODIFY
diff: @@ -3,6 +3,7 @@ Changes in Askbot
 
 Development version
 -------------------
+* Added instant search to the tags page
 * Added a placeholder template for the custom javascript on the question page
 * Allowed to disable the big "ask" button.
 * Some support for the media compression (Tyler Mandry)

programming_language: Markdown
filename: live_search.js
change_type: ModificationType.MODIFY
diff: @@ -267,6 +267,7 @@ TagWarningBox.prototype.showWarning = function(){
  */
 var InputToolTip = function() {
     WrappedElement.call(this);
+    this._promptText = gettext('search or ask your question');
 };
 inherits(InputToolTip, WrappedElement);
 
@@ -284,6 +285,10 @@ InputToolTip.prototype.dim = function() {
     this._element.addClass('dimmed');
 };
 
+InputToolTip.prototype.setPromptText = function(text) {
+    this._promptText = text;
+};
+
 InputToolTip.prototype.setClickHandler = function(handler) {
     this._clickHandler = handler;
 };
@@ -292,7 +297,7 @@ InputToolTip.prototype.createDom = function() {
     var element = this.makeElement('div');
     this._element = element;
     element.addClass('input-tool-tip');
-    element.html(gettext('search or ask your question'));
+    element.html(this._promptText);
     this.decorate(element);
 };
 
@@ -882,3 +887,139 @@ FullTextSearch.prototype.decorate = function(element) {
 
     $("form#searchForm").submit(me.makeFormSubmitHandler());
 };
+
+/**
+ * @constructor
+ */
+var TagSearch = function() {
+    WrappedElement.call(this);
+    this._isRunning = false;
+};
+inherits(TagSearch, WrappedElement);
+
+TagSearch.prototype.getQuery = function() {
+    return $.trim(this._element.val());
+};
+
+TagSearch.prototype.setQuery = function(val) {
+    this._element.val(val);
+};
+
+TagSearch.prototype.getSort = function() {
+    //todo: read it off the page
+    var link = $('.tabBar a.on');
+    if (link.length === 1) {
+        var sort = link.attr('id').replace('sort_', '');
+        if (sort === 'name' || sort === 'used') {
+            return sort;
+        }
+    }
+    return 'name';
+};
+
+TagSearch.prototype.getIsRunning = function() {
+    return this._isRunning;
+};
+
+TagSearch.prototype.setIsRunning = function(val) {
+    this._isRunning = val;
+};
+
+TagSearch.prototype.renderResult = function(html) {
+    this._contentBox.html(html);
+};
+
+TagSearch.prototype.runSearch = function() {
+    var data = {
+        'query': this.getQuery(),
+        'sort': this.getSort(),
+        'page': '1'
+    };
+    var me = this;
+    $.ajax({
+        dataType: 'json',
+        data: data,
+        cache: false,
+        url: askbot['urls']['tags'],
+        success: function(data) {
+            if (data['success']) {
+                me.renderResult(data['html']);
+                me.setIsRunning(false);
+            }
+        },
+        error: function() { me.setIsRunning(false); }
+    });
+    me.setIsRunning(true);
+};
+
+TagSearch.prototype.getToolTip = function() {
+    return this._toolTip;
+};
+
+TagSearch.prototype.makeKeyUpHandler = function() {
+    var me = this;
+    return function(evt) {
+        var keyCode = getKeyCode(evt);
+        if (me.getIsRunning() === false) {
+            me.runSearch();
+        }
+    };
+};
+
+TagSearch.prototype.makeKeyDownHandler = function() {
+    var me = this;
+    var xButton = this._xButton;
+    return function(evt) {
+        var query = me.getQuery();
+        var keyCode = getKeyCode(evt);
+        var toolTip = me.getToolTip();
+        if (keyCode === 27) {//escape
+            me.setQuery('');
+            toolTip.show();
+            xButton.hide();
+            return;
+        }
+        if (keyCode === 8 || keyCode === 48) {//del or backspace
+            if (query.length === 1) {
+                toolTip.show();
+                xButton.hide();
+            }
+        } else {
+            toolTip.hide();
+            xButton.show();
+        }
+    };
+};
+
+TagSearch.prototype.reset = function() {
+    if (this.getIsRunning() === false) {
+        this.setQuery('');
+        this._toolTip.show();
+        this._xButton.hide();
+        this.runSearch();
+        this._element.focus();
+    }
+};
+
+TagSearch.prototype.decorate = function(element) {
+    this._element = element;
+    this._contentBox = $('#ContentLeft');
+    this._xButton = $('input[name=reset_query]');
+    element.keyup(this.makeKeyUpHandler());
+    element.keydown(this.makeKeyDownHandler());
+
+    var me = this;
+    this._xButton.click(function(){ me.reset() });
+
+    var toolTip = new InputToolTip();
+    toolTip.setPromptText(askbot['data']['tagSearchPromptText']);
+    toolTip.setClickHandler(function() {
+        element.focus();
+    });
+    element.after(toolTip.getElement());
+    //below is called after getElement, b/c element must be defined
+    if (this.getQuery() !== '') {
+        toolTip.hide();//hide if search query is not empty
+    }
+    this._toolTip = toolTip;
+};

programming_language: JavaScript
filename: style.css
change_type: ModificationType.MODIFY
diff: @@ -547,7 +547,6 @@ input[type="submit"].searchBtn {
   z-index: 10001;
 }
 .groups-page input[type="submit"].searchBtn,
-.tags-page input[type="submit"].searchBtn,
 .badges-pages input[type="submit"].searchBtn,
 .user-profile-page input[type="submit"].searchBtn,
 .meta input[type="submit"].searchBtn,

programming_language: CSS
filename: style.less
change_type: ModificationType.MODIFY
diff: @@ -592,7 +592,6 @@ input[type="submit"].searchBtn {
 }
 
 .groups-page, /* todo: clean up - should not need this */
-.tags-page,
 .badges-pages,
 .user-profile-page,
 .meta,

programming_language: CSS
filename: bottom_scripts.html
change_type: ModificationType.MODIFY
diff: @@ -84,6 +84,9 @@
                 search.setAskButtonEnabled(false);
             }
             search.decorate(searchInput);
+        } else if (activeTab === 'tags') {
+            var search = new TagSearch();
+            search.decorate(searchInput);
         }
 
         if (askbot['data']['userIsAdminOrMod']) {

programming_language: HTML
filename: tags.html
change_type: ModificationType.MODIFY
diff: @@ -1,43 +1,8 @@
 {% extends "two_column_body.html" %}
-{% import "macros.html" as macros %}
 <!-- tags.html -->
 {% block title %}{% spaceless %}{% trans %}Tags{% endtrans %}{% endspaceless %}{% endblock %}
 {% block content %}
-<!-- Tabs -->
-{% include "tags/header.html" %}
-{% if tag_list_type == 'list' %}
-    {% if not tags.object_list %}
-        <span>{% trans %}Nothing found{% endtrans %}</span>
-    {% endif %}
-    {% if tags.object_list %}
-        <div class='clearfix'></div>
-        <ul class='tags'>
-            {% for tag in tags.object_list %}
-            <li>
-                {{ macros.tag_widget(
-                            tag=tag.name,
-                            html_tag='div',
-                            truncate_long_tag=True,
-                            extra_content='<span class="tag-number">&#215; ' ~
-                                            tag.used_count|intcomma ~ '</span>'
-                    )
-                }}
-            </li>
-            {% endfor %}
-        </ul>
-        <div class="clean"></div>
-        <div class="pager">
-            {{macros.paginator(paginator_context)}}
-        </div>
-    {% endif %}
-{% else %}
-    <div class="clearfix"></div>
-    {% if not tags %}
-        <span>{% trans %}Nothing found{% endtrans %}</span>
-    {% endif %}
-    {{ macros.tag_cloud(tags=tags, font_sizes=font_size, search_state=search_state) }}
-{% endif %}
-
+{% include "tags/content.html" %}
 {% endblock %}
 {% block endjs %}
     <script type="text/javascript">
@@ -49,7 +14,9 @@
             Hilite.elementid = "searchtags";
             Hilite.debug_referrer = location.href;
         });
+        askbot['data']['tagSearchPromptText'] = "{% trans %}search for tags{% endtrans %}";
     /*]]>*/
     </script>
+    {% include "tags/custom_javascript.httml" ignore missing %}
 {% endblock %}
 <!-- end tags.html -->

programming_language: HTML
filename: content.html
change_type: ModificationType.ADD
diff: @@ -0,0 +1,34 @@
+{% import "macros.html" as macros %}
+{% include "tags/header.html" %}
+{% if tag_list_type == 'list' %}
+    {% if not tags.object_list %}
+        <span>{% trans %}Nothing found{% endtrans %}</span>
+    {% endif %}
+    {% if tags.object_list %}
+        <div class='clearfix'></div>
+        <ul class='tags'>
+            {% for tag in tags.object_list %}
+            <li>
+                {{ macros.tag_widget(
+                            tag=tag.name,
+                            html_tag='div',
+                            truncate_long_tag=True,
+                            extra_content='<span class="tag-number">&#215; ' ~
+                                            tag.used_count|intcomma ~ '</span>'
+                    )
+                }}
+            </li>
+            {% endfor %}
+        </ul>
+        <div class="clean"></div>
+        <div class="pager">
+            {{macros.paginator(paginator_context)}}
+        </div>
+    {% endif %}
+{% else %}
+    <div class="clearfix"></div>
+    {% if not tags %}
+        <span>{% trans %}Nothing found{% endtrans %}</span>
+    {% endif %}
+    {{ macros.tag_cloud(tags=tags, font_sizes=font_size, search_state=search_state) }}
+{% endif %}

programming_language: HTML
filename: header.html
change_type: ModificationType.MODIFY
diff: @@ -1,9 +1,10 @@
 <div id="content-header">
+    {% set tag_query = stag|escape %}
     {% if page_title %}
             <h1 class="section-title">{{ page_title }}</h1>
     {% else %}
         {% if stag %}
-            <h1 class="section-title">{% trans %}Tags, matching "{{ stag }}"{% endtrans %}</h1>
+            <h1 class="section-title">{% trans %}Tags, matching "{{ tag_query }}"{% endtrans %}</h1>
         {% else %}
             <h1 class="section-title">{% trans %}Tags{% endtrans %}</h1>
         {% endif %}
@@ -13,13 +14,13 @@
             <span class="label">{% trans %}Sort by &raquo;{% endtrans %}</span>
             <a
                 id="sort_name"
-                href="{% url tags %}?sort=name"
+                href="{% url tags %}?sort=name{% if tag_query %}&query={{ tag_query }}{% endif %}"
                 {% if tab_id == 'name' %}class="on"{% endif %}
                 title="{% trans %}sorted alphabetically{% endtrans %}"
             ><span>{% trans %}by name{% endtrans %}</span></a>
             <a
                 id="sort_used"
-                href="{% url tags %}?sort=used"
+                href="{% url tags %}?sort=used{% if tag_query %}&query={{ tag_query }}{% endif %}"
                 {% if tab_id == 'used' %}class="on"{% endif %}
                 title="{% trans %}sorted by frequency of tag use{% endtrans %}"
             ><span>{% trans %}by popularity{% endtrans %}</span></a>

programming_language: HTML
filename: search_bar.html
change_type: ModificationType.MODIFY
diff: @@ -7,6 +7,7 @@
     {# url action depends on which tab is active #}
     {% if active_tab == "tags" %}
         <input type="hidden" name="t" value="tag"/>
+        {% set query=stag %}
     {% elif active_tab == "users" %}
         <input type="hidden" name="t" value="user"/>
     {% endif %}
@@ -14,7 +15,7 @@
         class="searchInput" 
         type="text" 
         autocomplete="off"
-        value="{{ query|default_if_none('') }}" 
+        value="{{ query|default_if_none('')|escape }}" 
         name="query" 
         id="keywords"
     />

programming_language: HTML
filename: readers.py
change_type: ModificationType.MODIFY
diff: @@ -245,9 +245,10 @@ def questions(request, **kwargs):
 def tags(request):#view showing a listing of available tags - plain list
 
     #1) Get parameters. This normally belongs to form cleaning.
-    sortby = request.GET.get('sort', 'used')
+    post_data = request.GET
+    sortby = post_data.get('sort', 'used')
     try:
-        page = int(request.GET.get('page', '1'))
+        page = int(post_data.get('page', '1'))
     except ValueError:
         page = 1
 
@@ -256,13 +257,13 @@ def tags(request):#view showing a listing of available tags - plain list
     else:
         order_by = '-used_count'
 
-    query = request.GET.get('query', '').strip()
+    query = post_data.get('query', '').strip()
     tag_list_type = askbot_settings.TAG_LIST_FORMAT
 
     #2) Get query set for the tags.
     query_params = {'deleted': False}
     if query != '':
-        query_params['name__icontains': query]
+        query_params['name__icontains'] = query
 
     tags_qs = Tag.objects.filter(**query_params).exclude(used_count=0)
 
@@ -307,7 +308,14 @@ def tags(request):#view showing a listing of available tags - plain list
 
     data['tags'] = tags
 
-    return render(request, 'tags.html', data)
+    if request.is_ajax():
+        template = get_template('tags/content.html')
+        template_context = RequestContext(request, data)
+        json_data = {'success': True, 'html': template.render(template_context)}
+        json_string = simplejson.dumps(json_data)
+        return HttpResponse(json_string, mimetype='application/json')
+    else:
+        return render(request, 'tags.html', data)
 
 @csrf.csrf_protect
 def question(request, id):#refactor - long subroutine. display question body, answers and comments

programming_language: Python