djangosnippets.org: Latest snippets tagged with 'ssl'http://djangosnippets.org/tags/ssl/2014-05-24T15:07:15.426150-05:00SSL Force Middleware
2014-05-24T15:07:15.426150-05:00careercoderhttp://djangosnippets.org/snippets/3067/<p>A simple way to force SSL on all pages. It's very simple at this point - the only issue I can see right now and I will address this later is if someone sends http:// in another portion of your url.</p>
Freely redistributableHTTPS redirections middleware with updated URL template tag
2012-10-19T11:12:48.629453-05:00xlqhttp://djangosnippets.org/snippets/2833/<p>This middleware redirects HTTP requests to HTTPS for some specified URLs, in the same way as <a href="http://djangosnippets.org/snippets/85/">85</a>. It also changes the <code>url</code> template tag to use the <code>https</code> scheme for the same URLs. For example, if you have the following URL pattern:</p>
<pre><code>url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'https': True})
</code></pre>
<p>then the template: …</p>
Freely redistributableTLS(SSL) middleware, per URL pattern or whole site
2010-12-01T08:46:29.250707-06:00robmadolehttp://djangosnippets.org/snippets/2282/<p>Allows url patterns to include a boolean indicating whether a view requires
TLS(SSL). The accompanying middleware handles the redirects needed to make
sure that it upholds this requirement.
</p>
<p><strong>WARNING</strong>: this monkey-patches some Django internals and is difficult to test
since Django's TestClient does not support TLS. If you use …</p>
Freely redistributableUse MEDIA_URL in flatpages with SSL
2010-07-02T07:49:13.476033-05:00gobblehttp://djangosnippets.org/snippets/2089/<p>This is a copy of <a href="http://djangosnippets.org/snippets/654/">snippet 654</a>, modified to allow dynamic MEDIA_URL, as you might need that for SSL in combination with <a href="http://djangosnippets.org/snippets/1754/">snippet 1754</a>.</p>
<p>This is a template filter to enable the use of the MEDIA_URL setting in content from the
flatpages database table. It searches for {{ …</p>
Freely redistributableFake SSL Middleware for Tests and Local Development
2010-05-05T17:19:15.980802-05:00DrMeershttp://djangosnippets.org/snippets/2009/<p>Add <code>FakeSSLMiddleware</code> to the top of your <code>MIDDLEWARE_CLASSES</code> stack when running tests or developing locally to allow https:// links to operate correctly. Can be used in conjunction with other SSL middleware to allow critical tests to be performed.</p>
Freely redistributableSSL / HTTPS Middleware for Redirection and href Rewriting
2010-04-27T18:39:18.203132-05:00DrMeershttp://djangosnippets.org/snippets/1999/<p>See docstrings for details. To use, add to <code>MIDDLEWARE_CLASSES</code> in <code>settings.py</code>, and in your <code>views.py</code>:
</p>
<ol>
<li>
<code>from path.to.this.middleware import secure</code>
</li>
<li>
Decorate SSL views with <code>@secure</code>
</li>
</ol>
Freely redistributableSecurity: Sideband information cover traffic middleware
2010-03-25T09:20:08.232559-05:00jdunckhttp://djangosnippets.org/snippets/1970/<p>This is a quick hack to address the SSL info leakage covered here:
http://www.freedom-to-tinker.com/blog/felten/side-channel-leaks-web-applications</p>
<p>Don't use this in prod without testing. :-)</p>
<p>I'll get some feedback from django-dev and update here.</p>
Freely redistributableLoad static media from secure (SSL) static server (Context Processor)
2009-10-09T13:25:54.511785-05:00ianreardonhttp://djangosnippets.org/snippets/1754/<p>If you request static files such as images, javascript or css using http rather than https, the browser will complain that your site is not secure.<br />
</p>
<p>This simple context processor will replace http:// with https:// in your MEDIA_URL if your static files are being included from an https page.</p>
<p>In …</p>
Freely redistributableWebFaction fixes middleware
2009-08-28T15:50:56.812936-05:00spookylukeyhttp://djangosnippets.org/snippets/1706/<p>On WebFaction, each host has it's own Apache instance, with WebFaction's main Apache instance forwarding requests. This is very useful but means that some of the original information is lost. This middleware should be installed at the top of your list to restore this lost info.</p>
<p>It includes the functionality …</p>
Freely redistributableDecorator to modify reverse() to render SSL urls
2009-04-27T08:26:02.867297-05:00AndrewIngramhttp://djangosnippets.org/snippets/1467/<p>This snippet monkey-patches Django's reverse() method (use for generating URLs from vew functions and parameters) to allow certain areas of your site to automatically have URLs with the correct SSL domain in place.
</p>
<p>This saves you from having to use unnecessary redirects to guide users to an SSL-encrypted version of …</p>
Freely redistributableSSL Decorator
2009-03-02T21:34:13.828112-06:00pjshttp://djangosnippets.org/snippets/1351/<p>Wrote this some time ago when I couldn't find one already completed. Came up in the IRC channel so I decided to post it.
</p>
<p>Easy enough to use.
</p>
<p><code>from ssldecorator import ssl_required</code>
</p>
<p><code>@ssl_required</code>
<code>def your_view(request):</code>
<code>''' your code here '''</code>
</p>
<p>You can place a variable in your settings.py to change …</p>
Freely redistributableAuthentication Against Active Directory (LDAP) over SSL
2008-07-21T16:06:45.691344-05:00maryhttp://djangosnippets.org/snippets/901/<p>I had some trouble getting other peoples code to work for AD support, so I wrote my own which authenticates against LDAP and will also use SSL and cert if required. It will also verify that an autheticated user has specific group membership before authorizing.</p>
<p>This will also debug to …</p>
Freely redistributableSSL Redirect Middleware and testing
2008-07-14T15:13:01.098160-05:00willhardyhttp://djangosnippets.org/snippets/881/<p>While we're on the topic of SSLRedirect (See snippet 240 and 880) here's what I add to the end of my ssl middleware module, so that SSLRedirect wont break my automated testing.</p>
<p>It simply creates a dummy middleware class that removes the SSL argument, but does not do any redirecting. …</p>
Freely redistributableSSL Redirect Middleware
2008-07-14T12:52:37.907988-05:00zbyte64http://djangosnippets.org/snippets/880/<p>Snippet 240 is great, but it does not handle flatpages since flatpages are not technically a view. This operates on the request level, not the view level so it will handle flat pages.</p>
<p><strong>Step 1</strong> Add this class to your MIDDLEWARE_CLASSES</p>
<p><strong>Step 2</strong> Add an entry in settings.py which is …</p>
Freely redistributableSSL Middleware for Webfaction
2007-05-16T20:01:12.410485-05:00parlarhttp://djangosnippets.org/snippets/240/<p><em>NOTE Stephen updated his original snippet http://www.djangosnippets.org/snippets/85/ to work with WebFaction, please use his version now</em></p>
<p>This code is 95% from Stephen Zabel's snippet at http://www.djangosnippets.org/snippets/85/. However, his snippet, as it was, wouldn't work when enabling SSL for the admin site on Webfaction. For some reason, the default request.is_secure() doesn't …</p>
Freely redistributable