Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is using thread locals in Django bad?
    primarykey
    data
    text
    <p>I am using thread locals to store the current user and request objects. This way I can have easy access to the request from anywhere in the programme (e.g. dynamic forms) without having to pass them around.</p> <p>To implement the thread locals storage in a middleware, I followed a tutorial on the Django site: <a href="http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=18" rel="noreferrer">http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=18</a></p> <p>This document has since been modified to suggest avoiding this technique: <a href="http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=20" rel="noreferrer">http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=20</a></p> <p>From the article:</p> <blockquote> <p>From a design point of view, threadlocals are essentially global variables, and are subject to all the usual problems of portability and predictability that global variables usually entail.</p> <p>More importantly, from a security point of view, threadlocals pose a huge risk. By providing an data store that exposes the state of other threads, you provide a way for one thread in your web server to potentially modify the state of another thread in the system. If the threadlocal data contains descriptions of users or other authentication-related data, that data could be used as the basis for an attack that grants access to an unauthorized user, or exposes private details of a user. While it is possible to build a threadlocal system that is safe from this sort of attack, it's a lot easier to be defensive and build a system that isn't subject to any such vulnerability in the first place.</p> </blockquote> <p>I understand why global variables can be bad, but in this case I'm running my own code on my own server so I can't see what danger two global variables pose.</p> <p>Can someone explain the security issue involved? I have asked many people how they would hack my application if they read this article and know I'm using thread locals, yet no one has been able to tell me. I am starting to suspect that this is an opinion held by hair-splitting purists who love to pass objects explicitly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload