0
0
Djangoframework~5 mins

SECRET_KEY and security settings in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the SECRET_KEY in a Django project?
The SECRET_KEY is a secret value used by Django to provide cryptographic signing. It helps protect data like session cookies and password reset tokens from being tampered with.
Click to reveal answer
beginner
Why should the SECRET_KEY never be shared or exposed publicly?
If the SECRET_KEY is exposed, attackers can forge session cookies or tokens, leading to security breaches like user impersonation or data leaks.
Click to reveal answer
intermediate
Name two important security settings in Django besides SECRET_KEY.
1. DEBUG: Should be set to False in production to avoid showing sensitive error details.<br>2. ALLOWED_HOSTS: Lists the host/domain names your Django site can serve to prevent HTTP Host header attacks.
Click to reveal answer
beginner
What is the risk of setting DEBUG = True in a production environment?
With DEBUG = True, detailed error pages with sensitive information are shown to users, which can help attackers find vulnerabilities.
Click to reveal answer
intermediate
How can you keep your SECRET_KEY safe when sharing your Django project code?
You can store the SECRET_KEY outside your code, for example in environment variables or separate config files not included in version control, so it is not shared publicly.
Click to reveal answer
What is the main use of Django's SECRET_KEY?
ATo sign cookies and tokens securely
BTo connect to the database
CTo set the website title
DTo configure static files
Which setting should be False in production to avoid exposing sensitive info?
AALLOWED_HOSTS
BDEBUG
CINSTALLED_APPS
DSTATIC_URL
What does the ALLOWED_HOSTS setting do?
AStores the secret key
BEnables debug mode
CLists allowed domain names for the site
DDefines database connections
What is a good practice to keep your SECRET_KEY safe?
AUse a simple string like 'password'
BHardcode it in your public code
CShare it on GitHub
DStore it in environment variables
What could happen if your SECRET_KEY is leaked?
AAttackers can forge session cookies
BYour database will be deleted
CYour website will load slower
DYour static files won't load
Explain why the SECRET_KEY is critical for Django security and how to protect it.
Think about what happens if someone can fake your cookies or tokens.
You got /3 concepts.
    Describe the role of DEBUG and ALLOWED_HOSTS settings in securing a Django app.
    Consider what happens if error details are shown or if any host can access your app.
    You got /3 concepts.