<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web-In-Sight &#187; development</title>
	<atom:link href="http://web-in-sight.nl/tag/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://web-in-sight.nl</link>
	<description>Inzicht in internet en werken</description>
	<lastBuildDate>Mon, 30 Jan 2012 09:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Django: QueryScreener, a record level ownership development auditor</title>
		<link>http://web-in-sight.nl/2009/10/26/django-queryscreener-a-record-level-ownership-development-auditor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=django-queryscreener-a-record-level-ownership-development-auditor</link>
		<comments>http://web-in-sight.nl/2009/10/26/django-queryscreener-a-record-level-ownership-development-auditor/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 16:41:12 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.gerardjp.com/?p=1049</guid>
		<description><![CDATA[QueryScreener is a middleware development tool that helps to avoid unwanted data disclosure once you go into production. It monitors queries to the models and warns you when queries are executed that lack a ownership clause.  <a href="http://web-in-sight.nl/2009/10/26/django-queryscreener-a-record-level-ownership-development-auditor/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>During the development stage of a Django app I&#8217;m working on I was exploring how to best implement rowlevel user ownerships. There are several ways to overwrite methods on <a title="Object Managers" href="http://docs.djangoproject.com/en/dev/topics/db/managers/" target="_blank">object managers</a> and even the Django admin interface is properly configurable to take a ownership from &#8220;request.user&#8221;.</p>
<p>But since wrongfull data disclosure is absolutely unacceptable I was still afraid that I would miss something somewhere. A nice example I ran into was populating a dropdown list in a form, where all records were visible instead of only those owned by the logged in user.</p>
<p>That got me thinking and eventually I wrote this small but sweet piece of <a title="Middleware" href="http://docs.djangoproject.com/en/dev/topics/http/middleware/" target="_blank">middleware</a>. Further elaboration below the code.</p>
<pre class="python" name="code">from django.db import connection
import re

"""
QueryScreener is a middleware development tool. This tool helps to avoid
unwanted data disclosure once you go into production.

It monitors queries to the models in your model_list and warns you when queries
are executed that do not contain a ownership where clause. And thus can be a
potential data disclosure hazard.

It requires a owner attribute in your model definition, e.g:

    owner = models.ForeignKey(User, editable=False)

Edit the 'model_list' below for what models should be monitored. And add
QueryScreener to MIDDLEWARE_CLASSES in you settings.py

Note: This can/should only be used while running Django's testserver command
with e.g: ./manage.py runserver 192.168.1.81:8000
"""

class QueryScreener(object):

    model_list = ['myapp_customer', 'myapp_order', 'myapp_product']

    def process_view(self, request, view_func, view_args, view_kwargs):
        if len(connection.queries) &gt; 0:
            query_parse(connection.queries, self.model_list, 'process_view')

    def process_response(self, request, response):
        if len(connection.queries) &gt; 0:
            query_parse(connection.queries, self.model_list, 'process_response')
        return response

def query_parse(self, model_list, caller_process):

    for query in connection.queries:
        for modelname in model_list:
            modelstring = 'FROM `'+modelname

            if re.search(modelstring, query['sql']) and not \
                re.search(r'^SELECT.\(1\).AS', query['sql']):

                reg = re.compile(r'^SELECT.*WHERE.*owner.*(ORDER BY.*)?$',
                                    re.DOTALL)

                if not reg.search(query['sql']):
                    print ('&lt;&lt;&lt; WARNING &gt;&gt;&gt; Query execution without ownership '
                            'clause, called from "' + caller_process + '"')
                    print query['sql']

            if re.search(r'^SELECT.\(1\).AS.`a`.FROM.*WHERE.*$', query['sql']):
                print ('&lt;&lt;&lt; Django Farted &gt;&gt;&gt;')
#                print query['sql']</pre>
<p><em>Update1: The &#8216;ORDER BY&#8217; in the regex needs to be optional.</em><br />
<em>Update2: Django does a &#8216;try update&#8217; in save_base() without owner (seperated the select statement)<br />
</em></p>
<p>The comment in the code above sums up how to get it working. What it does is print a warning and the query in question that does not respect ownership. If enabled while developing just keep track of your console output for:</p>
<pre>&lt;&lt;&lt; WARNING &gt;&gt;&gt; Query execution without ownership clause, called from "process_response"</pre>
<p>Should you  have suggestion, criticism, or words of admiration then please, do tell me <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>GrtzG</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2009%2F10%2F26%2Fdjango-queryscreener-a-record-level-ownership-development-auditor%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2009/10/26/django-queryscreener-a-record-level-ownership-development-auditor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans on Ubuntu</title>
		<link>http://web-in-sight.nl/2007/06/10/netbeans-on-ubuntu/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=netbeans-on-ubuntu</link>
		<comments>http://web-in-sight.nl/2007/06/10/netbeans-on-ubuntu/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 08:37:41 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.gp-net.nl/2007/06/10/netbeans-on-ubuntu/</guid>
		<description><![CDATA[Do you feel lost in the java forrest when you want to install these marvelous IDE&#8217;s out there? Me too. Try apache&#8217;s FOP on Debian if you want a real challenge. Anyhow .. This article is about Running Netbeans on &#8230; <a href="http://web-in-sight.nl/2007/06/10/netbeans-on-ubuntu/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Do you feel lost in the java forrest when you want to install these marvelous IDE&#8217;s out there? Me too. Try apache&#8217;s <a title="FOP" href="http://xmlgraphics.apache.org/fop/">FOP</a> on Debian if you want a real challenge.</p>
<p>Anyhow .. This article is about Running Netbeans on Ubuntu, and it&#8217;s not an intallation manual. It&#8217;s just shows a working combination of components.</p>
<p>I&#8217;m using Ubuntu 7.04 (upgraded from an installed 6.01) and wanted to check out NetBeans. I Googled around, and checked the NetBean requirements. It needs a JDK &#8230; oh boy ..  here we go &#8230;</p>
<p>I&#8217;m a fan of keeping thing as default as possible to avoids pitfalls in the future (KISS &#8230; Keep It Simple Stupid!). So I first tried the Ubuntu package manager. No decent JDK in there so we go to sun. Well I actually found it in the <a href="http://www.netbeans.org/kb/55/quickstart.html" target="_blank">Netbeans Quickstart Guide</a>.</p>
<p>To get to the point, these are the ones that work together:</p>
<ul>
<li>Ubuntu 7.04 (dist-upgraded from 6.01)</li>
<li>Java Development kit 6u1 (Netbeans Quickstart says 5 but the 6u1 does the job as well)</li>
<li>Netbeans IDE 5.5.1</li>
</ul>
<p>No hassle &#8230; Install the JDK (e.g. in &#8220;/usr/local/jdk1.6.0_01/&#8221;) and without setting environment variables Netbeans figures out by itself where the JDK HOMEDIR is. Cudos on that!!!. Then you can install NetBeans in any given directory.</p>
<p>Up and running! &#8230; Was that quick or what?!?</p>
<p>- &#8211; - Time Warp &#8211; - -</p>
<p>You didn&#8217;t know this but I wanted to try NetBeans to develop Rails websites. As it turns out NetBeans  5.5.1 has no support for Rails yet. That didn&#8217;t stop me from installing NetBeans IDE 6.0 Preview M9 Full version (which has the rails support). You only have to add a &#8220;&#8211;javahome&#8221; parameter to the installer like so:</p>
<pre>./netbeans-6.0m9-full-linux.sh --javahome /usr/local/jdk1.6.0_01/</pre>
<p>And guess what? .. that also works.</p>
<p>Happy Coding!</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2007%2F06%2F10%2Fnetbeans-on-ubuntu%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2007/06/10/netbeans-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

