SlideShare a Scribd company logo
1 of 78
Download to read offline
@carlobonamico#devoxxuk
Web Application Security
Reloaded for the HTML5 era
Carlo Bonamico
@carlobonamico
carlo.bonamico@nispro.it
http://www.nispro.it
Designing and implementing
secure Single Page Applications
https://wall-simple.sli.do/#/event/cmnxxfl0/section/18289/questions
@carlobonamico#devoxxuk
About me
Speaker Bio
– passionate software developer since the C128 era
– PhD and research at the University of Genova / CNIT National TLC
Research Consortium
– exciting time at startup Eptamedia
– now a Solution Architect and Senior Trainer at NIS s.r.l.

between Italy and new London office
Current projects & interests
– training/mentoring teams on AngularJS, Web Security, Continuous
Integration & Delivery
– creating component-based Angular applications
– security reviews and assessments
@carlobonamico#devoxxuk
Abstract
Ten years after the first OWASP Top Ten list of Web Application Security risks has been
published, the basics of protecting a typical JEE/Rails/PHP/.NET, webapp are becoming
mainstream knowledge (although never enough, as the endless series of high profile
vulerabilities demonstates).
But the industry-wide move towards HTML5 and Single Page Applications, motivated by the
opportunity for more sophisticated interaction and UX, is again upsetting the balance
between Hackers and Developers. A wave of new-generation front-end technologies such as
Web Components, AngularJS and Ember is Developers are attracting Developers with their
combination of productivity and innovative UX, but at the same time opens the door to new
vulnerabilities and security challenges.
This talk will summarize the main principles of Secure Coding, and will discuss their
application to HTML5 applications that interact with REST or WebSocket backends to
prevent major risks (including OWASP Top Ten).
A concrete example will demonstrate the use of tools and libraries, from RBAC to JWT, from
Spring Security to AngularJS modules for implementing secure HTML5/JS apps.
@carlobonamico#devoxxuk
Evolution of Application Security
When I taught my first Web Application Security training
– most participants had never heard of SQL Injection and XSS
Thanks to many industry and community players (especially OWASP),
– not to mention many high-profile incidents,
things have started to change... Application Security
Ensuring Application
guarantees
•Confidentiality
•Integrity
•Availability
•Accountability
of the Information
it processes
@carlobonamico#devoxxuk
Are we doing better?
It's 2015... we were promised flying cars... and what we got is...
See also
– http://www.cvedetails.com/vulnerabilities-by-types.php
– https://www.whitehatsec.com/resource/stats.html
@carlobonamico#devoxxuk
Enter HTML5
After years of playing catch-up with Desktop,
the Web is now often the default development target
– powerful APIs
– interactivity
– always up-to-date & cross-platform
the mobile web just adds more push to that
=> the rise of the Single Page Application
Somewhat ill-defined term, but you know what I mean
– HTML templates, statically served
– client retrieves data from REST services / websockets
– views dynamically rendered on the client side
@carlobonamico#devoxxuk
HTML5 apps
Definitely more powerful that traditional request-response webapps
also more secure?
@carlobonamico#devoxxuk
First problem
Spiderman's Uncle Ben version:
With great power comes great responsibility...
The Web Application Security version:
With great power come more holes and greater risks!
– increased Surface of Attack

Websockets, storage, apis...
– https://html5sec.org/
– http://html5security.org/
– and once you penetrate the browser, you can do basically everything

and I mean it: calling APIs, install keyloggers, redirect user behaviour,
capture private data
–http://xenotix.in/ 
“most attack were already possible...
but they are more powerful now”
http://w3af.org/understanding-html5-security
@carlobonamico#devoxxuk
Second problem
We are undergoing a wide architectural shift from
To
So many security assumptions do not hold true anymore!
ServerPOST params
HTML
Browser
Form-based
input
HTML rendering
HTML templating
Controllers,
Interaction
Logic
Business Logic
Server
POST JSON
JSON
Browser
HTML rendering
HTML templating
Business Logic
Interaction
Logic
REST
endpoints
@carlobonamico#devoxxuk
The good side
The typical modern HTML5 application architecture has a single/main
advantage:
it forces at the very least a basic degree of separation between UI
and business logic
– even more so with Angular, Ember, React
In our consulting/project/problem solving experience,
the single biggest cause of
– quality
– performance
– security
problems is....
@carlobonamico#devoxxuk
The good side
The typical modern HTML5 application architecture has a single/main
advantage:
it forces at the very least a basic degree of separation between UI
and business logic
– even more so with Angular, Ember, React
In our consulting/project/problem solving experience,
the single biggest cause of
– quality
– performance
– security
problems is.... the mixing & coupling of UI and business logic
@carlobonamico#devoxxuk
There's hope...
If we properly understand the
new architectural paradigm,
we can turn it into an
advantage
Follow the principles
of secure coding
– Do not trust inputs
– Minimize attack surface area
(and window of opportunity)
– Establish secure defaults
– Principle of Least privilege
– Principle of Defense in depth
– Fail securely
– Don’t trust services
– Separation of duties (vs
configuration)
– Avoid security by obscurity
– Keep security simple
– Fix security issues correctly
@carlobonamico#devoxxuk
Top Ten Web Application Risks
– A1-Injection
– A2-Broken Authentication and Session Management
– A3-Cross-Site Scripting (XSS)
– A4-Insecure Direct Object References
– A5-Security Misconfiguration
– A6-Sensitive Data Exposure
– A7-Missing Function Level Access Control
– A8-Cross-Site Request Forgery (CSRF)
– A9-Using Components with Known Vulnerabilities
– A10-Unvalidated Redirects and Forwards
What's different between Request/Response apps and HTML5/SPAs?
@carlobonamico#devoxxuk
What changes with HTML5/SPAs?
RED → more critical ORANGE → different solution GREEN → easier
– A1-Injection → same problem, same solution
– A2-Broken Authentication and Session Management
– A3-Cross-Site Scripting (XSS)
– A4-Insecure Direct Object References
– A5-Security Misconfiguration
– A6-Sensitive Data Exposure
– A7-Missing Function Level Access Control
– A8-Cross-Site Request Forgery (CSRF)
– A9-Using Components with Known Vulnerabilities
– A10-Unvalidated Redirects and Forwards
We will focus on those!
@carlobonamico#devoxxuk
A3-Cross-Site Scripting (XSS)
@carlobonamico#devoxxuk
A3 - XSS
Cross-Site-Scripting means that attacker can insert custom js code
which is then displayed in the user browser
– stored (input js in a field → DB → sent back to the page)
– reflected (input js in the url, send the url to a user, js executed)
– DOM-based (input triggers js logic that manipulates the DOM and
insert custom js)
Remember: any external input is UNTRUSTED!
– so we must avoid mixing user input with js code
@carlobonamico#devoxxuk
A3 – Preventing XSS
Looks easy: but HTML allows for multiple mixed execution contexts:
– JS within CSS within HTML within a frame of another HTML …
The proper solution is ESCAPING: encoding the data so that the
browser properly interprets it as plain text (and not js)
– https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Che
at_Sheet
In a well designed SPA,
– clear inputs paths

REST service responses, user inputs, url bar, ...
– HTML generation through the framework templating engine
– so it is easier to intercept and escape outputs
@carlobonamico#devoxxuk
A3 – Preventing XSS with Angular
Since 1.3, the HTML compiler will escape all {{}} & ng­bind by default
– https://www.ng-book.com/p/Security
– http://java.dzone.com/articles/angularjs-how-handle-xss
Be careful if you must include user-generated HTML (e.g. in rich text editors)
– take advantage of the services and directives
– ng­bind­html (from angular-sanitize)

print as is removing “script” tags (beware of img tags)

fully customizable with
–$sceProvider & $SanitizeProvider
– https://docs.angularjs.org/guide/security
Please note:
– escaping in the REST services is not always feasible/useful
– they can be consumed by mobile Apps and other clients
@carlobonamico#devoxxuk
More Angular-specific guidelines
Further suggesions:
– prefer model-based logic
– avoid mixing client side and server side templating
– clear template / data separation
– avoid dynamically generating templates from user input
– do not run input in $eval
@carlobonamico#devoxxuk
A3 – XSS - Tools
Static Code Analysis for DOM-based and reflected XSS
– Mozilla ScanJS

https://github.com/mozilla/scanjs
– JSPRime

https://github.com/dpnishant/jsprime
More references
– https://blog.nvisium.com/2014/06/javascript-security-tools.html
@carlobonamico#devoxxuk
Remember
Most vulnerabilities are not so serious by themselves
– but became terrible if mixed

think Pepsi + Mentos
XSS is an enabler for
– phishing
– browser-based MITM
– session / auth token stealing
– sensitive data extraction
– img courtesy of http://www.delawaretoday.com/
@carlobonamico#devoxxuk
A6-Sensitive Data Exposure
Do you protect your cookies?
@carlobonamico#devoxxuk
Securing cookies
If your cookie is stolen
– via Cross-Site-Scripting, interception, ...
attacker is granted access to the session
At the very least
– always use HTTPS / TLS
– set secure flag
– set HTTPOnly flag
Also, do not store sensitive data in clear in
localStorage / sessionStorage indexDB  
@carlobonamico#devoxxuk
A5-Security Misconfiguration
@carlobonamico#devoxxuk
A5 – Security misconfiguration
A single MITM (Man in the Middle) and your “done”
– as the attacker can put arbitrary code in your browser
– so,

https://www.eff.org/Https-everywhere
Be careful with CORS
– Avoid Allow­Origin “*” unless you have very strong authentication
and authorization
Remember to tell the browser to enable stronger protection
– typically through headers such as CSP
– https://www.owasp.org/index.php/List_of_useful_HTTP_headers
@carlobonamico#devoxxuk
Securing Headers
Node
– https://www.npmjs.com/package/helmet
Java (Spring Security)
– http://docs.spring.io/autorepo/docs/spring-security/current/reference/html/headers.
html
Test tools
– security headers online

https://securityheaders.com/
– OWASP ZAP

https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
@carlobonamico#devoxxuk
A2-Broken Authentication & Session Management
@carlobonamico#devoxxuk
What is Authentication
Verifying the user identity
– independently from his profile / authorizations
Several elements:
– where valid users are listed (Realm)

internal, file, DB, LDAP, Active Directory, SSO Server
– what info is used to establish user identity

one or more “factors”: username, password, OTP, certificate...
– how identity is checked the first time

login → credentials validation
– how identity is checked on subsequent requests

validation
@carlobonamico#devoxxuk
Traditional Request-Response Applications
e.g. JSP / ASP / PHP
– login page
– successful login creates a session
– protected pages accessed within the session
– data and access control filtered on the server side

often within views or controllers
Browser
Server
POST Login Data
GET secured page
SESSIONID = 5
SESSIONID = 5 auth
=
true?
crede
ntials
valid?
Realm
filtered
HTML
page
SID AUTH DATA
5 true carlo,admi
n
@carlobonamico#devoxxuk
Issues with Cookie + Session Authentication
Authentication requires
– checking credentials against a realm
– keeping auth in session state on the server
– sessionid sent in a cookie
Issues
– state replication in clustered servers vs sticky sessions

Single-Sign-On across servers?
– More complex scenarios are possible

e.g. SSO Server, like CAS
– typically cookie based →
all server must be in same domain
Remember:
Cookies are sent
with ANY request
to the same domain
(including images)
@carlobonamico#devoxxuk
Cookie-based authentication in Single Page
Applications
Can't SPA just do the same?
– login form POSTs to login service
– successful login creates a session and sets a cookie
– protected Pages & REST services accessed within the session

data and access control filtered … where ?
Browser
Server
POST Login Data
GET secured JSON
SESSIONID = 5
SID AUTH DATA
5 true carlo,admi
nSESSIONID = 5 auth
=
true?{
...
}
crede
ntials
valid?
Realm
@carlobonamico#devoxxuk
Authentication vs Session Management
Pros
– simple to implement
Cons
– not suited to stateless nature of REST services
Authentication vs Sessions
– They are two different things, although often used together
– REST services
tend to
be stateless
Unauthenticated Authenticated
Stateless Plain HTTP
e.g. Wikipedia
REST
e.g. Google APIs
With Session Session cookies
e.g. Amazon
JSP/ASP/PHP
e.g. Intranet Apps
@carlobonamico#devoxxuk
How to do stateless authentication?
@carlobonamico#devoxxuk
Token-based Authentication
Login establishes a valid token
– each request must be presented with the token
– the server can check token validity at each request
– https://auth0.com/blog/2014/01/07/angularjs-authentication-with-
cookies-vs-token/
Browser
Server
POST Login Data
GET secured JSON
TOKEN = 5
TOKEN = 5 token
valid?
crede
ntials
valid?
Realm
no session!
@carlobonamico#devoxxuk
Issues
Given a token
– how do you know which is the current user?
On the server
– how expensive it is to check the token at each request?
Can you share a token across services?
– can you validate it without connecting to a DB / SSO Server?
@carlobonamico#devoxxuk
How do you create & validate Tokens?
@carlobonamico#devoxxuk
Creating and Validating Tokens
Simplest way: checking them against a list of valid tokens
– in memory → similar to session-based auth

replication problems
– on a DB

easier clustering, must consider performance
– on an external server

SSO for free, must evaluate performance & complexity
@carlobonamico#devoxxuk
JWT - http://jwt.io
JWT = encoded & signed Json object containing
– Access token
– Claims (custom: session, domain, username...)
– Expiration
– and Digital Signature! → verifiable with just the public key
Returned by login REST service
Sent as header at each request
–Authentication: bearer eyJhbGciO                 
 .eyJzdWIiOWV9.eoaDV
Checked by REST backed at each request
– can also be used with websockets
{
“user”:”carlo”,
“domain”:”NIS”,
“expiry”: ..
}
@carlobonamico#devoxxuk
JWT in angular
Angular Library
– https://github.com/auth0/angular-jwt
Extensible hooks for
– storing and retrieving tokens on the client
Interceptors for
– retrieving tokens from server Response Headers
– optionally refresh tokens
– automatically sending tokens at each request
Robust and simple to user
bower install angular­jwt
@carlobonamico#devoxxuk
Token-based Auth in AngularJs
Ingredients
REST endpoints
– /auth/login

Input parameters: credentials

Response: token
– /auth/logout

Input parameters: token
$http or $resource based Client Service
AuthenticationService
– login() logout() methods wrapping the above
– plus isAuthenticated() and possibly currentUser()
@carlobonamico#devoxxuk
Token-based Auth in AngularJs
Ingredients
– Controller(s)
– LoginController

bound to Login form, calls service
– LogoutController
– AuthenticationController

IsAuthenticated, currentUser
Possibly, Directives
<authenticated­user> 
showWhenAuthenticated
<menu showWhenAuthenticated=”true”>
@carlobonamico#devoxxuk
Authentication Client
Perform the request – Form based POST
$http({
url: '/oauth2/token',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {
username: credentials.username,
password: credentials.password,
}
})
@carlobonamico#devoxxuk
Authentication Client
REST POST
$http({
url: '/rest/auth/token',
method: 'POST',
data: {
username: credentials.username,
password: credentials.password,
}
})
@carlobonamico#devoxxuk
Saving the token
In both cases, register a then() on the promise
$http(...).then(function(response) {
currentToken.jwt = response.data.access_token;
}
Store it locally
If you need, parse it
tokenPayload = jwtHelper.decodeToken(currentToken.jwt);
date = jwtHelper.getTokenExpirationDate(currentToken.jwt);
bool = jwtHelper.isTokenExpired(currentToken.jwt);
@carlobonamico#devoxxuk
Integrating with angular-jwt
Specify Token retrieval function
angular.module('myApp')
.config(function Config($httpProvider, jwtInterceptorProvider) {
jwtInterceptorProvider.tokenGetter = ['currentToken',
function(currentToken) {
return currentToken.jwt;
//or return localStorage.getItem('id_token');
}];
Register interceptor
$httpProvider.interceptors.push('jwtInterceptor');
});
@carlobonamico#devoxxuk
Back-end
Login endpoint
– validates credentials
– generates JWT
REST Service endpoints (or better interceptor)
– extract Token from Authentication: header
– validate it
– proceed with request processing

or return error 401
Full example
– http://thejackalofjavascript.com/architecting-a-restful-node-js-app/
@carlobonamico#devoxxuk
JWT in...
Plain Node: Auth0 library
– https://github.com/auth0/node-jsonwebtoken
Express: Express JWT
– https://github.com/auth0/express-jwt
Passport - Modular Auth Framework for node.js
– http://passportjs.org/
.NET - OWIN.Identity
– http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-
jwt-owin-authorization-server/
Java - Spring Security
– https://spring.io/guides/tutorials/spring-security-and-angular-
js/Integrating OAUTH with JWT
@carlobonamico#devoxxuk
Were can we store / send the token?
in a cookie?
in a header?
@carlobonamico#devoxxuk
Token Storage vs Session Duration
In memory or sessionStorage
– works only on current tab
– automatically closed
In localStorage
– persistent
– work across multiple tabs
– requires explicit expiration
https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-
html5-web-storage/
@carlobonamico#devoxxuk
Sending Tokens - Cookies vs Headers
Cookies
Pros
– sent automatically
– no code required on the client
Cons
– sent automatically
– even when do not want

e.g. <IMG src= in email
– less control on validity
– stored on client disk
Headers
Pros
– sent only explicitely
– not stored on disk
– unless you want to
– more control
– also prevents CSRF
Cons
– require code on the client side
– but this is normal in SPAs
https://auth0.com/blog/2014/01/27/
ten-things-you-should-know-about-
tokens-and-cookies/
@carlobonamico#devoxxuk
What else would we need?
what happens when the user is not logged in?
how to improve usability?
@carlobonamico#devoxxuk
Routing support for Authentication &
Authorization
Need to configure Routing for
– redirect to login if not authenticated
– redirect to login if token expired
– optionally, redirect back to original URL
– redirect to error page if route not authorized in the current profile
Difficult to do in the default ngRoute
– Possible in ui-router
Way easier in angular-new-router
– https://medium.com/angularjs-meetup-south-london/angular-ng-
conf-2015-media-25dbe6250154
@carlobonamico#devoxxuk
A8-Cross-Site Request Forgery (CSRF)
@carlobonamico#devoxxuk
CSRF
See section “Security Considerations” on
– https://docs.angularjs.org/api/ng/service/$http
Angular automatically manages CSRF-prevention tokens if you use cookies
The server needs to set a token
– JavaScript readable session cookie called XSRF-TOKEN on the first HTTP GET request
On subsequent XHR requests
– the server can verify that the cookie matches X-XSRF-TOKEN HTTP header
– the token must be unique for each user and must be verifiable by the server

e.g. a digest of your site's authentication cookie with a salt for added security
Also,
– Angular automatically supports JSONP-prevention characters

http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.as
px/
@carlobonamico#devoxxuk
A7-Missing Function Level Access Control
@carlobonamico#devoxxuk
Typical Server side application
Authorization is verified
– in controllers
if (user.hasRole(“admin”) == true)
– through filters / interceptors
– in views
<hasRole role=”admin”> or <if (...)>
confidential info
</hasRole>
Client Browser only receives content it has rights to
– (roughly) works even if security checks are “spaghetti code” in the
JSP/ASP/PHP templates
@carlobonamico#devoxxuk
And in a SPA?
Would this be secure?
In users-view.html
<button ng­if=”authCtrl.isAdmin” 
        ng­click=”userCtrl.deleteUser()”>
or this?
<section ng­if=”authCtrl.isAdmin” >
{{userCtrl.user.confidentialData}}
</section>
@carlobonamico#devoxxuk
No!
Just press F12
and modify the HTML / JS
or even the DOM in the developer tools
@carlobonamico#devoxxuk
Security is up to the server
Even in SPAs, Authorization is still up to the server:
Security controls
– checking authentication state
– checking profile and inferring permissions
– enabling privileged actions
– filtering confidential data
MUST be performed on the server
– in the REST / websocket endpoints
– locally in each service, or via filters/interceptors
Also, the same rule applies to input validation
@carlobonamico#devoxxuk
Usability is up to the client
But letting the user click on the button, invoking the service, and
only then displaying an error is not user friendly
UX is up to the client
– Front-End should have enough info to disable/hide the button

if the user is not authorized to click it

retrieve the permissions list from a REST service at logon
E.g. Permission check directives for Angular
<button ng­click=”postCtrl.delete()” 
has­permission=”deletePost”>
permissions for Role-Based Access Control
@carlobonamico#devoxxuk
Checking the user profile
So, in each server endpoint, you should check
– valid authentication
– valid authorization profile which includes privileges for the
currently requested action / data
Example Blog application
if (subject.hasRole(“admin”))
//enable delete post
if (subject.hasRole(“editor”))
//enable modification of post
else
//only read data
What are
the problems
with this code?
@carlobonamico#devoxxuk
What if the rules change?
What if an auditor asks about
what an “editor” can do?
Real-world cases tend to be more complex!
@carlobonamico#devoxxuk
Role Based Access Control
Separating Role definition from Permission check
– In each service / action, code checks that the user has the relevant
permission
if (subject.hasPermission(“deletePost”))
– Role Definition lists all the permissions

e.g.
–Admin   detelePost, updatePost→
–anonymous   readPost→
Authorization system maps user/groups to list of roles
– and computes the “merged” set of permissions active for the valid user

user is both Admin & Editor

Permissions are
–changeSettings, deleteUser, addUser, deletePost, 
modifyPost 
@carlobonamico#devoxxuk
Hierarchical permission system
2-level: User → Role → Permissions
3-level: User → Groups → Roles → Permissions
Wildcard Permissions
– blog:deletePost
– blog:readPost
– blog:* means both

blog:readPost:12 → entity level permission

blog:readPost:* on all entities
see Apache Shiro
@carlobonamico#devoxxuk
Advantages
Permission check is
– focused, readable
– easy to implement
– easy to test
– rarely changes
Role definition is
– centralized
– easy to review
– easy to change
– as it tends to change often
Secure Design Principle
all parts of the system
need to perform security
checks
but
security check
implementation
should be centralized and
not “spread” in the system
@carlobonamico#devoxxuk
RBAC in a Single Page Application
Server-side Ingredients:
– Profile definition mapping Roles to Permissions

static file

db table

possibly cached

Identity server (e.g. OpenAM)
– API for checking permissions
Normally, some of this information is cached to ensure minimal
performance penalty
@carlobonamico#devoxxuk
Usable Secure UI in AngularJS
Ingredients:
– /authorization/profile/current REST endpoint

returns a Json

current user roles

merged list of all active permissions
On the Client
– Client Service wrapping the above
– Authorization/ProfileService storing the permission list

hasPermission(p) method
Call the service from
– Controller methods
– Routing callbacks
@carlobonamico#devoxxuk
Unvalidated Redirects
@carlobonamico#devoxxuk
A9-Using Components with Known Vulnerabilities
@carlobonamico#devoxxuk
Component Security
The code we write
The code which actually runs in our application
– libraries and components
@carlobonamico#devoxxuk
Checking dependecies for vulns
On the client side
– http://retirejs.github.io/retire.js/
npm install ­g retire ; retire –path src
– also available as ZAP & mvn plugin
mvn com.h3xstream.retirejs:retirejs­maven­
plugin:scan
On the server side
– OWASP Dependency Check

https://github.com/jeremylong/DependencyCheck
dependency­check.sh ­­app Testing ­­out . ­­scan 
[path to jar files to be scanned]
mvn org.owasp:dependency­check­maven
@YourTwitterHandle#DVXFR14{session hashtag} @carlobonamico#devoxxuk
A
f
nal
w
ord
...
But isn't all that unnecessary complexity
slowing down development of my critical project?
@carlobonamico#devoxxuk
A final word
People tend to view Security as “overhead”, not adding value to the project
The reality:
– if you know what to pay attention to, minimal additional costs
– also, in most cases, adding security just means following good design principles
if you separate well concerns, adding security is easy
– favor clarity of intent and code readability
– favor composition over inheritance
– test, test, test!

incorporate security checks in your tests
This lets software adapt more easily to both requirements & security changes
– easier to evolve incrementally & validating each step → see Continuous
Delivery
@carlobonamico#devoxxuk
References
@carlobonamico#devoxxuk
References
Owasp Secure Coding Principles
– https://www.owasp.org/index.php/Secure_Coding_Principles
OWASP Testing Guide
– https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_
of_Contents
SOLID Design Principles
– http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
@carlobonamico#devoxxuk
HTML5 Security
Attack Vectors & Vulnerabilities
– https://media.blackhat.com/bh-eu-12/shah/bh-eu-12-Shah_HTML5_
Top_10-WP.pdf
OWASP Guidelines
– https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet
JS Frameworks Security
– http://www.slideshare.net/x00mario/jsmvcomfg-to-sternly-look-at-
javascript-mvc-and-templating-frameworks
@carlobonamico#devoxxuk
Thank You for your attention
Interested?
– attend our Web Application Security trainings
– engage us for Design/Code Reviews, Vulnerability Assessments &
team mentoring
Read more on
– http://www.nispro.it
– http://www.slideshare.net/carlo.bonamico
Follow us on twitter
– @nis_srl @carlobonamico

updates on Security, AngularJS, Continuous Delivery
Contact me
– carlo.bonamico@gmail.com / carlo.bonamico@nispro.it
@YourTwitterHandle#DVXFR14{session hashtag} @carlobonamico#devoxxuk
Q
&
A

More Related Content

What's hot

Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET WebskillsCaleb Jenkins
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Jonas Bandi
 
Web application framework
Web application frameworkWeb application framework
Web application frameworkPankaj Chand
 
The Future Of Web Frameworks
The Future Of Web FrameworksThe Future Of Web Frameworks
The Future Of Web FrameworksMatt Raible
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Jonas Bandi
 
Mobile applications development - why should you start learning it right now?
Mobile applications development - why should you start learning it right now?Mobile applications development - why should you start learning it right now?
Mobile applications development - why should you start learning it right now?Natalija Rodionova
 
Coding for Desktop and Mobile with HTML5 and Java EE 7
Coding for Desktop and Mobile with HTML5 and Java EE 7Coding for Desktop and Mobile with HTML5 and Java EE 7
Coding for Desktop and Mobile with HTML5 and Java EE 7Petr Jiricka
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students shafiq sangi
 
MVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebdayMVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebdayRicardo Fiel
 
[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scaleOWASP
 
Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development PresentationTurnToTech
 
Gsm library for proteus the engineering projects
Gsm library for proteus   the engineering projectsGsm library for proteus   the engineering projects
Gsm library for proteus the engineering projectsZerihunDemere
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Beat Signer
 
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. MolinaACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. MolinaPedro J. Molina
 
Architecting your app in ext js 4, part 1 learn sencha
Architecting your app in ext js 4, part 1   learn   senchaArchitecting your app in ext js 4, part 1   learn   sencha
Architecting your app in ext js 4, part 1 learn senchaRahul Kumar
 
Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010Christian Heilmann
 
Developing Enterprise-Grade Mobile Applications
Developing Enterprise-Grade Mobile ApplicationsDeveloping Enterprise-Grade Mobile Applications
Developing Enterprise-Grade Mobile ApplicationsSimon Guest
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Edureka!
 

What's hot (20)

Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET Webskills
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!
 
Web application framework
Web application frameworkWeb application framework
Web application framework
 
The Future Of Web Frameworks
The Future Of Web FrameworksThe Future Of Web Frameworks
The Future Of Web Frameworks
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!
 
Mobile applications development - why should you start learning it right now?
Mobile applications development - why should you start learning it right now?Mobile applications development - why should you start learning it right now?
Mobile applications development - why should you start learning it right now?
 
Coding for Desktop and Mobile with HTML5 and Java EE 7
Coding for Desktop and Mobile with HTML5 and Java EE 7Coding for Desktop and Mobile with HTML5 and Java EE 7
Coding for Desktop and Mobile with HTML5 and Java EE 7
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
 
MVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebdayMVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebday
 
[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale
 
Hai_Bui
Hai_BuiHai_Bui
Hai_Bui
 
Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development Presentation
 
Gsm library for proteus the engineering projects
Gsm library for proteus   the engineering projectsGsm library for proteus   the engineering projects
Gsm library for proteus the engineering projects
 
Top 10 web application development frameworks 2016
Top 10 web application development frameworks 2016Top 10 web application development frameworks 2016
Top 10 web application development frameworks 2016
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
 
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. MolinaACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
 
Architecting your app in ext js 4, part 1 learn sencha
Architecting your app in ext js 4, part 1   learn   senchaArchitecting your app in ext js 4, part 1   learn   sencha
Architecting your app in ext js 4, part 1 learn sencha
 
Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010Understanding progressive enhancement - yuiconf2010
Understanding progressive enhancement - yuiconf2010
 
Developing Enterprise-Grade Mobile Applications
Developing Enterprise-Grade Mobile ApplicationsDeveloping Enterprise-Grade Mobile Applications
Developing Enterprise-Grade Mobile Applications
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
 

Similar to Web Application Security Reloaded for the HTML5 era

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
 
Die Qual der Wahl bei den Single Page Application Frameworks
Die Qual der Wahl bei den Single Page Application FrameworksDie Qual der Wahl bei den Single Page Application Frameworks
Die Qual der Wahl bei den Single Page Application FrameworksJonas Bandi
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | IntroductionJohnTaieb
 
Chandra Sekhar Cheekuru NET UI
Chandra Sekhar Cheekuru  NET UIChandra Sekhar Cheekuru  NET UI
Chandra Sekhar Cheekuru NET UIChandra Sekhar
 
Protection and Verification of Security Design Flaws
Protection and Verification of Security Design FlawsProtection and Verification of Security Design Flaws
Protection and Verification of Security Design FlawsHdiv Security
 
Angular js mobile jsday 2014 - Verona 14 may
Angular js mobile   jsday 2014 - Verona 14 mayAngular js mobile   jsday 2014 - Verona 14 may
Angular js mobile jsday 2014 - Verona 14 mayLuciano Amodio
 
How to migrate large project from Angular to React
How to migrate large project from Angular to ReactHow to migrate large project from Angular to React
How to migrate large project from Angular to ReactTomasz Bak
 
GeeCON Microservices 2015 scaling micro services at gilt
GeeCON Microservices 2015   scaling micro services at giltGeeCON Microservices 2015   scaling micro services at gilt
GeeCON Microservices 2015 scaling micro services at giltAdrian Trenaman
 
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe-Lexware GmbH & Co KG
 
Application security for the modern web - ISSA South Texas Houston DevOps
Application security for the modern web - ISSA South Texas Houston DevOpsApplication security for the modern web - ISSA South Texas Houston DevOps
Application security for the modern web - ISSA South Texas Houston DevOpsPhillip Maddux
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...Mark Leusink
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...Mark Roden
 
Enjoying the full stack - Frontend 2010
Enjoying the full stack - Frontend 2010Enjoying the full stack - Frontend 2010
Enjoying the full stack - Frontend 2010Christian Heilmann
 
ASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a coupleASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a coupleAlexandre Marreiros
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalAlessandro Pilotti
 
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignalITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignalITCamp
 
Prakhar Sood-Resume-CV
Prakhar Sood-Resume-CVPrakhar Sood-Resume-CV
Prakhar Sood-Resume-CVPrakhar Sood
 
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysDaniel Bryant
 

Similar to Web Application Security Reloaded for the HTML5 era (20)

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...
 
Die Qual der Wahl bei den Single Page Application Frameworks
Die Qual der Wahl bei den Single Page Application FrameworksDie Qual der Wahl bei den Single Page Application Frameworks
Die Qual der Wahl bei den Single Page Application Frameworks
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Chandra Sekhar Cheekuru NET UI
Chandra Sekhar Cheekuru  NET UIChandra Sekhar Cheekuru  NET UI
Chandra Sekhar Cheekuru NET UI
 
Protection and Verification of Security Design Flaws
Protection and Verification of Security Design FlawsProtection and Verification of Security Design Flaws
Protection and Verification of Security Design Flaws
 
Angular js mobile jsday 2014 - Verona 14 may
Angular js mobile   jsday 2014 - Verona 14 mayAngular js mobile   jsday 2014 - Verona 14 may
Angular js mobile jsday 2014 - Verona 14 may
 
How to migrate large project from Angular to React
How to migrate large project from Angular to ReactHow to migrate large project from Angular to React
How to migrate large project from Angular to React
 
GeeCON Microservices 2015 scaling micro services at gilt
GeeCON Microservices 2015   scaling micro services at giltGeeCON Microservices 2015   scaling micro services at gilt
GeeCON Microservices 2015 scaling micro services at gilt
 
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
 
Application security for the modern web - ISSA South Texas Houston DevOps
Application security for the modern web - ISSA South Texas Houston DevOpsApplication security for the modern web - ISSA South Texas Houston DevOps
Application security for the modern web - ISSA South Texas Houston DevOps
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
Resume
ResumeResume
Resume
 
Enjoying the full stack - Frontend 2010
Enjoying the full stack - Frontend 2010Enjoying the full stack - Frontend 2010
Enjoying the full stack - Frontend 2010
 
ASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a coupleASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a couple
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
 
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignalITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
ITCamp 2012 - Alessandro Pilotti - Web API, web sockets and RSignal
 
Prakhar Sood-Resume-CV
Prakhar Sood-Resume-CVPrakhar Sood-Resume-CV
Prakhar Sood-Resume-CV
 
Ramji
RamjiRamji
Ramji
 
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
 

More from Carlo Bonamico

Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component LibraryCarlo Bonamico
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCCarlo Bonamico
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014Carlo Bonamico
 
Infrastructure as Data with Ansible for easier Continuous Delivery
Infrastructure as Data with Ansible for easier Continuous DeliveryInfrastructure as Data with Ansible for easier Continuous Delivery
Infrastructure as Data with Ansible for easier Continuous DeliveryCarlo Bonamico
 
Infrastructure as Data with Ansible
Infrastructure as Data with AnsibleInfrastructure as Data with Ansible
Infrastructure as Data with AnsibleCarlo Bonamico
 
Maven 2 in the real world
Maven 2 in the real worldMaven 2 in the real world
Maven 2 in the real worldCarlo Bonamico
 
Nasa World Wind For Java (by Fabrizio Giudici)
Nasa World Wind For Java (by Fabrizio Giudici)Nasa World Wind For Java (by Fabrizio Giudici)
Nasa World Wind For Java (by Fabrizio Giudici)Carlo Bonamico
 
Continuous Integration With Hudson (and Jenkins)
Continuous Integration With Hudson (and Jenkins)Continuous Integration With Hudson (and Jenkins)
Continuous Integration With Hudson (and Jenkins)Carlo Bonamico
 

More from Carlo Bonamico (9)

Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component Library
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVC
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014
 
Infrastructure as Data with Ansible for easier Continuous Delivery
Infrastructure as Data with Ansible for easier Continuous DeliveryInfrastructure as Data with Ansible for easier Continuous Delivery
Infrastructure as Data with Ansible for easier Continuous Delivery
 
Infrastructure as Data with Ansible
Infrastructure as Data with AnsibleInfrastructure as Data with Ansible
Infrastructure as Data with Ansible
 
Maven 2 in the real world
Maven 2 in the real worldMaven 2 in the real world
Maven 2 in the real world
 
Nasa World Wind For Java (by Fabrizio Giudici)
Nasa World Wind For Java (by Fabrizio Giudici)Nasa World Wind For Java (by Fabrizio Giudici)
Nasa World Wind For Java (by Fabrizio Giudici)
 
Continuous Integration With Hudson (and Jenkins)
Continuous Integration With Hudson (and Jenkins)Continuous Integration With Hudson (and Jenkins)
Continuous Integration With Hudson (and Jenkins)
 
Build Automation Tips
Build Automation TipsBuild Automation Tips
Build Automation Tips
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 

Recently uploaded (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Web Application Security Reloaded for the HTML5 era

  • 1. @carlobonamico#devoxxuk Web Application Security Reloaded for the HTML5 era Carlo Bonamico @carlobonamico carlo.bonamico@nispro.it http://www.nispro.it Designing and implementing secure Single Page Applications https://wall-simple.sli.do/#/event/cmnxxfl0/section/18289/questions
  • 2. @carlobonamico#devoxxuk About me Speaker Bio – passionate software developer since the C128 era – PhD and research at the University of Genova / CNIT National TLC Research Consortium – exciting time at startup Eptamedia – now a Solution Architect and Senior Trainer at NIS s.r.l.  between Italy and new London office Current projects & interests – training/mentoring teams on AngularJS, Web Security, Continuous Integration & Delivery – creating component-based Angular applications – security reviews and assessments
  • 3. @carlobonamico#devoxxuk Abstract Ten years after the first OWASP Top Ten list of Web Application Security risks has been published, the basics of protecting a typical JEE/Rails/PHP/.NET, webapp are becoming mainstream knowledge (although never enough, as the endless series of high profile vulerabilities demonstates). But the industry-wide move towards HTML5 and Single Page Applications, motivated by the opportunity for more sophisticated interaction and UX, is again upsetting the balance between Hackers and Developers. A wave of new-generation front-end technologies such as Web Components, AngularJS and Ember is Developers are attracting Developers with their combination of productivity and innovative UX, but at the same time opens the door to new vulnerabilities and security challenges. This talk will summarize the main principles of Secure Coding, and will discuss their application to HTML5 applications that interact with REST or WebSocket backends to prevent major risks (including OWASP Top Ten). A concrete example will demonstrate the use of tools and libraries, from RBAC to JWT, from Spring Security to AngularJS modules for implementing secure HTML5/JS apps.
  • 4. @carlobonamico#devoxxuk Evolution of Application Security When I taught my first Web Application Security training – most participants had never heard of SQL Injection and XSS Thanks to many industry and community players (especially OWASP), – not to mention many high-profile incidents, things have started to change... Application Security Ensuring Application guarantees •Confidentiality •Integrity •Availability •Accountability of the Information it processes
  • 5. @carlobonamico#devoxxuk Are we doing better? It's 2015... we were promised flying cars... and what we got is... See also – http://www.cvedetails.com/vulnerabilities-by-types.php – https://www.whitehatsec.com/resource/stats.html
  • 6. @carlobonamico#devoxxuk Enter HTML5 After years of playing catch-up with Desktop, the Web is now often the default development target – powerful APIs – interactivity – always up-to-date & cross-platform the mobile web just adds more push to that => the rise of the Single Page Application Somewhat ill-defined term, but you know what I mean – HTML templates, statically served – client retrieves data from REST services / websockets – views dynamically rendered on the client side
  • 7. @carlobonamico#devoxxuk HTML5 apps Definitely more powerful that traditional request-response webapps also more secure?
  • 8. @carlobonamico#devoxxuk First problem Spiderman's Uncle Ben version: With great power comes great responsibility... The Web Application Security version: With great power come more holes and greater risks! – increased Surface of Attack  Websockets, storage, apis... – https://html5sec.org/ – http://html5security.org/ – and once you penetrate the browser, you can do basically everything  and I mean it: calling APIs, install keyloggers, redirect user behaviour, capture private data –http://xenotix.in/  “most attack were already possible... but they are more powerful now” http://w3af.org/understanding-html5-security
  • 9. @carlobonamico#devoxxuk Second problem We are undergoing a wide architectural shift from To So many security assumptions do not hold true anymore! ServerPOST params HTML Browser Form-based input HTML rendering HTML templating Controllers, Interaction Logic Business Logic Server POST JSON JSON Browser HTML rendering HTML templating Business Logic Interaction Logic REST endpoints
  • 10. @carlobonamico#devoxxuk The good side The typical modern HTML5 application architecture has a single/main advantage: it forces at the very least a basic degree of separation between UI and business logic – even more so with Angular, Ember, React In our consulting/project/problem solving experience, the single biggest cause of – quality – performance – security problems is....
  • 11. @carlobonamico#devoxxuk The good side The typical modern HTML5 application architecture has a single/main advantage: it forces at the very least a basic degree of separation between UI and business logic – even more so with Angular, Ember, React In our consulting/project/problem solving experience, the single biggest cause of – quality – performance – security problems is.... the mixing & coupling of UI and business logic
  • 12. @carlobonamico#devoxxuk There's hope... If we properly understand the new architectural paradigm, we can turn it into an advantage Follow the principles of secure coding – Do not trust inputs – Minimize attack surface area (and window of opportunity) – Establish secure defaults – Principle of Least privilege – Principle of Defense in depth – Fail securely – Don’t trust services – Separation of duties (vs configuration) – Avoid security by obscurity – Keep security simple – Fix security issues correctly
  • 13. @carlobonamico#devoxxuk Top Ten Web Application Risks – A1-Injection – A2-Broken Authentication and Session Management – A3-Cross-Site Scripting (XSS) – A4-Insecure Direct Object References – A5-Security Misconfiguration – A6-Sensitive Data Exposure – A7-Missing Function Level Access Control – A8-Cross-Site Request Forgery (CSRF) – A9-Using Components with Known Vulnerabilities – A10-Unvalidated Redirects and Forwards What's different between Request/Response apps and HTML5/SPAs?
  • 14. @carlobonamico#devoxxuk What changes with HTML5/SPAs? RED → more critical ORANGE → different solution GREEN → easier – A1-Injection → same problem, same solution – A2-Broken Authentication and Session Management – A3-Cross-Site Scripting (XSS) – A4-Insecure Direct Object References – A5-Security Misconfiguration – A6-Sensitive Data Exposure – A7-Missing Function Level Access Control – A8-Cross-Site Request Forgery (CSRF) – A9-Using Components with Known Vulnerabilities – A10-Unvalidated Redirects and Forwards We will focus on those!
  • 16. @carlobonamico#devoxxuk A3 - XSS Cross-Site-Scripting means that attacker can insert custom js code which is then displayed in the user browser – stored (input js in a field → DB → sent back to the page) – reflected (input js in the url, send the url to a user, js executed) – DOM-based (input triggers js logic that manipulates the DOM and insert custom js) Remember: any external input is UNTRUSTED! – so we must avoid mixing user input with js code
  • 17. @carlobonamico#devoxxuk A3 – Preventing XSS Looks easy: but HTML allows for multiple mixed execution contexts: – JS within CSS within HTML within a frame of another HTML … The proper solution is ESCAPING: encoding the data so that the browser properly interprets it as plain text (and not js) – https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Che at_Sheet In a well designed SPA, – clear inputs paths  REST service responses, user inputs, url bar, ... – HTML generation through the framework templating engine – so it is easier to intercept and escape outputs
  • 18. @carlobonamico#devoxxuk A3 – Preventing XSS with Angular Since 1.3, the HTML compiler will escape all {{}} & ng­bind by default – https://www.ng-book.com/p/Security – http://java.dzone.com/articles/angularjs-how-handle-xss Be careful if you must include user-generated HTML (e.g. in rich text editors) – take advantage of the services and directives – ng­bind­html (from angular-sanitize)  print as is removing “script” tags (beware of img tags)  fully customizable with –$sceProvider & $SanitizeProvider – https://docs.angularjs.org/guide/security Please note: – escaping in the REST services is not always feasible/useful – they can be consumed by mobile Apps and other clients
  • 19. @carlobonamico#devoxxuk More Angular-specific guidelines Further suggesions: – prefer model-based logic – avoid mixing client side and server side templating – clear template / data separation – avoid dynamically generating templates from user input – do not run input in $eval
  • 20. @carlobonamico#devoxxuk A3 – XSS - Tools Static Code Analysis for DOM-based and reflected XSS – Mozilla ScanJS  https://github.com/mozilla/scanjs – JSPRime  https://github.com/dpnishant/jsprime More references – https://blog.nvisium.com/2014/06/javascript-security-tools.html
  • 21. @carlobonamico#devoxxuk Remember Most vulnerabilities are not so serious by themselves – but became terrible if mixed  think Pepsi + Mentos XSS is an enabler for – phishing – browser-based MITM – session / auth token stealing – sensitive data extraction – img courtesy of http://www.delawaretoday.com/
  • 23. @carlobonamico#devoxxuk Securing cookies If your cookie is stolen – via Cross-Site-Scripting, interception, ... attacker is granted access to the session At the very least – always use HTTPS / TLS – set secure flag – set HTTPOnly flag Also, do not store sensitive data in clear in localStorage / sessionStorage indexDB  
  • 25. @carlobonamico#devoxxuk A5 – Security misconfiguration A single MITM (Man in the Middle) and your “done” – as the attacker can put arbitrary code in your browser – so,  https://www.eff.org/Https-everywhere Be careful with CORS – Avoid Allow­Origin “*” unless you have very strong authentication and authorization Remember to tell the browser to enable stronger protection – typically through headers such as CSP – https://www.owasp.org/index.php/List_of_useful_HTTP_headers
  • 26. @carlobonamico#devoxxuk Securing Headers Node – https://www.npmjs.com/package/helmet Java (Spring Security) – http://docs.spring.io/autorepo/docs/spring-security/current/reference/html/headers. html Test tools – security headers online  https://securityheaders.com/ – OWASP ZAP  https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
  • 28. @carlobonamico#devoxxuk What is Authentication Verifying the user identity – independently from his profile / authorizations Several elements: – where valid users are listed (Realm)  internal, file, DB, LDAP, Active Directory, SSO Server – what info is used to establish user identity  one or more “factors”: username, password, OTP, certificate... – how identity is checked the first time  login → credentials validation – how identity is checked on subsequent requests  validation
  • 29. @carlobonamico#devoxxuk Traditional Request-Response Applications e.g. JSP / ASP / PHP – login page – successful login creates a session – protected pages accessed within the session – data and access control filtered on the server side  often within views or controllers Browser Server POST Login Data GET secured page SESSIONID = 5 SESSIONID = 5 auth = true? crede ntials valid? Realm filtered HTML page SID AUTH DATA 5 true carlo,admi n
  • 30. @carlobonamico#devoxxuk Issues with Cookie + Session Authentication Authentication requires – checking credentials against a realm – keeping auth in session state on the server – sessionid sent in a cookie Issues – state replication in clustered servers vs sticky sessions  Single-Sign-On across servers? – More complex scenarios are possible  e.g. SSO Server, like CAS – typically cookie based → all server must be in same domain Remember: Cookies are sent with ANY request to the same domain (including images)
  • 31. @carlobonamico#devoxxuk Cookie-based authentication in Single Page Applications Can't SPA just do the same? – login form POSTs to login service – successful login creates a session and sets a cookie – protected Pages & REST services accessed within the session  data and access control filtered … where ? Browser Server POST Login Data GET secured JSON SESSIONID = 5 SID AUTH DATA 5 true carlo,admi nSESSIONID = 5 auth = true?{ ... } crede ntials valid? Realm
  • 32. @carlobonamico#devoxxuk Authentication vs Session Management Pros – simple to implement Cons – not suited to stateless nature of REST services Authentication vs Sessions – They are two different things, although often used together – REST services tend to be stateless Unauthenticated Authenticated Stateless Plain HTTP e.g. Wikipedia REST e.g. Google APIs With Session Session cookies e.g. Amazon JSP/ASP/PHP e.g. Intranet Apps
  • 33. @carlobonamico#devoxxuk How to do stateless authentication?
  • 34. @carlobonamico#devoxxuk Token-based Authentication Login establishes a valid token – each request must be presented with the token – the server can check token validity at each request – https://auth0.com/blog/2014/01/07/angularjs-authentication-with- cookies-vs-token/ Browser Server POST Login Data GET secured JSON TOKEN = 5 TOKEN = 5 token valid? crede ntials valid? Realm no session!
  • 35. @carlobonamico#devoxxuk Issues Given a token – how do you know which is the current user? On the server – how expensive it is to check the token at each request? Can you share a token across services? – can you validate it without connecting to a DB / SSO Server?
  • 36. @carlobonamico#devoxxuk How do you create & validate Tokens?
  • 37. @carlobonamico#devoxxuk Creating and Validating Tokens Simplest way: checking them against a list of valid tokens – in memory → similar to session-based auth  replication problems – on a DB  easier clustering, must consider performance – on an external server  SSO for free, must evaluate performance & complexity
  • 38. @carlobonamico#devoxxuk JWT - http://jwt.io JWT = encoded & signed Json object containing – Access token – Claims (custom: session, domain, username...) – Expiration – and Digital Signature! → verifiable with just the public key Returned by login REST service Sent as header at each request –Authentication: bearer eyJhbGciO                   .eyJzdWIiOWV9.eoaDV Checked by REST backed at each request – can also be used with websockets { “user”:”carlo”, “domain”:”NIS”, “expiry”: .. }
  • 39. @carlobonamico#devoxxuk JWT in angular Angular Library – https://github.com/auth0/angular-jwt Extensible hooks for – storing and retrieving tokens on the client Interceptors for – retrieving tokens from server Response Headers – optionally refresh tokens – automatically sending tokens at each request Robust and simple to user bower install angular­jwt
  • 40. @carlobonamico#devoxxuk Token-based Auth in AngularJs Ingredients REST endpoints – /auth/login  Input parameters: credentials  Response: token – /auth/logout  Input parameters: token $http or $resource based Client Service AuthenticationService – login() logout() methods wrapping the above – plus isAuthenticated() and possibly currentUser()
  • 41. @carlobonamico#devoxxuk Token-based Auth in AngularJs Ingredients – Controller(s) – LoginController  bound to Login form, calls service – LogoutController – AuthenticationController  IsAuthenticated, currentUser Possibly, Directives <authenticated­user>  showWhenAuthenticated <menu showWhenAuthenticated=”true”>
  • 42. @carlobonamico#devoxxuk Authentication Client Perform the request – Form based POST $http({ url: '/oauth2/token', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, transformRequest: function (obj) { var str = []; for (var p in obj) str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); return str.join("&"); }, data: { username: credentials.username, password: credentials.password, } })
  • 43. @carlobonamico#devoxxuk Authentication Client REST POST $http({ url: '/rest/auth/token', method: 'POST', data: { username: credentials.username, password: credentials.password, } })
  • 44. @carlobonamico#devoxxuk Saving the token In both cases, register a then() on the promise $http(...).then(function(response) { currentToken.jwt = response.data.access_token; } Store it locally If you need, parse it tokenPayload = jwtHelper.decodeToken(currentToken.jwt); date = jwtHelper.getTokenExpirationDate(currentToken.jwt); bool = jwtHelper.isTokenExpired(currentToken.jwt);
  • 45. @carlobonamico#devoxxuk Integrating with angular-jwt Specify Token retrieval function angular.module('myApp') .config(function Config($httpProvider, jwtInterceptorProvider) { jwtInterceptorProvider.tokenGetter = ['currentToken', function(currentToken) { return currentToken.jwt; //or return localStorage.getItem('id_token'); }]; Register interceptor $httpProvider.interceptors.push('jwtInterceptor'); });
  • 46. @carlobonamico#devoxxuk Back-end Login endpoint – validates credentials – generates JWT REST Service endpoints (or better interceptor) – extract Token from Authentication: header – validate it – proceed with request processing  or return error 401 Full example – http://thejackalofjavascript.com/architecting-a-restful-node-js-app/
  • 47. @carlobonamico#devoxxuk JWT in... Plain Node: Auth0 library – https://github.com/auth0/node-jsonwebtoken Express: Express JWT – https://github.com/auth0/express-jwt Passport - Modular Auth Framework for node.js – http://passportjs.org/ .NET - OWIN.Identity – http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2- jwt-owin-authorization-server/ Java - Spring Security – https://spring.io/guides/tutorials/spring-security-and-angular- js/Integrating OAUTH with JWT
  • 48. @carlobonamico#devoxxuk Were can we store / send the token? in a cookie? in a header?
  • 49. @carlobonamico#devoxxuk Token Storage vs Session Duration In memory or sessionStorage – works only on current tab – automatically closed In localStorage – persistent – work across multiple tabs – requires explicit expiration https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs- html5-web-storage/
  • 50. @carlobonamico#devoxxuk Sending Tokens - Cookies vs Headers Cookies Pros – sent automatically – no code required on the client Cons – sent automatically – even when do not want  e.g. <IMG src= in email – less control on validity – stored on client disk Headers Pros – sent only explicitely – not stored on disk – unless you want to – more control – also prevents CSRF Cons – require code on the client side – but this is normal in SPAs https://auth0.com/blog/2014/01/27/ ten-things-you-should-know-about- tokens-and-cookies/
  • 51. @carlobonamico#devoxxuk What else would we need? what happens when the user is not logged in? how to improve usability?
  • 52. @carlobonamico#devoxxuk Routing support for Authentication & Authorization Need to configure Routing for – redirect to login if not authenticated – redirect to login if token expired – optionally, redirect back to original URL – redirect to error page if route not authorized in the current profile Difficult to do in the default ngRoute – Possible in ui-router Way easier in angular-new-router – https://medium.com/angularjs-meetup-south-london/angular-ng- conf-2015-media-25dbe6250154
  • 54. @carlobonamico#devoxxuk CSRF See section “Security Considerations” on – https://docs.angularjs.org/api/ng/service/$http Angular automatically manages CSRF-prevention tokens if you use cookies The server needs to set a token – JavaScript readable session cookie called XSRF-TOKEN on the first HTTP GET request On subsequent XHR requests – the server can verify that the cookie matches X-XSRF-TOKEN HTTP header – the token must be unique for each user and must be verifiable by the server  e.g. a digest of your site's authentication cookie with a salt for added security Also, – Angular automatically supports JSONP-prevention characters  http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.as px/
  • 56. @carlobonamico#devoxxuk Typical Server side application Authorization is verified – in controllers if (user.hasRole(“admin”) == true) – through filters / interceptors – in views <hasRole role=”admin”> or <if (...)> confidential info </hasRole> Client Browser only receives content it has rights to – (roughly) works even if security checks are “spaghetti code” in the JSP/ASP/PHP templates
  • 57. @carlobonamico#devoxxuk And in a SPA? Would this be secure? In users-view.html <button ng­if=”authCtrl.isAdmin”          ng­click=”userCtrl.deleteUser()”> or this? <section ng­if=”authCtrl.isAdmin” > {{userCtrl.user.confidentialData}} </section>
  • 58. @carlobonamico#devoxxuk No! Just press F12 and modify the HTML / JS or even the DOM in the developer tools
  • 59. @carlobonamico#devoxxuk Security is up to the server Even in SPAs, Authorization is still up to the server: Security controls – checking authentication state – checking profile and inferring permissions – enabling privileged actions – filtering confidential data MUST be performed on the server – in the REST / websocket endpoints – locally in each service, or via filters/interceptors Also, the same rule applies to input validation
  • 60. @carlobonamico#devoxxuk Usability is up to the client But letting the user click on the button, invoking the service, and only then displaying an error is not user friendly UX is up to the client – Front-End should have enough info to disable/hide the button  if the user is not authorized to click it  retrieve the permissions list from a REST service at logon E.g. Permission check directives for Angular <button ng­click=”postCtrl.delete()”  has­permission=”deletePost”> permissions for Role-Based Access Control
  • 61. @carlobonamico#devoxxuk Checking the user profile So, in each server endpoint, you should check – valid authentication – valid authorization profile which includes privileges for the currently requested action / data Example Blog application if (subject.hasRole(“admin”)) //enable delete post if (subject.hasRole(“editor”)) //enable modification of post else //only read data What are the problems with this code?
  • 62. @carlobonamico#devoxxuk What if the rules change? What if an auditor asks about what an “editor” can do? Real-world cases tend to be more complex!
  • 63. @carlobonamico#devoxxuk Role Based Access Control Separating Role definition from Permission check – In each service / action, code checks that the user has the relevant permission if (subject.hasPermission(“deletePost”)) – Role Definition lists all the permissions  e.g. –Admin   detelePost, updatePost→ –anonymous   readPost→ Authorization system maps user/groups to list of roles – and computes the “merged” set of permissions active for the valid user  user is both Admin & Editor  Permissions are –changeSettings, deleteUser, addUser, deletePost,  modifyPost 
  • 64. @carlobonamico#devoxxuk Hierarchical permission system 2-level: User → Role → Permissions 3-level: User → Groups → Roles → Permissions Wildcard Permissions – blog:deletePost – blog:readPost – blog:* means both  blog:readPost:12 → entity level permission  blog:readPost:* on all entities see Apache Shiro
  • 65. @carlobonamico#devoxxuk Advantages Permission check is – focused, readable – easy to implement – easy to test – rarely changes Role definition is – centralized – easy to review – easy to change – as it tends to change often Secure Design Principle all parts of the system need to perform security checks but security check implementation should be centralized and not “spread” in the system
  • 66. @carlobonamico#devoxxuk RBAC in a Single Page Application Server-side Ingredients: – Profile definition mapping Roles to Permissions  static file  db table  possibly cached  Identity server (e.g. OpenAM) – API for checking permissions Normally, some of this information is cached to ensure minimal performance penalty
  • 67. @carlobonamico#devoxxuk Usable Secure UI in AngularJS Ingredients: – /authorization/profile/current REST endpoint  returns a Json  current user roles  merged list of all active permissions On the Client – Client Service wrapping the above – Authorization/ProfileService storing the permission list  hasPermission(p) method Call the service from – Controller methods – Routing callbacks
  • 70. @carlobonamico#devoxxuk Component Security The code we write The code which actually runs in our application – libraries and components
  • 71. @carlobonamico#devoxxuk Checking dependecies for vulns On the client side – http://retirejs.github.io/retire.js/ npm install ­g retire ; retire –path src – also available as ZAP & mvn plugin mvn com.h3xstream.retirejs:retirejs­maven­ plugin:scan On the server side – OWASP Dependency Check  https://github.com/jeremylong/DependencyCheck dependency­check.sh ­­app Testing ­­out . ­­scan  [path to jar files to be scanned] mvn org.owasp:dependency­check­maven
  • 72. @YourTwitterHandle#DVXFR14{session hashtag} @carlobonamico#devoxxuk A f nal w ord ... But isn't all that unnecessary complexity slowing down development of my critical project?
  • 73. @carlobonamico#devoxxuk A final word People tend to view Security as “overhead”, not adding value to the project The reality: – if you know what to pay attention to, minimal additional costs – also, in most cases, adding security just means following good design principles if you separate well concerns, adding security is easy – favor clarity of intent and code readability – favor composition over inheritance – test, test, test!  incorporate security checks in your tests This lets software adapt more easily to both requirements & security changes – easier to evolve incrementally & validating each step → see Continuous Delivery
  • 75. @carlobonamico#devoxxuk References Owasp Secure Coding Principles – https://www.owasp.org/index.php/Secure_Coding_Principles OWASP Testing Guide – https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_ of_Contents SOLID Design Principles – http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
  • 76. @carlobonamico#devoxxuk HTML5 Security Attack Vectors & Vulnerabilities – https://media.blackhat.com/bh-eu-12/shah/bh-eu-12-Shah_HTML5_ Top_10-WP.pdf OWASP Guidelines – https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet JS Frameworks Security – http://www.slideshare.net/x00mario/jsmvcomfg-to-sternly-look-at- javascript-mvc-and-templating-frameworks
  • 77. @carlobonamico#devoxxuk Thank You for your attention Interested? – attend our Web Application Security trainings – engage us for Design/Code Reviews, Vulnerability Assessments & team mentoring Read more on – http://www.nispro.it – http://www.slideshare.net/carlo.bonamico Follow us on twitter – @nis_srl @carlobonamico  updates on Security, AngularJS, Continuous Delivery Contact me – carlo.bonamico@gmail.com / carlo.bonamico@nispro.it