Changeset - bb573ebee4dc
[Not reviewed]
0 1 0
Sachi King - 7 years ago 2017-04-30 02:10:56
nakato@nakato.io
settings - DEBUG hardening

DEBUG is something that should never be turned in on prod. As such,
lets be extremely specific on what we expect to process.

As we'll be taking this in from the environment, it's ensured we will
get a string. So we'll always get and only handle this in string
form. If it's anything else, it's an operational error and we bail.

(Note: bool('0') is truthy, so we make sure we leverge our string -> int
-> bool every time, so corectness can be noticed if it is not)
1 file changed with 13 insertions and 1 deletions:
0 comments (0 inline, 0 general)
pinaxcon/settings.py
Show inline comments
...
 
@@ -13,7 +13,19 @@ BASE_DIR = PACKAGE_ROOT
 

	
 
### USER SETTINGS
 

	
 
DEBUG = True
 
DEBUG = os.environ.get('SYMPOSION_APP_DEBUG', '0')
 
if isinstance(DEBUG, str):
 
    try:
 
        i = int(DEBUG)
 
        if not i in [0, 1]:
 
            raise ValueError("not 0 or 1")
 
        DEBUG = bool(i)
 
    except ValueError:
 
        sys.exit('DEBUG env var must be set to string value of a 0 or 1')
 
else:
 
    sys.exit('DEBUG env var is in unexpected format.  Should be a string'
 
             'containing either a 0 or a 1 - Got type %s' % type(DEBUG))
 

	
 
DATABASES = {
 
    "default": {
 
        "ENGINE": "django.db.backends.sqlite3",
0 comments (0 inline, 0 general)