SlideShare a Scribd company logo
Secure Coding
Web Application SecurityVulnerabilities and Best Practices
What is Secure
Coding?
Is it this?
...or this?
...maybe even this?
Security Principles
• Minimise Attack Surface Area	

• Establish Secure Defaults	

• Principle of Least Privilege	

• Principle of Defence in Depth	

• Fail Securely	

• Separation of Duties	

• Avoid Security by Obscurity	

• Keep Security Simple	

• Fix Security Issues Correctly
Minimise Attack Surface
• Every feature or technology is a risk.	

• Secure development is all about reducing
the risk by minimising the attack surface.
Thanks Boromir.
Establish Secure
Defaults
• By default a system should be secure out-
of-the-box.	

• It should be up to the user to reduce their
security if allowed.
Trust Morpheus!
Principle of Least
Privilege
• Use the least possible privilege to perform
the required business task.
Don’t be the luser!
Principle of Defence in
Depth
• Always consider that upper layers are
already compromised.
This is how we do it.
Fail Securely
• Code fails regularly.
Fail Securely
isAdmin = true;	
!
try {	
codeWhichMayFail();	
isAdmin = isUserInRole("Administrator");	
} catch (Exception ex) {	
log.write(ex.toString());	
}
Separation of Duties
• Some roles have different levels of trust
than normal users.
Hell yeah!?!
Avoid Security By
Obscurity
• Security By Obscurity is a weak security
control.	

• Security By Obscurity depends on
knowledge.
Don’t be like Dawson!
Keep Security Simple
• Simplicity leads to better understanding the
system and its constraints.
Please!
Fix Security Issues
Correctly
• Understand the root cause of the problem.	

• Identify the the pattern of the problem.	

• Some issues are wide-spread across the
code base.	

• Develop a Fix	

• Develop Tests
Fix Security Issues Correctly
PHP Hash Collision DOS(CVE-2011-4885)
• Problem: PHP was found vulnerable to a
denial of service by submitting a large
amount of specially crafted variables	

• Solution: max_input_vars was introduced
to limit the number of variables that can be
used in a request
Fix Security Issues Correctly
PHP Remote Code Execution(CVE-2012-0830)
if (sapi_module.input_filter(PARSE_POST, var, &val, val_len, &new_val_len TSRMLS_CC)) {	
php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC);	
}	
!
... code removed ...	
!
PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars_array TSRMLS_DC)	
{	
!
... code removed ...	
!
if (is_array) {	
!
... code removed ...	
!
if (zend_hash_num_elements(symtable1) <= PG(max_input_vars)) {	
if (zend_hash_num_elements(symtable1) == PG(max_input_vars)) {	
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));	
}	
MAKE_STD_ZVAL(gpc_element);	
array_init(gpc_element);	
zend_symtable_update(symtable1, escaped_index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);	
}	
!
... code removed ...	
!
symtable1 = Z_ARRVAL_PP(gpc_element_p);	
!
... code removed ...	
!
}
Fix Security Issues Correctly
PHP Remote Code Execution(CVE-2012-0830)
• Vulnerability occurs when max_input_vars is
exceeded and the variable is an array.	

• Code execution occurs when Z_ARRVAL_PP is
called to obtain reference of an updated
hashtable.	

• If number of variables is greater than
max_input_vars, gpc_element will point to the
previous variable value, which is not initialised
memory.
Security in Languages
Rails/Grails/MVC
• Model/View/Controller and scaffolding
paradigm is often abused.
Python
• Python has a funny way of dealing with
different data types.
Python
Number Rounding
round(4000/5000)	
# vs	
round(4000.0/5000)
JavaScript Type
Problems
• JavaScript has loose semantics on its types.
JavaScript
Types Differences
{} + {} = NaN	
{} + [] = 0	
[] + {} = "[object Object]"	
[] + [] = ""	
{} - 1 = -1	
[] - 1 = -1	
-1 + {} = "-1[object Object]"	
-1 + [] = "-1"
JavaScript
Obfuscation
$=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")
[$],_$_:++$,$_$$:({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$
$_:(!""+"")[$],$__:++$,$_$:++$,$$__:({}+"")[$],$$_:++$,$$
$:++$,$___:++$,$__$:++$};$.$_=($.$_=$+"")[$.$_$]+($._$=$.
$_[$.__$])+($.$$=($.$+"")[$.__$])+((!$)+"")[$._$$]+($.__=
$.$_[$.$$_])+($.$=(!""+"")[$.__$])+($._=(!""+"")[$._$_])+
$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+(!""+"")[$._$$]+$.__+
$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];$.$($.$($.$$+"""+$.
$_$_+(![]+"")[$._$_]+$.$$$_+""+$.__$+$.$$_+$._$_+$.__
+"("+$.__$+""+$.$__+$.___+")"+""")())();	
!
// equal to	
!
alert(1);
C
• In C the type system is completely
arbitrary. You can do whatever you like
with pointers.
Ruby
• The Ruby language supports the use of
system commands.	

• Kernel.system provides means of injecting
malicious input into the application to
bypass security measures.
Struts
• Struts allows you to do dynamic method invocation	

• http://host/struts2_security_vulnerability/
changepassword!changePassword.action?
newPassword=my_new_password&username=bruce
• <init-param>

<param-
name>struts.enable.DynamicMethodInvocation</
param-name><param-value>false</param-
value></init-param>
Thanks!

More Related Content

PDF
Secure Coding principles by example: Build Security In from the start - Carlo...
PDF
Secure code
PPTX
Secure Coding 101 - OWASP University of Ottawa Workshop
PPTX
Secure coding practices
PDF
Secure coding presentation Oct 3 2020
PPT
Top 10 Web Security Vulnerabilities (OWASP Top 10)
ODP
OWASP Secure Coding
PPTX
How to Test for The OWASP Top Ten
Secure Coding principles by example: Build Security In from the start - Carlo...
Secure code
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure coding practices
Secure coding presentation Oct 3 2020
Top 10 Web Security Vulnerabilities (OWASP Top 10)
OWASP Secure Coding
How to Test for The OWASP Top Ten

What's hot (20)

PPTX
Secure coding practices
PPTX
Owasp top 10 vulnerabilities
PPT
Secure code practices
ODP
Secure coding in C#
PDF
Threat Modeling Using STRIDE
PDF
OWASP Top 10 Web Application Vulnerabilities
PPSX
Web application security
PDF
Secure Coding for Java
PPTX
Vulnerabilities in modern web applications
PPTX
Cyber Security 101: Training, awareness, strategies for small to medium sized...
PDF
Application Threat Modeling
PPTX
Security Code Review 101
PDF
Enterprise Security Architecture for Cyber Security
PDF
Secure coding-guidelines
PDF
Application Security | Application Security Tutorial | Cyber Security Certifi...
PPTX
Build an Information Security Strategy
PPTX
OWASP Top 10 2021 Presentation (Jul 2022)
PPTX
Java Secure Coding Practices
PDF
Vulnerability Management
PDF
Secure Code Review 101
Secure coding practices
Owasp top 10 vulnerabilities
Secure code practices
Secure coding in C#
Threat Modeling Using STRIDE
OWASP Top 10 Web Application Vulnerabilities
Web application security
Secure Coding for Java
Vulnerabilities in modern web applications
Cyber Security 101: Training, awareness, strategies for small to medium sized...
Application Threat Modeling
Security Code Review 101
Enterprise Security Architecture for Cyber Security
Secure coding-guidelines
Application Security | Application Security Tutorial | Cyber Security Certifi...
Build an Information Security Strategy
OWASP Top 10 2021 Presentation (Jul 2022)
Java Secure Coding Practices
Vulnerability Management
Secure Code Review 101
Ad

Similar to Secure Coding - Web Application Security Vulnerabilities and Best Practices (20)

PPTX
Secure programming with php
PDF
Secure PHP Coding
PDF
ZendCon Security
PDF
php blunders
PPTX
Real-World WebAppSec Flaws - Examples and Countermeasues
PPT
Eight simple rules to writing secure PHP programs
PDF
11 PHP Security #burningkeyboards
PPTX
Secure coding - Balgan - Tiago Henriques
PDF
Defensive Coding Crash Course
PDF
Php Security
PDF
Injecting simplicity not SQL RSA Europe 2010
PDF
Defensive Coding Crash Course - ZendCon 2017
PDF
OWASP TOP 10 by Team xbios
PPT
Secure coding checklist
PDF
Injecting simplicity not SQL BSides Las Vegas 2010
PDF
Session10-PHP Misconfiguration
ODP
Break it while you make it: writing (more) secure software
PPTX
Something Died Inside Your Git Repo
PPTX
Ebu class edgescan-2017
PPTX
Security Training: #4 Development: Typical Security Issues
Secure programming with php
Secure PHP Coding
ZendCon Security
php blunders
Real-World WebAppSec Flaws - Examples and Countermeasues
Eight simple rules to writing secure PHP programs
11 PHP Security #burningkeyboards
Secure coding - Balgan - Tiago Henriques
Defensive Coding Crash Course
Php Security
Injecting simplicity not SQL RSA Europe 2010
Defensive Coding Crash Course - ZendCon 2017
OWASP TOP 10 by Team xbios
Secure coding checklist
Injecting simplicity not SQL BSides Las Vegas 2010
Session10-PHP Misconfiguration
Break it while you make it: writing (more) secure software
Something Died Inside Your Git Repo
Ebu class edgescan-2017
Security Training: #4 Development: Typical Security Issues
Ad

More from Websecurify (12)

PDF
Security Challenges in Node.js
PDF
Unicode - Hacking The International Character System
PDF
Next Generation of Web Application Security Tools
PDF
Web Application Security 101 - 14 Data Validation
PDF
Web Application Security 101 - 12 Logging
PDF
Web Application Security 101 - 10 Server Tier
PDF
Web Application Security 101 - 07 Session Management
PDF
Web Application Security 101 - 06 Authentication
PDF
Web Application Security 101 - 05 Enumeration
PDF
Web Application Security 101 - 04 Testing Methodology
PDF
Web Application Security 101 - 03 Web Security Toolkit
PDF
Web Application Security 101 - 02 The Basics
Security Challenges in Node.js
Unicode - Hacking The International Character System
Next Generation of Web Application Security Tools
Web Application Security 101 - 14 Data Validation
Web Application Security 101 - 12 Logging
Web Application Security 101 - 10 Server Tier
Web Application Security 101 - 07 Session Management
Web Application Security 101 - 06 Authentication
Web Application Security 101 - 05 Enumeration
Web Application Security 101 - 04 Testing Methodology
Web Application Security 101 - 03 Web Security Toolkit
Web Application Security 101 - 02 The Basics

Recently uploaded (20)

PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
L1 - Introduction to python Backend.pptx
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administraation Chapter 3
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
How Creative Agencies Leverage Project Management Software.pdf
PTS Company Brochure 2025 (1).pdf.......
Adobe Illustrator 28.6 Crack My Vision of Vector Design
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
L1 - Introduction to python Backend.pptx
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo POS Development Services by CandidRoot Solutions
System and Network Administraation Chapter 3
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
wealthsignaloriginal-com-DS-text-... (1).pdf
top salesforce developer skills in 2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf
How to Choose the Right IT Partner for Your Business in Malaysia

Secure Coding - Web Application Security Vulnerabilities and Best Practices