SlideShare ist ein Scribd-Unternehmen logo
1 von 30
A Case Study of
Django
Web Applications that are Secure by Default
Kishor Kumar Mahato
1407191233
@kisor_143
Web Security Essentials
• The essentials of web application security are still not
well understood.
• Most developers have little to no idea about web
security fundamentals.
• Higher adoption to new web technologies, but no
accompanying security awareness.
Web Security Essentials
• The basic idea of web security: Never trust users,
and never trust their data. No exceptions.
• Many layers exist in web technologies, and therefore
many attack vectors and possibilities.
• Web developers must understand risks and
mitigations for all web layers.
Problems in Applying Web Security
• Web security cannot be achieved if developers are
not well trained in security. Education is key.
• Deadlines will almost always result in security
vulnerabilities. Developers who are too busy and
under pressure will not focus on security.
• Security is not integrated early in the development
process, so it gets delayed/forgotten.
Bad Practices in Web Security
• Developers don’t validate user input.
• Even if they validate it, they do it poorly or out of
context.
• Developers make wrong assumptions about security:
– “It’s ok, we use SSL!”
– “The Firewall will protect us”
– “Who will think of attacking this function?”
• Most developers copy/paste code from the internet.
Admit it.
Bad Practices in Web Security
• Session/password management is done poorly:
– Sessions are easy to forge by attackers.
– Passwords are stored as plaintext.
• Server & Database configuration/security are not
understood by web developers.
• Developers don’t realize the threats on end users:
– Cross Site Scripting (XSS)
– Cross Site Request Forgery (CSRF)
• Django is a Web Application Framework, written in
Python
• Allows rapid, secure and agile web development.
• Write better web applications in less time & effort.
• Django is loaded with security features that are used
by default.
• Security by default provides great protection to
developers with no security experience
• Django makes it more difficult to write insecure
code.
• Django is used by many popular websites/services:
Security Features of Django
• Django provides many default protections against
web threats, mainly against problems of:
– User Management
– Authorization
– Cookies
– SQL Injection
– Cross Site Scripting (XSS)
– Cross Site Request Forgery (CSRF)
– Clickjacking
– Files
– E-mail Header Injection
– Cryptography
– Directory Traversal
User Management
• Django provides a default User model that can be used in
any website. It comes equipped with correct session
management, permissions, registration and login.
• Developers don’t need to re-invent the wheel and re-
introduce user management risks.
• Django provides strong password hashing methods
(bcrypt, PBKDF2, SHA1), with increasing work factors.
•
• Django makes passwords very hard to crack.
User Management
• Django provides easy methods for user management
such as is_authenticated(), permission_required(),
requires_login(), and more, offsetting difficult session
and permission code away from the developer.
• Django provides secure default password reset and login
redirection functionality. Developers don’t need to
create password reset forms and introduce risks.
• By using Django’s user management module, developers
will not make mistakes such as ‘admin=true’ in cookies!
Clickjacking
• Clickjacking is an attack where an attackers loads an
invisible page over a visible one. The user thinks he is
clicking on the visible page, but he’s actually clicking on
invisible buttons and links.
• Can be used to trick users into buying items, deleting
content or adding fake friends online.
• Django provides direct protection against Clickjacking
attacks using the X-Frame-Options header. Only one line
of code!
Clickjacking Example
Image taken from ‘Busting Frame Busting’ research paper (found in references)
Cross Site Scripting (XSS)
• XSS is one of the most dangerous and popular
attacks, where users instead of servers are targeted.
• In an XSS attack, an attacker runs evil scripts on the
user’s browser, through a vulnerable website.
• It can be used to steal cookies, accounts, install
malware, deface websites and many more uses.
Cross Site Scripting (XSS)
• XSS is very easy to introduce by ignorant developers,
example:
• It’s okay if the search query was Car, but what if the
attacker entered…
<script>alert(document.cookie)</script>
<?php
echo "Results for: " . $_GET["query"];
?>
Cross Site Scripting (XSS)
• Evidently XSS is a critical attack, so Django provides great
default protections against it.
• HTML output is always escaped by Django to ensure that user
input cannot execute code.
• Django’s templating engine provides autoescaping.
• HTML Attributes must always be quoted so that Django’s
protections can be activated.
• For extra XSS protections, use ESAPI, lxml, html5lib, Bleach or
Markdown
SQL Injection (SQLi)
• SQL Injection is a dangerous attack in which evil data is sent
to the database to be executed as destructive commands.
• Developers write SQL queries in a wrong way, allowing
attackers to inject SQL commands into the query, to be
executed as SQL code. Example:
• Looks innocent, but what if the user entered ‘; DROP
TABLE USERS;-- ?
string sql = “SELECT * FROM USERS WHERE name=‘” +
Request[‘username’] + “’”;
SQL Injection (SQLi)
• SQL injection attacks are used to read and corrupt databases,
take complete control over servers as well as modify web
pages (and therefore steal user sessions or install malware)
• The good news is that Django provides excellent defense
against SQL Injection!
• Django uses ORM and query sets to make sure all input is
escaped & validated.
• Developers do not need to write any SQL. Just write Python
classes and Django will convert them to SQL securely!
SQL Injection (SQLi)
• No matter where input comes from (GET,POST,COOKIES),
Django will escape all input that goes to the database.
• Even if developers needed to write raw SQL, they can use
placeholders like "Select * from users where id = %s ” which
will safely validate input.
Cookies
• Django sets cookies to HttpOnly by default, to prevent
sessions from getting stolen in most browsers.
• Session ID are never used in URLs even if cookies are disabled.
• Django will always give a new session ID if a user tried a non-
existent one, to protect against session fixation.
• Cookies can be digitally signed and time-stamped, to
protect against tampering of data.
Files
• Django provides excellent protection to files.
• No webroot concept in Django. Only the directories and files
you allow are requested. Even if attackers upload a file, it is
only downloaded if you allow it in URLConf.
• Django executes Python code from the outside of the web
root, so attackers cannot retrieve any files not explicitly
allowed from the web root.
Cross Site Request Forgery (CSRF)
• CSRF is an attack where an attacker can force users of a
website to perform actions without their permission.
• If a user is logged into website A, an attacker can let a user
visit website B, which will perform actions on website A on
behalf of the user.
• This happens because the forms in website A are not
protected against CSRF.
• Basically CSRF means evil websites can let users of other
websites perform actions without user permission.
Cross Site Request Forgery (CSRF)
• Example: A form in website A allows a logged in user to delete
his account. If there is no CSRF protection, website B can
force visitors to delete their account on website A.
• Example: Suppose website B has this HTML form in its code.
What happens if a user of website A visits B?
<form
action="http://websiteA.com/deleteMyAccount.php”
method=”post” >
</form>
Cross Site Request Forgery (CSRF)
• The effects of CSRF is that attackers can make users perform
ANY action on the vulnerable website.
• Django provides CSRF protections for all POST,PUT,DELETE
requests (according to RFC2616).
• If website A used Django CSRF protection, the form would be:
<form action=”/deleteMyAccount.php” method=”post”
>
<input type='hidden' name='csrfmiddlewaretoken'
value='Aes4YiAfBQwCS8d4T1ngDAa6jJQiYDFs' />
</form>
E-mail Header Injection
• E-mail Header injection is a less popular attack that targets
weak email-sending forms in websites.
• By crafting a special string, attackers can use your email form
to spend spam through your mail server, resulting in your
domains/IPs getting blocked and possible worse effects.
• Example email form:
To: mycustomer@example.com
Subject: Customer feedback
<email content here>
E-mail Header Injection
• What if the attacker supplies the following data as the email
content? They will be able to use your website as a spam
base.
• “ncc: spamVictim@example.comn<spam content>”
• It would be:
• Django provides default protection by using the built-in email
form.
To: mycustomer@example.com
Subject: Customer feedback
cc: spamVictim@example.com
<spam message content, buy drugs, lose weight or something>
Final Remarks
• It must be understood that nothing can protect developers if
they refuse to learn about web security and vulnerabilities.
• The point of Django’s default security features is to make it
very easy to add security, and very difficult to remove
security.
• However, developers still need to learn the basics of security
and risk assessment.
• Knowledge is the best defense against web attacks.
References
• http://davidbliss.com/sites-built-using-django
• https://docs.djangoproject.com/en/1.4/topics/security/
• http://www.djangobook.com/en/2.0/chapter20/
• http://seclab.stanford.edu/websec/framebusting/framebust.
pdf
Questions?
• Do not hesitate to ask any question!
• Do not hesitate to let your developers try Django in the
workplace! It could be your road to increased productivity
and security!

Weitere ähnliche Inhalte

Was ist angesagt?

When Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsWhen Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsSimon Willison
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaJim Manico
 
Ekoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's MethodologyEkoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's Methodologybugcrowd
 
Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirtyAndy Dai
 
JavaScript Security
JavaScript SecurityJavaScript Security
JavaScript SecurityJason Harwig
 
The Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile PlatformsThe Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile Platformskosborn
 
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMagno Logan
 
DVWA BruCON Workshop
DVWA BruCON WorkshopDVWA BruCON Workshop
DVWA BruCON Workshoptestuser1223
 
Javascript Security
Javascript SecurityJavascript Security
Javascript Securityjgrahamc
 
DVWA(Damn Vulnerabilities Web Application)
DVWA(Damn Vulnerabilities Web Application)DVWA(Damn Vulnerabilities Web Application)
DVWA(Damn Vulnerabilities Web Application)Soham Kansodaria
 
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security TeamSecrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security TeamOWASP Delhi
 
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015 Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015 lokeshpidawekar
 
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesXXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesAbraham Aranguren
 
A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...Noppadol Songsakaew
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Irfad Imtiaz
 
Client-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesOry Segal
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)nyccamp
 

Was ist angesagt? (20)

When Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsWhen Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentals
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with Java
 
Bug Bounty for - Beginners
Bug Bounty for - BeginnersBug Bounty for - Beginners
Bug Bounty for - Beginners
 
Ekoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's MethodologyEkoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's Methodology
 
Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirty
 
JavaScript Security
JavaScript SecurityJavaScript Security
JavaScript Security
 
The Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile PlatformsThe Hidden XSS - Attacking the Desktop & Mobile Platforms
The Hidden XSS - Attacking the Desktop & Mobile Platforms
 
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
 
DVWA BruCON Workshop
DVWA BruCON WorkshopDVWA BruCON Workshop
DVWA BruCON Workshop
 
Javascript Security
Javascript SecurityJavascript Security
Javascript Security
 
DVWA(Damn Vulnerabilities Web Application)
DVWA(Damn Vulnerabilities Web Application)DVWA(Damn Vulnerabilities Web Application)
DVWA(Damn Vulnerabilities Web Application)
 
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security TeamSecrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
 
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015 Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
 
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesXXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
 
A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 
Client-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript Vulnerabilities
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
 

Andere mochten auch

NOVICOR Consultancy for Technology
NOVICOR Consultancy for TechnologyNOVICOR Consultancy for Technology
NOVICOR Consultancy for TechnologyMustafa Kuğu
 
15 kwaliteitsfactoren - Henk Jan Bijmolt (Cleafs)
15 kwaliteitsfactoren  -  Henk Jan Bijmolt (Cleafs)15 kwaliteitsfactoren  -  Henk Jan Bijmolt (Cleafs)
15 kwaliteitsfactoren - Henk Jan Bijmolt (Cleafs)Affiliate Dag
 
Cute baby animals of all kindz
Cute baby animals of all kindzCute baby animals of all kindz
Cute baby animals of all kindzSpartaKiss
 
The Technology In Education From Children
The Technology In Education From Children The Technology In Education From Children
The Technology In Education From Children Laura Arias Ocampo
 
Rail Transportation Of Ethanol: Will There Be Enough Capacity?
Rail Transportation Of Ethanol: Will There Be Enough Capacity?Rail Transportation Of Ethanol: Will There Be Enough Capacity?
Rail Transportation Of Ethanol: Will There Be Enough Capacity?John Schmitter
 
Turist în orașul meu craiova
Turist în orașul meu  craiovaTurist în orașul meu  craiova
Turist în orașul meu craiovaGheorghitoiumaria
 
company overview
company overviewcompany overview
company overviewnikumoni
 
STR2 Winners Round 3
STR2 Winners Round 3STR2 Winners Round 3
STR2 Winners Round 3Mahindra Rise
 
APBDRF Webinar: Mary Wallace on Patient Nutrition
APBDRF Webinar: Mary Wallace on Patient NutritionAPBDRF Webinar: Mary Wallace on Patient Nutrition
APBDRF Webinar: Mary Wallace on Patient NutritionBen Decker
 
The Baker Family of Cambridgeshire.
The Baker Family of Cambridgeshire.The Baker Family of Cambridgeshire.
The Baker Family of Cambridgeshire.rekab20
 
Mole nikh
Mole nikhMole nikh
Mole nikhnirap61
 
Luke Sanford " A Closer Look In How Luke Communication" 2010
Luke Sanford " A Closer Look In How Luke Communication" 2010 Luke Sanford " A Closer Look In How Luke Communication" 2010
Luke Sanford " A Closer Look In How Luke Communication" 2010 LukeFinlaySanford
 
Adding films on demand to ppt
Adding films on demand to pptAdding films on demand to ppt
Adding films on demand to pptbauder
 

Andere mochten auch (20)

Jesus
JesusJesus
Jesus
 
NOVICOR Consultancy for Technology
NOVICOR Consultancy for TechnologyNOVICOR Consultancy for Technology
NOVICOR Consultancy for Technology
 
Historia de puebla
Historia de pueblaHistoria de puebla
Historia de puebla
 
15 kwaliteitsfactoren - Henk Jan Bijmolt (Cleafs)
15 kwaliteitsfactoren  -  Henk Jan Bijmolt (Cleafs)15 kwaliteitsfactoren  -  Henk Jan Bijmolt (Cleafs)
15 kwaliteitsfactoren - Henk Jan Bijmolt (Cleafs)
 
Drinking ageeeeee
Drinking ageeeeeeDrinking ageeeeee
Drinking ageeeeee
 
Cute baby animals of all kindz
Cute baby animals of all kindzCute baby animals of all kindz
Cute baby animals of all kindz
 
Scout Powerpoint
Scout PowerpointScout Powerpoint
Scout Powerpoint
 
The Technology In Education From Children
The Technology In Education From Children The Technology In Education From Children
The Technology In Education From Children
 
TAB
TABTAB
TAB
 
Rail Transportation Of Ethanol: Will There Be Enough Capacity?
Rail Transportation Of Ethanol: Will There Be Enough Capacity?Rail Transportation Of Ethanol: Will There Be Enough Capacity?
Rail Transportation Of Ethanol: Will There Be Enough Capacity?
 
Turist în orașul meu craiova
Turist în orașul meu  craiovaTurist în orașul meu  craiova
Turist în orașul meu craiova
 
company overview
company overviewcompany overview
company overview
 
Energy
EnergyEnergy
Energy
 
STR2 Winners Round 3
STR2 Winners Round 3STR2 Winners Round 3
STR2 Winners Round 3
 
APBDRF Webinar: Mary Wallace on Patient Nutrition
APBDRF Webinar: Mary Wallace on Patient NutritionAPBDRF Webinar: Mary Wallace on Patient Nutrition
APBDRF Webinar: Mary Wallace on Patient Nutrition
 
The Baker Family of Cambridgeshire.
The Baker Family of Cambridgeshire.The Baker Family of Cambridgeshire.
The Baker Family of Cambridgeshire.
 
Cursos
CursosCursos
Cursos
 
Mole nikh
Mole nikhMole nikh
Mole nikh
 
Luke Sanford " A Closer Look In How Luke Communication" 2010
Luke Sanford " A Closer Look In How Luke Communication" 2010 Luke Sanford " A Closer Look In How Luke Communication" 2010
Luke Sanford " A Closer Look In How Luke Communication" 2010
 
Adding films on demand to ppt
Adding films on demand to pptAdding films on demand to ppt
Adding films on demand to ppt
 

Ähnlich wie Django (Web Applications that are Secure by Default)

Mr. Mohammed Aldoub - A case study of django web applications that are secur...
Mr. Mohammed Aldoub  - A case study of django web applications that are secur...Mr. Mohammed Aldoub  - A case study of django web applications that are secur...
Mr. Mohammed Aldoub - A case study of django web applications that are secur...nooralmousa
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelinesZakaria SMAHI
 
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...IBM Security
 
Vulnerabilities in modern web applications
Vulnerabilities in modern web applicationsVulnerabilities in modern web applications
Vulnerabilities in modern web applicationsNiyas Nazar
 
How to Destroy a Database
How to Destroy a DatabaseHow to Destroy a Database
How to Destroy a DatabaseJohn Ashmead
 
Become a Security Ninja
Become a Security NinjaBecome a Security Ninja
Become a Security NinjaPaul Gilzow
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101 Stormpath
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingSam Bowne
 
Ch 12 Attacking Users - XSS
Ch 12 Attacking Users - XSSCh 12 Attacking Users - XSS
Ch 12 Attacking Users - XSSSam Bowne
 
Top 10 web application security risks akash mahajan
Top 10 web application security risks   akash mahajanTop 10 web application security risks   akash mahajan
Top 10 web application security risks akash mahajanAkash Mahajan
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10bilcorry
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingSam Bowne
 
Security testing presentation
Security testing presentationSecurity testing presentation
Security testing presentationConfiz
 
Web application security part 01
Web application security part 01Web application security part 01
Web application security part 01G Prachi
 
How to Test for The OWASP Top Ten
 How to Test for The OWASP Top Ten How to Test for The OWASP Top Ten
How to Test for The OWASP Top TenSecurity Innovation
 
Do You Write Secure Code? by Erez Metula
Do You Write Secure Code? by Erez MetulaDo You Write Secure Code? by Erez Metula
Do You Write Secure Code? by Erez MetulaAlphageeks
 

Ähnlich wie Django (Web Applications that are Secure by Default) (20)

Mr. Mohammed Aldoub - A case study of django web applications that are secur...
Mr. Mohammed Aldoub  - A case study of django web applications that are secur...Mr. Mohammed Aldoub  - A case study of django web applications that are secur...
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
 
Security testing
Security testingSecurity testing
Security testing
 
Owasp top 10 2017
Owasp top 10 2017Owasp top 10 2017
Owasp top 10 2017
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelines
 
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
 
Vulnerabilities in Web Applications
Vulnerabilities in Web ApplicationsVulnerabilities in Web Applications
Vulnerabilities in Web Applications
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
Vulnerabilities in modern web applications
Vulnerabilities in modern web applicationsVulnerabilities in modern web applications
Vulnerabilities in modern web applications
 
How to Destroy a Database
How to Destroy a DatabaseHow to Destroy a Database
How to Destroy a Database
 
Become a Security Ninja
Become a Security NinjaBecome a Security Ninja
Become a Security Ninja
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
 
Ch 12 Attacking Users - XSS
Ch 12 Attacking Users - XSSCh 12 Attacking Users - XSS
Ch 12 Attacking Users - XSS
 
Top 10 web application security risks akash mahajan
Top 10 web application security risks   akash mahajanTop 10 web application security risks   akash mahajan
Top 10 web application security risks akash mahajan
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
 
Security testing presentation
Security testing presentationSecurity testing presentation
Security testing presentation
 
Web application security part 01
Web application security part 01Web application security part 01
Web application security part 01
 
How to Test for The OWASP Top Ten
 How to Test for The OWASP Top Ten How to Test for The OWASP Top Ten
How to Test for The OWASP Top Ten
 
Do You Write Secure Code? by Erez Metula
Do You Write Secure Code? by Erez MetulaDo You Write Secure Code? by Erez Metula
Do You Write Secure Code? by Erez Metula
 

Kürzlich hochgeladen

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Kürzlich hochgeladen (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Django (Web Applications that are Secure by Default)

  • 1. A Case Study of Django Web Applications that are Secure by Default Kishor Kumar Mahato 1407191233 @kisor_143
  • 2. Web Security Essentials • The essentials of web application security are still not well understood. • Most developers have little to no idea about web security fundamentals. • Higher adoption to new web technologies, but no accompanying security awareness.
  • 3. Web Security Essentials • The basic idea of web security: Never trust users, and never trust their data. No exceptions. • Many layers exist in web technologies, and therefore many attack vectors and possibilities. • Web developers must understand risks and mitigations for all web layers.
  • 4. Problems in Applying Web Security • Web security cannot be achieved if developers are not well trained in security. Education is key. • Deadlines will almost always result in security vulnerabilities. Developers who are too busy and under pressure will not focus on security. • Security is not integrated early in the development process, so it gets delayed/forgotten.
  • 5. Bad Practices in Web Security • Developers don’t validate user input. • Even if they validate it, they do it poorly or out of context. • Developers make wrong assumptions about security: – “It’s ok, we use SSL!” – “The Firewall will protect us” – “Who will think of attacking this function?” • Most developers copy/paste code from the internet. Admit it.
  • 6. Bad Practices in Web Security • Session/password management is done poorly: – Sessions are easy to forge by attackers. – Passwords are stored as plaintext. • Server & Database configuration/security are not understood by web developers. • Developers don’t realize the threats on end users: – Cross Site Scripting (XSS) – Cross Site Request Forgery (CSRF)
  • 7. • Django is a Web Application Framework, written in Python • Allows rapid, secure and agile web development. • Write better web applications in less time & effort.
  • 8. • Django is loaded with security features that are used by default. • Security by default provides great protection to developers with no security experience • Django makes it more difficult to write insecure code.
  • 9. • Django is used by many popular websites/services:
  • 10. Security Features of Django • Django provides many default protections against web threats, mainly against problems of: – User Management – Authorization – Cookies – SQL Injection – Cross Site Scripting (XSS) – Cross Site Request Forgery (CSRF) – Clickjacking – Files – E-mail Header Injection – Cryptography – Directory Traversal
  • 11. User Management • Django provides a default User model that can be used in any website. It comes equipped with correct session management, permissions, registration and login. • Developers don’t need to re-invent the wheel and re- introduce user management risks. • Django provides strong password hashing methods (bcrypt, PBKDF2, SHA1), with increasing work factors. • • Django makes passwords very hard to crack.
  • 12. User Management • Django provides easy methods for user management such as is_authenticated(), permission_required(), requires_login(), and more, offsetting difficult session and permission code away from the developer. • Django provides secure default password reset and login redirection functionality. Developers don’t need to create password reset forms and introduce risks. • By using Django’s user management module, developers will not make mistakes such as ‘admin=true’ in cookies!
  • 13. Clickjacking • Clickjacking is an attack where an attackers loads an invisible page over a visible one. The user thinks he is clicking on the visible page, but he’s actually clicking on invisible buttons and links. • Can be used to trick users into buying items, deleting content or adding fake friends online. • Django provides direct protection against Clickjacking attacks using the X-Frame-Options header. Only one line of code!
  • 14. Clickjacking Example Image taken from ‘Busting Frame Busting’ research paper (found in references)
  • 15. Cross Site Scripting (XSS) • XSS is one of the most dangerous and popular attacks, where users instead of servers are targeted. • In an XSS attack, an attacker runs evil scripts on the user’s browser, through a vulnerable website. • It can be used to steal cookies, accounts, install malware, deface websites and many more uses.
  • 16. Cross Site Scripting (XSS) • XSS is very easy to introduce by ignorant developers, example: • It’s okay if the search query was Car, but what if the attacker entered… <script>alert(document.cookie)</script> <?php echo "Results for: " . $_GET["query"]; ?>
  • 17. Cross Site Scripting (XSS) • Evidently XSS is a critical attack, so Django provides great default protections against it. • HTML output is always escaped by Django to ensure that user input cannot execute code. • Django’s templating engine provides autoescaping. • HTML Attributes must always be quoted so that Django’s protections can be activated. • For extra XSS protections, use ESAPI, lxml, html5lib, Bleach or Markdown
  • 18. SQL Injection (SQLi) • SQL Injection is a dangerous attack in which evil data is sent to the database to be executed as destructive commands. • Developers write SQL queries in a wrong way, allowing attackers to inject SQL commands into the query, to be executed as SQL code. Example: • Looks innocent, but what if the user entered ‘; DROP TABLE USERS;-- ? string sql = “SELECT * FROM USERS WHERE name=‘” + Request[‘username’] + “’”;
  • 19. SQL Injection (SQLi) • SQL injection attacks are used to read and corrupt databases, take complete control over servers as well as modify web pages (and therefore steal user sessions or install malware) • The good news is that Django provides excellent defense against SQL Injection! • Django uses ORM and query sets to make sure all input is escaped & validated. • Developers do not need to write any SQL. Just write Python classes and Django will convert them to SQL securely!
  • 20. SQL Injection (SQLi) • No matter where input comes from (GET,POST,COOKIES), Django will escape all input that goes to the database. • Even if developers needed to write raw SQL, they can use placeholders like "Select * from users where id = %s ” which will safely validate input.
  • 21. Cookies • Django sets cookies to HttpOnly by default, to prevent sessions from getting stolen in most browsers. • Session ID are never used in URLs even if cookies are disabled. • Django will always give a new session ID if a user tried a non- existent one, to protect against session fixation. • Cookies can be digitally signed and time-stamped, to protect against tampering of data.
  • 22. Files • Django provides excellent protection to files. • No webroot concept in Django. Only the directories and files you allow are requested. Even if attackers upload a file, it is only downloaded if you allow it in URLConf. • Django executes Python code from the outside of the web root, so attackers cannot retrieve any files not explicitly allowed from the web root.
  • 23. Cross Site Request Forgery (CSRF) • CSRF is an attack where an attacker can force users of a website to perform actions without their permission. • If a user is logged into website A, an attacker can let a user visit website B, which will perform actions on website A on behalf of the user. • This happens because the forms in website A are not protected against CSRF. • Basically CSRF means evil websites can let users of other websites perform actions without user permission.
  • 24. Cross Site Request Forgery (CSRF) • Example: A form in website A allows a logged in user to delete his account. If there is no CSRF protection, website B can force visitors to delete their account on website A. • Example: Suppose website B has this HTML form in its code. What happens if a user of website A visits B? <form action="http://websiteA.com/deleteMyAccount.php” method=”post” > </form>
  • 25. Cross Site Request Forgery (CSRF) • The effects of CSRF is that attackers can make users perform ANY action on the vulnerable website. • Django provides CSRF protections for all POST,PUT,DELETE requests (according to RFC2616). • If website A used Django CSRF protection, the form would be: <form action=”/deleteMyAccount.php” method=”post” > <input type='hidden' name='csrfmiddlewaretoken' value='Aes4YiAfBQwCS8d4T1ngDAa6jJQiYDFs' /> </form>
  • 26. E-mail Header Injection • E-mail Header injection is a less popular attack that targets weak email-sending forms in websites. • By crafting a special string, attackers can use your email form to spend spam through your mail server, resulting in your domains/IPs getting blocked and possible worse effects. • Example email form: To: mycustomer@example.com Subject: Customer feedback <email content here>
  • 27. E-mail Header Injection • What if the attacker supplies the following data as the email content? They will be able to use your website as a spam base. • “ncc: spamVictim@example.comn<spam content>” • It would be: • Django provides default protection by using the built-in email form. To: mycustomer@example.com Subject: Customer feedback cc: spamVictim@example.com <spam message content, buy drugs, lose weight or something>
  • 28. Final Remarks • It must be understood that nothing can protect developers if they refuse to learn about web security and vulnerabilities. • The point of Django’s default security features is to make it very easy to add security, and very difficult to remove security. • However, developers still need to learn the basics of security and risk assessment. • Knowledge is the best defense against web attacks.
  • 29. References • http://davidbliss.com/sites-built-using-django • https://docs.djangoproject.com/en/1.4/topics/security/ • http://www.djangobook.com/en/2.0/chapter20/ • http://seclab.stanford.edu/websec/framebusting/framebust. pdf
  • 30. Questions? • Do not hesitate to ask any question! • Do not hesitate to let your developers try Django in the workplace! It could be your road to increased productivity and security!