<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Victor Chibotaru on Medium]]></title>
        <description><![CDATA[Stories by Victor Chibotaru on Medium]]></description>
        <link>https://medium.com/@tch1bo?source=rss-87728e97aa98------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*byjm3t4eMqxqiCi_88Ywyw.jpeg</url>
            <title>Stories by Victor Chibotaru on Medium</title>
            <link>https://medium.com/@tch1bo?source=rss-87728e97aa98------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:44:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tch1bo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fantastic Vulnerabilities and Where To Find Them (Part 1) — Cross-site Scripting with Django form e]]></title>
            <link>https://medium.com/crowdbotics/fantastic-vulnerabilities-and-where-to-find-them-part-1-how-to-xss-using-django-form-errors-9b4a1d97a5bb?source=rss-87728e97aa98------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b4a1d97a5bb</guid>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-security]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[code-review]]></category>
            <dc:creator><![CDATA[Victor Chibotaru]]></dc:creator>
            <pubDate>Thu, 14 Mar 2019 10:38:37 GMT</pubDate>
            <atom:updated>2019-06-15T07:59:17.572Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fantastic Vulnerabilities and Where To Find Them (Part 1) — Cross-site Scripting with Django form errors</h3><h4>XSS scripting vulnerabilities</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-jzxnV-kWMmYRXZQ00NMA.jpeg" /></figure><p>Why is Cross-Site Scripting (XSS) still the most common web vulnerability? The theory of identifying XSS is pretty straightforward, there are many static analysis tools created to detect it and yet there are so many undiscovered vulnerabilities. So, what gives?</p><p>Well, one of the reasons is that traditional program analysis methods often fail to identify the intent of a given piece of code. For example, a tool might struggle with figuring out which objects in the program could contain user input.</p><p>In my<a href="https://hackernoon.com/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-3f9729230b24"> previous post </a>I described how we addressed this problem by building a <a href="https://deepcode.ai/">system</a> that learns security specifications from thousands of Open Source projects and uses them to find real vulnerabilities. I also promised to share some cool examples of what it learned.</p><p>I decided to start with an interesting and rather unexpected source of possible issues in projects using <a href="https://www.djangoproject.com/">Django</a>. This post is a guide to identifying and exploiting XSS vulnerabilities using validation errors in Django forms. Here’s a real example: <a href="https://github.com/mozilla/pontoon/pull/1175">https://github.com/mozilla/pontoon/pull/1175</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jRppdgQ3Zy1ehhQSZykow.jpeg" /></figure><p>Let’s jump straight into it and start with a little quiz. How many times have you written/seen code similar to the following snippet?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d813dadf3b1d2ea66fbfea4be924cd0c/href">https://medium.com/media/d813dadf3b1d2ea66fbfea4be924cd0c/href</a></iframe><p>What about this one?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee27829e2253ba72e54bb81eb82b9cab/href">https://medium.com/media/ee27829e2253ba72e54bb81eb82b9cab/href</a></iframe><p>Or this one?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97c255d827f9d3b9b34bc35a4e7ae7d1/href">https://medium.com/media/97c255d827f9d3b9b34bc35a4e7ae7d1/href</a></iframe><p>All of them are widespread examples of how you usually let the user know that the provided input is invalid, right? The input is taken from the HTTP request parameters and neatly unmarshalled into a MyForm object. If any of the fields contains invalid input (e.g. someone entered the string &quot;foobar&quot; into a numeric field), then a 400 Bad Request page gets returned with a description of the error. The difference between snippets is the format of the returned error — an HTML list, plain text or JSON.</p><p>Now a million dollar question — which of these snippets will make your web app XSSable?</p><p>To answer it, let’s investigate the Django forms API from two points of view:</p><ol><li>Is the attacker able to inject malicious input into the web page displayed in user’s browser?</li><li>Will this malicious input always be properly escaped before it gets returned to the user?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rAt1jPpKFnf7y_jRQrBzWg.gif" /></figure><p>According to Django’s <a href="https://docs.djangoproject.com/en/2.1/ref/forms/validation/">documentation</a> the way to build dynamic error messages for field validation errors is to raise a django.core.exceptions.ValidationError exception with the corresponding message. Such an exception thrown from any of the validation functions of the form (e.g. the methods clean() and clean_&lt;fieldname&gt;()of the django.forms.BaseForm class) will cause the message to be stored in the form’s error dictionary (django.forms.utils.ErrorDict) and later possibly shown to the user.</p><p>One way to exploit such an exception is to use some of the built-in form fields that conveniently reflect the faulty input into the exception message. I tried all Django form fields types listed <a href="https://docs.djangoproject.com/en/2.1/ref/forms/fields/">here</a> and got the following list: ChoiceField, TypedChoiceField, MultipleChoiceField, FilePathField. Each of these generates an error message like &quot;Select a valid choice. %(value)s is not one of the available choices.” , where value is the faulty input. &lt;script&gt;alert(1)&lt;/script&gt; for the win.</p><p>The second option is to exploit custom fields and/or validation procedures. For example, consider the following snippet (taken from a real project and modified for brevity):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768164494dbe46985dde7d2ebd7114c4/href">https://medium.com/media/768164494dbe46985dde7d2ebd7114c4/href</a></iframe><p>Here a good payload would be something like foo.&lt;img src=x onerror=alert(1)&gt;.</p><p>Yep, you’re right, the ValidationError exceptions alone will not grant us an XSS. For a proper vulnerability we need one more ingredient — the ability to inject error messages into the final HTML page that gets returned to the user.</p><p>The aforementioned ErrorDict class has the following methods to extract the error messages:</p><ol><li>as_data() — no sanitization</li><li>get_json_data(escape_html=False) — no sanitization if escape_html == False (the default)</li><li>as_json(escape_html=False) no sanitization if escape_html == False (the default)</li><li>as_ul() — safe</li><li>as_text() — no sanitization</li><li>__str__() (calls as_ul()) — safe</li></ol><p>Now let’s go back to our little quiz. It’s easy to see that snippet 1 is safe, because it uses the __str__() method, which escapes the input. Snippets 2 and 3, however are dangerous and may result in XSS.</p><p>There are two main takeaway messages here. The one for developers is the mantra “always sanitize untrusted input”. The one for security researchers is: a simple grep -R &quot;ValidationError&quot; might broaden the attack surface for you.</p><p>By the way you have my respect if you passed the quiz correctly without reading the full post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*t8C63OX9x98UWgr_vHM6UQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7kqyahThCaSx77QSjO_8A.png" /></figure><h4>Building A Web Or Mobile App?</h4><p><em>Crowdbotics is the fastest way to build, launch and scale an application.</em></p><p><em>Developer? Try out the </em><a href="https://www.crowdbotics.com/app-builder/?utm_source=medium?utm_campaign=cb-medium?utm_content=footer"><strong><em>Crowdbotics App Builder</em></strong></a><em> to quickly scaffold and deploy apps with a variety of popular frameworks.</em></p><p><em>Busy or non-technical? Join hundreds of happy teams building software with Crowdbotics PMs and expert developers. Scope timeline and cost with Crowdbotics</em><strong><em> </em></strong><a href="https://www.crowdbotics.com/managed-app-development/?utm_source=medium?utm_campaign=cb-medium?utm_content=footer"><strong><em>Managed App Development</em></strong></a><em> for free.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b4a1d97a5bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/crowdbotics/fantastic-vulnerabilities-and-where-to-find-them-part-1-how-to-xss-using-django-form-errors-9b4a1d97a5bb">Fantastic Vulnerabilities and Where To Find Them (Part 1) — Cross-site Scripting with Django form e</a> was originally published in <a href="https://medium.com/crowdbotics">Crowdbotics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fantastic vulnerabilities and where to find them (part 1)- how to XSS using Django form errors]]></title>
            <link>https://medium.com/deepcode-ai/fantastic-vulnerabilities-and-where-to-find-them-part-1-how-to-xss-using-django-form-errors-ba905f90811?source=rss-87728e97aa98------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba905f90811</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Victor Chibotaru]]></dc:creator>
            <pubDate>Thu, 14 Mar 2019 10:25:33 GMT</pubDate>
            <atom:updated>2019-03-14T10:25:33.196Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fantastic vulnerabilities and where to find them (part 1) — how to XSS using Django form errors</h3><p>Why is Cross-Site Scripting still the most common web vulnerability? The theory of identifying XSS is pretty straightforward, there are many static analysis tools created to detect it and yet there are so many undiscovered vulnerabilities. Why?</p><p>Well, one of the reasons is that traditional program analysis methods often fail to identify the intent of a given piece of code. For example, a tool might struggle with figuring out which objects in the program could contain user input.</p><p>In my<a href="https://hackernoon.com/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-3f9729230b24"> previous post </a>I described how we addressed this problem by building a <a href="https://deepcode.ai/">system</a> that learns security specifications from thousands of Open Source projects and uses them to find real vulnerabilities. I also promised to share some cool examples of what it learned.</p><p>I decided to start with an interesting and rather unexpected source of possible issues in projects using <a href="https://www.djangoproject.com/">Django</a>. This post is a guide to identifying and exploiting XSS vulnerabilities using validation errors in Django forms. Here’s a real example: <a href="https://github.com/mozilla/pontoon/pull/1175">https://github.com/mozilla/pontoon/pull/1175</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jRppdgQ3Zy1ehhQSZykow.jpeg" /></figure><p>Let’s jump straight into it and start with a little quiz. How many times have you written/seen code similar to the following snippet?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d813dadf3b1d2ea66fbfea4be924cd0c/href">https://medium.com/media/d813dadf3b1d2ea66fbfea4be924cd0c/href</a></iframe><p>What about this one?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee27829e2253ba72e54bb81eb82b9cab/href">https://medium.com/media/ee27829e2253ba72e54bb81eb82b9cab/href</a></iframe><p>Or this one?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97c255d827f9d3b9b34bc35a4e7ae7d1/href">https://medium.com/media/97c255d827f9d3b9b34bc35a4e7ae7d1/href</a></iframe><p>All of them are widespread examples of how you usually let the user know that the provided input is invalid, right? The input is taken from the HTTP request parameters and neatly unmarshalled into a MyForm object. If any of the fields contains invalid input (e.g. someone entered the string &quot;foobar&quot; into a numeric field), then a 400 Bad Request page gets returned with a description of the error. The difference between snippets is the format of the returned error — an HTML list, plain text or JSON.</p><p>Now a million dollar question — which of these snippets will make your web app XSSable?</p><p>To answer it, let’s investigate the Django forms API from two points of view:</p><ol><li>Is the attacker able to inject malicious input into the web page displayed in user’s browser?</li><li>Will this malicious input always be properly escaped before it gets returned to the user?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rAt1jPpKFnf7y_jRQrBzWg.gif" /></figure><p>According to Django’s <a href="https://docs.djangoproject.com/en/2.1/ref/forms/validation/">documentation</a> the way to build dynamic error messages for field validation errors is to raise a django.core.exceptions.ValidationError exception with the corresponding message. Such an exception thrown from any of the validation functions of the form (e.g. the methods clean() and clean_&lt;fieldname&gt;()of the django.forms.BaseForm class) will cause the message to be stored in the form’s error dictionary (django.forms.utils.ErrorDict) and later possibly shown to the user.</p><p>One way to exploit such an exception is to use some of the built-in form fields that conveniently reflect the faulty input into the exception message. I tried all Django form fields types listed <a href="https://docs.djangoproject.com/en/2.1/ref/forms/fields/">here</a> and got the following list: ChoiceField, TypedChoiceField, MultipleChoiceField, FilePathField. Each of these generates an error message like &quot;Select a valid choice. %(value)s is not one of the available choices.” , where value is the faulty input. &lt;script&gt;alert(1)&lt;/script&gt; for the win.</p><p>The second option is to exploit custom fields and/or validation procedures. For example, consider the following snippet (taken from a real project and modified for brevity):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768164494dbe46985dde7d2ebd7114c4/href">https://medium.com/media/768164494dbe46985dde7d2ebd7114c4/href</a></iframe><p>Here a good payload would be something like foo.&lt;img src=x onerror=alert(1)&gt;.</p><p>Yep, you’re right, the ValidationError exceptions alone will not grant us an XSS. For a proper vulnerability we need one more ingredient — the ability to inject error messages into the final HTML page that gets returned to the user.</p><p>The aforementioned ErrorDict class has the following methods to extract the error messages:</p><ol><li>as_data() — no sanitization</li><li>get_json_data(escape_html=False) — no sanitization if escape_html == False (the default)</li><li>as_json(escape_html=False) no sanitization if escape_html == False (the default)</li><li>as_ul() — safe</li><li>as_text() — no sanitization</li><li>__str__() (calls as_ul()) — safe</li></ol><p>Now let’s go back to our little quiz. It’s easy to see that snippet 1 is safe, because it uses the __str__() method, which escapes the input. Snippets 2 and 3, however are dangerous and may result in XSS.</p><p>There are two main takeaway messages here. The one for developers is the mantra “always sanitize untrusted input”. The one for security researchers is: a simple grep -R &quot;ValidationError&quot; might broaden the attack surface for you.</p><p>By the way you have my respect if you passed the quiz correctly without reading the full post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*t8C63OX9x98UWgr_vHM6UQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba905f90811" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deepcode-ai/fantastic-vulnerabilities-and-where-to-find-them-part-1-how-to-xss-using-django-form-errors-ba905f90811">Fantastic vulnerabilities and where to find them (part 1)- how to XSS using Django form errors</a> was originally published in <a href="https://medium.com/deepcode-ai">DeepCodeAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fantastic vulnerabilities and where to find them (part 1)— how to XSS using Django form errors]]></title>
            <link>https://medium.com/hackernoon/fantastic-vulnerabilities-and-where-to-find-them-part-1-how-to-xss-using-django-form-errors-e83c653eb27?source=rss-87728e97aa98------2</link>
            <guid isPermaLink="false">https://medium.com/p/e83c653eb27</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Victor Chibotaru]]></dc:creator>
            <pubDate>Fri, 22 Feb 2019 11:31:52 GMT</pubDate>
            <atom:updated>2019-02-22T11:31:52.446Z</atom:updated>
            <content:encoded><![CDATA[<p>Why is Cross-Site Scripting still the most common web vulnerability? The theory of identifying XSS is pretty straightforward, there are many static analysis tools created to detect it and yet there are so many undiscovered vulnerabilities. Why?</p><p>Well, one of the reasons is that traditional program analysis methods often fail to identify the intent of a given piece of code. For example, a tool might struggle with figuring out which objects in the program could contain user input.</p><p>In my<a href="https://hackernoon.com/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-3f9729230b24"> previous post </a>I described how we addressed this problem by building a <a href="https://deepcode.ai/">system</a> that learns security specifications from thousands of Open Source projects and uses them to find real vulnerabilities. I also promised to share some cool examples of what it learned.</p><p>I decided to start with an interesting and rather unexpected source of possible issues in projects using <a href="https://www.djangoproject.com/">Django</a>. This post is a guide to identifying and exploiting XSS vulnerabilities using validation errors in Django forms. Here’s a real example: <a href="https://github.com/mozilla/pontoon/pull/1175">https://github.com/mozilla/pontoon/pull/1175</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jRppdgQ3Zy1ehhQSZykow.jpeg" /></figure><p>Let’s jump straight into it and start with a little quiz. How many times have you written/seen code similar to the following snippet?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d813dadf3b1d2ea66fbfea4be924cd0c/href">https://medium.com/media/d813dadf3b1d2ea66fbfea4be924cd0c/href</a></iframe><p>What about this one?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee27829e2253ba72e54bb81eb82b9cab/href">https://medium.com/media/ee27829e2253ba72e54bb81eb82b9cab/href</a></iframe><p>Or this one?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97c255d827f9d3b9b34bc35a4e7ae7d1/href">https://medium.com/media/97c255d827f9d3b9b34bc35a4e7ae7d1/href</a></iframe><p>All of them are widespread examples of how you usually let the user know that the provided input is invalid, right? The input is taken from the HTTP request parameters and neatly unmarshalled into a MyForm object. If any of the fields contains invalid input (e.g. someone entered the string &quot;foobar&quot; into a numeric field), then a 400 Bad Request page gets returned with a description of the error. The difference between snippets is the format of the returned error — an HTML list, plain text or JSON.</p><p>Now a million dollar question — which of these snippets will make your web app XSSable?</p><p>To answer it, let’s investigate the Django forms API from two points of view:</p><ol><li>Is the attacker able to inject malicious input into the web page displayed in user’s browser?</li><li>Will this malicious input always be properly escaped before it gets returned to the user?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rAt1jPpKFnf7y_jRQrBzWg.gif" /></figure><p>According to Django’s <a href="https://docs.djangoproject.com/en/2.1/ref/forms/validation/">documentation</a> the way to build dynamic error messages for field validation errors is to raise a django.core.exceptions.ValidationError exception with the corresponding message. Such an exception thrown from any of the validation functions of the form (e.g. the methods clean() and clean_&lt;fieldname&gt;()of the django.forms.BaseForm class) will cause the message to be stored in the form’s error dictionary (django.forms.utils.ErrorDict) and later possibly shown to the user.</p><p>One way to exploit such an exception is to use some of the built-in form fields that conveniently reflect the faulty input into the exception message. I tried all Django form fields types listed <a href="https://docs.djangoproject.com/en/2.1/ref/forms/fields/">here</a> and got the following list: ChoiceField, TypedChoiceField, MultipleChoiceField, FilePathField. Each of these generates an error message like &quot;Select a valid choice. %(value)s is not one of the available choices.” , where value is the faulty input. &lt;script&gt;alert(1)&lt;/script&gt; for the win.</p><p>The second option is to exploit custom fields and/or validation procedures. For example, consider the following snippet (taken from a real project and modified for brevity):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768164494dbe46985dde7d2ebd7114c4/href">https://medium.com/media/768164494dbe46985dde7d2ebd7114c4/href</a></iframe><p>Here a good payload would be something like foo.&lt;img src=x onerror=alert(1)&gt;.</p><p>Yep, you’re right, the ValidationError exceptions alone will not grant us an XSS. For a proper vulnerability we need one more ingredient — the ability to inject error messages into the final HTML page that gets returned to the user.</p><p>The aforementioned ErrorDict class has the following methods to extract the error messages:</p><ol><li>as_data() — no sanitization</li><li>get_json_data(escape_html=False) — no sanitization if escape_html == False (the default)</li><li>as_json(escape_html=False) no sanitization if escape_html == False (the default)</li><li>as_ul() — safe</li><li>as_text() — no sanitization</li><li>__str__() (calls as_ul()) — safe</li></ol><p>Now let’s go back to our little quiz. It’s easy to see that snippet 1 is safe, because it uses the __str__() method, which escapes the input. Snippets 2 and 3, however are dangerous and may result in XSS.</p><p>There are two main takeaway messages here. The one for developers is the mantra “always sanitize untrusted input”. The one for security researchers is: a simple grep -R &quot;ValidationError&quot; might broaden the attack surface for you.</p><p>By the way you have my respect if you passed the quiz correctly without reading the full post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*t8C63OX9x98UWgr_vHM6UQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e83c653eb27" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/fantastic-vulnerabilities-and-where-to-find-them-part-1-how-to-xss-using-django-form-errors-e83c653eb27">Fantastic vulnerabilities and where to find them (part 1)— how to XSS using Django form errors</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meet the tool that automatically infers security vulnerabilities in Python code]]></title>
            <link>https://medium.com/hackernoon/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-3f9729230b24?source=rss-87728e97aa98------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f9729230b24</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[security-vulnerabilities]]></category>
            <category><![CDATA[python-security]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Victor Chibotaru]]></dc:creator>
            <pubDate>Fri, 08 Feb 2019 22:56:18 GMT</pubDate>
            <atom:updated>2019-02-08T22:56:18.292Z</atom:updated>
            <content:encoded><![CDATA[<h3>TL;DR</h3><p>In January 2019 we released a tool that significantly raises the bar for detecting security vulnerabilities in Python code. We built a fully automated system that couples data flow analysis algorithms with a novel ML component and detects many more new security issues than traditional approaches. After running it on several Open Source repositories, we found and reported 35 critical security vulnerabilities from the <a href="https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project">OWASP Top Ten</a> list. Here’s a motivating screenshot that shows one of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kR8n94sq5GsuGQZO8slDPA.png" /><figcaption>One of the XSS vulnerabilities that we found and reported</figcaption></figure><p>The interest towards Information Security and, in particular Web Applications security, is steadily growing over the past years. Unfortunately so does the threat level posed by security vulnerabilities that are silently awaiting to be exploited by attackers. This fact obviously puts an additional burden on developers’ shoulders, which a code review tool <strong>must</strong> relieve. That is why we decided to make a big push to improve detection of security issues. This blog post covers how we did it.</p><p>When it comes to detecting all these scary vulnerabilities like Cross-Site Scripting (XSS), SQL Injection (SQLi), Path Traversal (PT), Remote Code Execution (RCE), etc. probably the most used code analysis technique is called <a href="https://en.wikipedia.org/wiki/Taint_checking">Taint Analysis</a>. I guess its popularity comes from the simplicity of the core idea, which very simply put sounds like: “check that all user input is properly escaped before it reaches a critical (from the security point of view) piece of code ”.</p><p>So, if I ask you to exploit this super-complicated snippet of code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31e88c9bbd27137c79b8d5dfa9f0bc9b/href">https://medium.com/media/31e88c9bbd27137c79b8d5dfa9f0bc9b/href</a></iframe><p>and you think “hmm, user input from the HTTP request gets into the variable name and then into the django.http.HttpResponse call, so if I set it to &lt;script&gt;evil_code&lt;/script&gt; , then evil_code will get executed in victim’s browser”, then you already know how it works. If not, here’s an informal description of the technique in less than a hundred words.</p><p>Taint Analysis emphasizes three categories of objects (variables, function calls, etc.):</p><ol><li><strong>Sources</strong> — contain user input (e.g. request.GET.get(“name”))</li><li><strong>Sanitizers</strong> — transform user input from unsafe to safe (e.g. django.utils.html.escape() )</li><li><strong>Sinks</strong> — trigger security vulnerabilities if an attacker’s input reaches them (e.g. django.http.HttpResponse() )</li></ol><p>The analysis validates that all data flows from a source to a sink pass through a sanitizer. If not, then each unsanitized flow is reported as a potential vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*8DPJWtt4cMmc2xC5mu0r2Q.jpeg" /></figure><p>One of the main limitations of Taint Analysis is its dependence on the specification of sources, sinks and sanitizers. Such a specification has to be manually compiled by a “security expert”, who must be very familiar with both the project code base and all the used third party frameworks. Ideally, the expert would then write down all the sources, sinks and sanitizers present in the code and let the taint tool do its job. It is not hard to see that this approach has some obvious downsides.</p><p>First, imagine how much work it is to manually assemble this security specification. One would have to go through tons of documentation and/or code of both the project and the frameworks. Now think of this famous quote by Larry Wall, which says that “laziness and impatience are two true virtues of a great programmer”, and feel some pity for the poor fellow assigned to the task.</p><p>Second, each missed entity in the list is a potentially neglected vulnerability. Humans are notorious for making mistakes, especially when it comes to routine jobs like this. Can you trust the completeness of the obtained list?</p><p>Third, this is not a one-time effort. This process has to be incrementally redone every time a framework gets updated or the project starts using a different one or its own code changes significantly. This considerably increases the cost of maintaining the project.</p><p>Fourth, this approach does not scale. Each project and each framework are unique, which means that the security specifications can’t be 100% successfully reused.</p><p>These four basically mean that the traditional approach will not work efficiently for a tool like our <a href="https://www.deepcode.ai/">Code Review</a>, that is run daily on thousands of different projects. We simply do not have an army of security consultants that would work on specifications for each project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*GUMY7MavfJyrfhjKbPKB9w.jpeg" /></figure><p>We solved this problem the DeepCode way — we learned the answer from Open Source code. We built a system that analyzes publicly available code, collects stats about all encountered APIs, neatly combines them in a model and infers new sources, sinks and sanitizers in a fully automated way. It also predicts the vulnerability types for sinks and provides suggestions on which sanitizer to use to fix the issue.</p><p>Clearly our new approach helps against limitations 1, 3 and 4 listed above. But what about the second (and main) one? To check the quality of our inferred specification, we exposed it to the ultimate challenge — a bug hunt. We ran the <a href="https://www.deepcode.ai/">publicly available version of our analyzer</a> on multiple Open Source repositories hosted on GitHub. We specifically targeted web applications that are meant to be (or already are) used by multiple (honest and malicious) users.</p><p>This experiment resulted in the following list of vulnerabilities that were discovered and fixed. It also proved that our tool is capable of finding interesting, non-trivial and sometimes unexpected bugs. A more detailed description with cool examples deserves its own blog post, which will hopefully come out soon. So, for now let us just conclude with presenting the GitHub pull requests/issues we filed.</p><p><em>(XSS = Cross-Site Scripting, SQLi = SQL Injection, PT = Path Traversal, RCE = Remote Code Execution)</em></p><ol><li><a href="https://github.com/mozilla/pontoon/pull/1175">Multiple XSS in mozilla/pontoon</a></li><li><a href="https://github.com/earthgecko/skyline/issues/86">Mutliple SQLi in earthgecko/skyline</a></li><li><a href="https://github.com/earthgecko/skyline/issues/85">XSS in earthgecko/skyline</a></li><li><a href="https://github.com/DataViva/dataviva-site/issues/1662">XSS in DataViva/dataviva-site</a></li><li><a href="https://github.com/DataViva/dataviva-site/issues/1661">SQLi in DataViva/dataviva-site</a></li><li><a href="https://github.com/LMFDB/lmfdb/pull/2696">SQLi in lmfdb/LMFDB</a></li><li><a href="https://github.com/LMFDB/lmfdb/pull/2695">Multiple XSS in lmfdb/LMFDB</a></li><li><a href="https://github.com/gestorpsi/gestorpsi/pull/75">Multiple XSS in gestorpsi/gestorpsi</a></li><li><a href="https://github.com/sharadbhat/VideoHub/issues/3">Multiple SQLi in sharadbhat/VideoHub</a></li><li><a href="https://github.com/UDST/urbansim/issues/213">RCE in UDST/urbansim</a></li><li><a href="https://github.com/viaict/viaduct/pull/5">Mutliple XSS in viaict/viaduct</a></li><li><a href="https://github.com/MLTSHP/mltshp/pull/509">XSS in MLTSHP/mltshp</a></li><li><a href="https://github.com/kylewm/woodwind/issues/77">Multiple XSS in kylewm/woodwind</a></li><li><a href="https://github.com/kylewm/silo.pub/issues/57">XSS in kylewm/silo.pub</a></li><li><a href="https://github.com/anyaudio/anyaudio-server/pull/163">Multiple XSS in anyaudio/anyaudio-server</a></li><li><a href="https://github.com/MinnPost/election-night-api/issues/1">SQLi in MinnPost/election-night-api</a></li><li><a href="https://github.com/mitre/multiscanner/issues/159">PT in mitre/multiscanner</a></li><li><a href="https://github.com/PadamSethia/shorty/pull/4">SQLi in PadamSethia/shorty</a></li></ol><p><strong>P.S. </strong>Curious to see how many vulnerabilities we can find in your project? Looking for CVEs in Open Source? Or simply not yet convinced that it works? Well, then see you at <a href="https://www.deepcode.ai/">https://www.deepcode.ai/</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f9729230b24" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-3f9729230b24">Meet the tool that automatically infers security vulnerabilities in Python code</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meet the tool that automatically infers security vulnerabilities in Python code]]></title>
            <link>https://medium.com/deepcode-ai/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-d83e4151872f?source=rss-87728e97aa98------2</link>
            <guid isPermaLink="false">https://medium.com/p/d83e4151872f</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[code-review-tool]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Victor Chibotaru]]></dc:creator>
            <pubDate>Fri, 01 Feb 2019 10:48:28 GMT</pubDate>
            <atom:updated>2019-02-01T10:48:28.413Z</atom:updated>
            <content:encoded><![CDATA[<h3>TL;DR</h3><p>In January 2019 we released a tool that significantly raises the bar for detecting security vulnerabilities in Python code. We built a fully automated system that couples data flow analysis algorithms with a novel ML component and detects many more new security issues than traditional approaches. After running it on several Open Source repositories, we found and reported 35 critical security vulnerabilities from the <a href="https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project">OWASP Top Ten</a> list. Here’s a motivating screenshot that shows one of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kR8n94sq5GsuGQZO8slDPA.png" /><figcaption>One of the XSS vulnerabilities that we found and reported</figcaption></figure><p>The interest towards Information Security and, in particular Web Applications security, is steadily growing over the past years. Unfortunately so does the threat level posed by security vulnerabilities that are silently awaiting to be exploited by attackers. This fact obviously puts an additional burden on developers’ shoulders, which a code review tool <strong>must</strong> relieve. That is why we decided to make a big push to improve detection of security issues. This blog post covers how we did it.</p><p>When it comes to detecting all these scary vulnerabilities like Cross-Site Scripting (XSS), SQL Injection (SQLi), Path Traversal (PT), Remote Code Execution (RCE), etc. probably the most used code analysis technique is called <a href="https://en.wikipedia.org/wiki/Taint_checking">Taint Analysis</a>. I guess its popularity comes from the simplicity of the core idea, which very simply put sounds like: “check that all user input is properly escaped before it reaches a critical (from the security point of view) piece of code ”.</p><p>So, if I ask you to exploit this super-complicated snippet of code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31e88c9bbd27137c79b8d5dfa9f0bc9b/href">https://medium.com/media/31e88c9bbd27137c79b8d5dfa9f0bc9b/href</a></iframe><p>and you think “hmm, user input from the HTTP request gets into the variable name and then into the django.http.HttpResponse call, so if I set it to &lt;script&gt;evil_code&lt;/script&gt; , then evil_code will get executed in victim’s browser”, then you already know how it works. If not, here’s an informal description of the technique in less than a hundred words.</p><p>Taint Analysis emphasizes three categories of objects (variables, function calls, etc.):</p><ol><li><strong>Sources</strong> — contain user input (e.g. request.GET.get(“name”))</li><li><strong>Sanitizers</strong> — transform user input from unsafe to safe (e.g. django.utils.html.escape() )</li><li><strong>Sinks</strong> —trigger security vulnerabilities if an attacker’s input reaches them (e.g. django.http.HttpResponse() )</li></ol><p>The analysis validates that all data flows from a source to a sink pass through a sanitizer. If not, then each unsanitized flow is reported as a potential vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*8DPJWtt4cMmc2xC5mu0r2Q.jpeg" /></figure><p>One of the main limitations of Taint Analysis is its dependence on the specification of sources, sinks and sanitizers. Such a specification has to be manually compiled by a “security expert”, who must be very familiar with both the project code base and all the used third party frameworks. Ideally, the expert would then write down all the sources, sinks and sanitizers present in the code and let the taint tool do its job. It is not hard to see that this approach has some obvious downsides.</p><p>First, imagine how much work it is to manually assemble this security specification. One would have to go through tons of documentation and/or code of both the project and the frameworks. Now think of this famous quote by Larry Wall, which says that “laziness and impatience are two true virtues of a great programmer”, and feel some pity for the poor fellow assigned to the task.</p><p>Second, each missed entity in the list is a potentially neglected vulnerability. Humans are notorious for making mistakes, especially when it comes to routine jobs like this. Can you trust the completeness of the obtained list?</p><p>Third, this is not a one-time effort. This process has to be incrementally redone every time a framework gets updated or the project starts using a different one or its own code changes significantly. This considerably increases the cost of maintaining the project.</p><p>Fourth, this approach does not scale. Each project and each framework are unique, which means that the security specifications can’t be 100% successfully reused.</p><p>These four basically mean that the traditional approach will not work efficiently for a tool like our <a href="https://www.deepcode.ai/">Code Review</a>, that is run daily on thousands of different projects. We simply do not have an army of security consultants that would work on specifications for each project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*GUMY7MavfJyrfhjKbPKB9w.jpeg" /></figure><p>We solved this problem the DeepCode way — we learned the answer from Open Source code. We built a system that analyzes publicly available code, collects stats about all encountered APIs, neatly combines them in a model and infers new sources, sinks and sanitizers in a fully automated way. It also predicts the vulnerability types for sinks and provides suggestions on which sanitizer to use to fix the issue.</p><p>Clearly our new approach helps against limitations 1, 3 and 4 listed above. But what about the second (and main) one? To check the quality of our inferred specification, we exposed it to the ultimate challenge — a bug hunt. We ran the <a href="https://www.deepcode.ai/">publicly available version of our analyzer</a> on multiple Open Source repositories hosted on GitHub. We specifically targeted web applications that are meant to be (or already are) used by multiple (honest and malicious) users.</p><p>This experiment resulted in the following list of vulnerabilities that were discovered and fixed. It also proved that our tool is capable of finding interesting, non-trivial and sometimes unexpected bugs. A more detailed description with cool examples deserves its own blog post, which will hopefully come out soon. So, for now let us just conclude with presenting the GitHub pull requests/issues we filed.</p><p><em>(XSS = Cross-Site Scripting, SQLi = SQL Injection, PT = Path Traversal, RCE = Remote Code Execution)</em></p><ol><li><a href="https://github.com/mozilla/pontoon/pull/1175">Multiple XSS in mozilla/pontoon</a></li><li><a href="https://github.com/earthgecko/skyline/issues/86">Mutliple SQLi in earthgecko/skyline</a></li><li><a href="https://github.com/earthgecko/skyline/issues/85">XSS in earthgecko/skyline</a></li><li><a href="https://github.com/DataViva/dataviva-site/issues/1662">XSS in DataViva/dataviva-site</a></li><li><a href="https://github.com/DataViva/dataviva-site/issues/1661">SQLi in DataViva/dataviva-site</a></li><li><a href="https://github.com/LMFDB/lmfdb/pull/2696">SQLi in lmfdb/LMFDB</a></li><li><a href="https://github.com/LMFDB/lmfdb/pull/2695">Multiple XSS in lmfdb/LMFDB</a></li><li><a href="https://github.com/gestorpsi/gestorpsi/pull/75">Multiple XSS in gestorpsi/gestorpsi</a></li><li><a href="https://github.com/sharadbhat/VideoHub/issues/3">Multiple SQLi in sharadbhat/VideoHub</a></li><li><a href="https://github.com/UDST/urbansim/issues/213">RCE in UDST/urbansim</a></li><li><a href="https://github.com/viaict/viaduct/pull/5">Mutliple XSS in viaict/viaduct</a></li><li><a href="https://github.com/MLTSHP/mltshp/pull/509">XSS in MLTSHP/mltshp</a></li><li><a href="https://github.com/kylewm/woodwind/issues/77">Multiple XSS in kylewm/woodwind</a></li><li><a href="https://github.com/kylewm/silo.pub/issues/57">XSS in kylewm/silo.pub</a></li><li><a href="https://github.com/anyaudio/anyaudio-server/pull/163">Multiple XSS in anyaudio/anyaudio-server</a></li><li><a href="https://github.com/MinnPost/election-night-api/issues/1">SQLi in MinnPost/election-night-api</a></li><li><a href="https://github.com/mitre/multiscanner/issues/159">PT in mitre/multiscanner</a></li><li><a href="https://github.com/PadamSethia/shorty/pull/4">SQLi in PadamSethia/shorty</a></li></ol><p><strong>P.S. </strong>Curious to see how many vulnerabilities we can find in your project? Looking for CVEs in Open Source? Or simply not yet convinced that it works? Well, then see you at <a href="https://www.deepcode.ai/">https://www.deepcode.ai/</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d83e4151872f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deepcode-ai/meet-the-tool-that-automatically-infers-security-vulnerabilities-in-python-code-d83e4151872f">Meet the tool that automatically infers security vulnerabilities in Python code</a> was originally published in <a href="https://medium.com/deepcode-ai">DeepCodeAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>