0% found this document useful (0 votes)
2K views

Secure Coding Practices

The document discusses secure coding practices and common application threats. It provides an overview of the OWASP Top 10 security risks, including injection, broken authentication, sensitive data exposure, XML external entities, broken access control, security misconfiguration, cross-site scripting, insecure deserialization, use of components with known vulnerabilities, and insufficient logging and monitoring. It also lists the top 25 risks from SANS, such as SQL injection, OS command injection, buffer overflows, missing authentication, unauthorized access, use of hard-coded credentials, missing encryption of sensitive data, and others. Finally, it extracts one best practice related to database security around using strongly typed parameterized queries.

Uploaded by

das
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Secure Coding Practices

The document discusses secure coding practices and common application threats. It provides an overview of the OWASP Top 10 security risks, including injection, broken authentication, sensitive data exposure, XML external entities, broken access control, security misconfiguration, cross-site scripting, insecure deserialization, use of components with known vulnerabilities, and insufficient logging and monitoring. It also lists the top 25 risks from SANS, such as SQL injection, OS command injection, buffer overflows, missing authentication, unauthorized access, use of hard-coded credentials, missing encryption of sensitive data, and others. Finally, it extracts one best practice related to database security around using strongly typed parameterized queries.

Uploaded by

das
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

SECURE CODING PRACTICES

Date :
By:
Guide Overview
■ Technology agnostic coding practices

■ What to do, not how to do it

■ Compact, but comprehensive checklist


format
■ Focuses on secure coding requirements,
rather then on vulnerabilities and exploits
■ Includes a cross referenced glossary to get
developers and security folks talking the
same language

2
5 Common Application Threats

■ Security Misconfiguration
■ Malware
■ Injection Attacks
■ Phishing Scam
■ Brute Force
Owasp Top 10
OWASP Top 10 Application Security Risks - 2017

A1:2017-Injection
Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to
an interpreter as part of a command or query. The attacker's hostile data can trick the interpreter
into executing unintended commands or accessing data without proper authorization.
A2:2017-Broken Authentication
Application functions related to authentication and session management are often implemented
incorrectly, allowing attackers to compromise passwords, keys, or session tokens, or to exploit
other implementation flaws to assume other users' identities temporarily or permanently.
A3:2017-Sensitive Data Exposure
Many web applications and APIs do not properly protect sensitive data, such as financial,
healthcare, and PII. Attackers may steal or modify such weakly protected data to conduct credit
card fraud, identity theft, or other crimes. Sensitive data may be compromised without extra
protection, such as encryption at rest or in transit, and requires special precautions when
exchanged with the browser.
Owasp Top 10

OWASP Top 10 Application Security Risks - 2017


A4:2017-XML External Entities (XXE)
Many older or poorly configured XML processors evaluate external entity references within XML
documents. External entities can be used to disclose internal files using the file URI handler, internal file
shares, internal port scanning, remote code execution, and denial of service attacks.
A5:2017-Broken Access Control
Restrictions on what authenticated users are allowed to do are often not properly enforced. Attackers can
exploit these flaws to access unauthorized functionality and/or data, such as access other users'
accounts, view sensitive files, modify other users' data, change access rights, etc.
A6:2017-Security Misconfiguration
Security misconfiguration is the most commonly seen issue. This is commonly a result of insecure default
configurations, incomplete or ad hoc configurations, open cloud storage, misconfigured HTTP headers,
and verbose error messages containing sensitive information. Not only must all operating systems,
frameworks, libraries, and applications be securely configured, but they must be patched/upgraded in a
timely fashion.
A7:2017-Cross-Site Scripting (XSS)
XSS flaws occur whenever an application includes untrusted data in a new web page without proper
validation or escaping, or updates an existing web page with user-supplied data using a browser API that
can create HTML or JavaScript. XSS allows attackers to execute scripts in the victim's browser which can
hijack user sessions, deface web sites, or redirect the user to malicious sites.
Owasp Top 10

OWASP Top 10 Application Security Risks - 2017


A8:2017-Insecure Deserialization
Insecure deserialization often leads to remote code execution. Even if deserialization flaws do not
result in remote code execution, they can be used to perform attacks, including replay attacks,
injection attacks, and privilege escalation attacks.
A9:2017-Using Components with Known Vulnerabilities
Components, such as libraries, frameworks, and other software modules, run with the same
privileges as the application. If a vulnerable component is exploited, such an attack can facilitate
serious data loss or server takeover. Applications and APIs using components with known
vulnerabilities may undermine application defenses and enable various attacks and impacts.
A10:2017-Insufficient Logging&Monitoring
Insufficient logging and monitoring, coupled with missing or ineffective integration with incident
response, allows attackers to further attack systems, maintain persistence, pivot to more systems,
and tamper, extract, or destroy data. Most breach studies show time to detect a breach is over 200
days, typically detected by external parties rather than internal processes or monitoring.
Owasp Top 10
OWASP Top 10 Application Security Risks - 2017

A1:2017-Injection
Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker's hostile data can trick the interpreter
into executing unintended commands or accessing data without proper authorization.
A2:2017-Broken Authentication
Application functions related to authentication and session management are often implemented incorrectly, allowing attackers to compromise passwords, keys, or session tokens, or to exploit other
implementation flaws to assume other users' identities temporarily or permanently.
A3:2017-Sensitive Data Exposure
Many web applications and APIs do not properly protect sensitive data, such as financial, healthcare, and PII. Attackers may steal or modify such weakly protected data to conduct credit card fraud,
identity theft, or other crimes. Sensitive data may be compromised without extra protection, such as encryption at rest or in transit, and requires special precautions when exchanged with the
browser.
A4:2017-XML External Entities (XXE)
Many older or poorly configured XML processors evaluate external entity references within XML documents. External entities can be used to disclose internal files using the file URI handler, internal
file shares, internal port scanning, remote code execution, and denial of service attacks.
A5:2017-Broken Access Control
Restrictions on what authenticated users are allowed to do are often not properly enforced. Attackers can exploit these flaws to access unauthorized functionality and/or data, such as access other
users' accounts, view sensitive files, modify other users' data, change access rights, etc.
A6:2017-Security Misconfiguration
Security misconfiguration is the most commonly seen issue. This is commonly a result of insecure default configurations, incomplete or ad hoc configurations, open cloud storage, misconfigured
HTTP headers, and verbose error messages containing sensitive information. Not only must all operating systems, frameworks, libraries, and applications be securely configured, but they must be
patched/upgraded in a timely fashion.
A7:2017-Cross-Site Scripting (XSS)
XSS flaws occur whenever an application includes untrusted data in a new web page without proper validation or escaping, or updates an existing web page with user-supplied data using a browser
API that can create HTML or JavaScript. XSS allows attackers to execute scripts in the victim's browser which can hijack user sessions, deface web sites, or redirect the user to malicious sites.
A8:2017-Insecure Deserialization
Insecure deserialization often leads to remote code execution. Even if deserialization flaws do not result in remote code execution, they can be used to perform attacks, including replay attacks,
injection attacks, and privilege escalation attacks.
A9:2017-Using Components with Known Vulnerabilities
Components, such as libraries, frameworks, and other software modules, run with the same privileges as the application. If a vulnerable component is exploited, such an attack can facilitate serious
data loss or server takeover. Applications and APIs using components with known vulnerabilities may undermine application defenses and enable various attacks and impacts.
A10:2017-Insufficient Logging&Monitoring
Insufficient logging and monitoring, coupled with missing or ineffective integration with incident response, allows attackers to further attack systems, maintain persistence, pivot to more systems, and
tamper, extract, or destroy data. Most breach studies show time to detect a breach is over 200 days, typically detected by external parties rather than internal processes or monitoring.
SANS Top 25

■ 1 Improper Neutralization of Special Elements used in an SQL Command


('SQL Injection')
■ 2 Improper Neutralization of Special Elements used in an OS Command ('OS
Command Injection')
■ 3 Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
■ 4 Improper Neutralization of Input During Web Page Generation ('Cross-site
Scripting')
■ 5 Missing Authentication for Critical Function
■ 6 Missing Authorization
■ 7 Use of Hard-coded Credentials
SANS Top 25

■ 8 Missing Encryption of Sensitive Data


■ 9 Unrestricted Upload of File with Dangerous Type
■ 10 Reliance on Untrusted Inputs in a Security Decision
■ 11 Execution with Unnecessary Privileges
■ 12 Cross-Site Request Forgery (CSRF)
■ 13 Improper Limitation of a Pathname to a Restricted Directory ('Path
Traversal')
■ 14 Download of Code Without Integrity Check
SANS Top 25

■ 15 Incorrect Authorization
■ 16 Inclusion of Functionality from Untrusted Control Sphere
■ 17 Incorrect Permission Assignment for Critical Resource
■ 18 Use of Potentially Dangerous Function
■ 19 Use of a Broken or Risky Cryptographic Algorithm
■ 20 Incorrect Calculation of Buffer Size
■ 22 URL Redirection to Untrusted Site ('Open Redirect')
■ 23 Uncontrolled Format String
■ 24 Integer Overflow or Wraparound
Extract - Database Security
 Use strongly typed parameterized queries. Parameterized queries keep the
query and data separate through the use of placeholders. The query structure is
defined with place holders and then the application specifies the contents of
each placeholder.
 Utilize input validation and if validation fails, do not run the database command.
 Ensure that variables are strongly typed.
 Escape meta characters in SQL statements.
 The application should use the lowest possible level of privilege when accessing
the database.
 Use secure credentials for database access.
 Do not provide connection strings or credentials directly to the client. If this is
unavoidable, encrypted them.
 Use stored procedures to abstract data access.
 Turn off any database functionality (e.g., unnecessary stored procedures or
services).
 Eliminate default content.
 Disable any default accounts that are not required to support business
requirements.
 Close the connection as soon as possible.
 The application should connect to the database with different credentials for
every trust distinction (e.g., user, read-only user, guest, administrators). 11
Using the guide
■ Scenario #1: Developing Guidance Documents

Coding Practices

Guiding Principles What to do How to do it

Security Applicatio Applicatio


Policies n Security n Security
Procedure Coding
s Standards

12
Using the guide continued
■ Scenario #2: Support Secure Development
Lifecycle

What to do How you should do it What you did Did it work

Application Application Review Test Solution


Security Development Practices Solutions Implementation
Requirements
Standardized Libraries
Standard Guidance for
non-Library Solutions

Coding Practices

13
Using the guide continued
■ Scenario #3: Contracted Development
■ Identify security requirements to be added to outsourced
software development projects.
■ Include them in the RFP and Contract

We can Coding Practices


How do I I need
build
make it cool
anything
work Softwar
e
RFP
Best
Contract
Software
Best
Ever
Software
Ever

Programm Salesm Custom


er an er
14
Checklist Sections
 Data Validation
 Authentication and Password Management
 Authorization and Access Management
 Session Management
 Sensitive Information Storage or
Transmission
 System Configuration Management
 General Coding Practices
 Database Security
 File Management
 Memory Management
15
Checklist Practices
■ Short and to the point.

■ Straight forward "do this" or "don't do that"

■ Does not attempt to rank the practices

■ Some practices are conditional recommendations


that depend on the criticality of the system or
information

■ The security implications of not following any of


the practices that apply to the application, should
be clearly understood

16
Summary
■ Makes it easier for development teams to quickly
understand secure coding practices

■ Assists with defining requirements and adding


them to policies and contracts

■ Provides a context and vocabulary for


interactions with security staff

■ Serves as an easy desk reference

17
A Secure Development
Framework
Guidance on implementing a secure software development framework
is beyond the scope of the Quick reference Guide, however the
following OWASP projects can help:

■ Implement a secure software development lifecycle


– OWASP CLASP Project
■ Establish secure coding standards
– OWASP Development Guide Project
■ Build a re-usable object library
– OWASP Enterprise Security API (ESAPI) Project
■ Verify the effectiveness of security controls
– OWASP Application Security Verification Standard (ASVS)
Project)
■ Establish secure outsourced development practices including
defining security requirements and verification methodologies in
both the RFP and contract
– OWASP Legal Project

18
Questions

19

You might also like