SlideShare ist ein Scribd-Unternehmen logo
1 von 93
Downloaden Sie, um offline zu lesen
Securing your AngularJS Application
Philippe De Ryck
About Me – Philippe De Ryck
2
§  Postdoctoral Researcher @ DistriNet (KU Leuven)
§  Focus on (client-side) Web security
§  Responsible for the Web Security training program
§  Dissemination of knowledge and research results
§  Target audiences include industry and researchers
§  Main author of the Primer on Client-Side Web Security
§  7 attacker models, broken down in 10 capabilities
§  13 attacks and their countermeasures
§  Overview of security best practices
iMinds-DistriNet, KU Leuven
3
§  Headcount:
§  10 professors
§  65 researchers
§  Research Domains
§  Secure Software
§  Distributed Software
§  Part of the iMinds Security Department
§  Together with COSIC and ICRI
§  Academic and industrial collaboration in 30+ national and
European projects
https://distrinet.cs.kuleuven.be
The Web Platform
4
Web Security has Become Complex
5http://arstechnica.com/security/2015/04/no-joke-googles-april-fools-prank-inadvertently-broke-sites-security/
Web Security has Become Complex
6http://arstechnica.com/security/2015/04/match-coms-http-only-login-page-puts-millions-of-passwords-at-risk/
Security of the Web Platform
7
Towards a Client-centric Web
8
§  The browser has become an application platform
§  Think of browser-based OSes
§  Think of Chrome’s packaged apps
§  Wide set of typical OS features are coming to the Web
§  Client-side storage
§  Access to system information
§  System-level notifications
§  Real-time communication
Client-Side Web Security
9
§  Browser security policies govern client-side behavior
§  Default policies apply to all applications running in the browser
§  Same-origin policy restricts interactions within the browser
§  Depended upon by numerous countermeasures
§  Modern client-side security policies are server-driven
§  Tailored towards a specific web application
§  Prevent unauthorized actions within the browser
§  Often preceded by autonomous client-side countermeasures
The Web Security Landscape
10
Overview
11
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Overview
12
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Cross-Site Request Forgery Illustrated
13
some-shop.com
hackedblog.com
Login as Philippe
Hello Philippe
Show orders
List of orders
Show latest blog post
Latest blog post
Change email address
Sure thing, Philippe
The Essence of CSRF
14
§  The server is confused about the intentions of the user
§  Malicious sites can trigger unintended requests from the browser
§  Consequence of the ambient authority carried by the cookie
§  Common vulnerability
§  Illustrated by cases at Google, Facebook, eBay, …
§  Ranked #8 on OWASP top 10 (2013)
§  Countermeasures require explicit action by the developer
§  Often only focus on POST / PUT / DELETE
CSRF Examples
15
http://news.softpedia.com/news/CSRF-Vulnerability-in-eBay-Allows-Hackers-to-Hijack-User-Accounts-Video-383316.shtml
CSRF Examples
16https://threatpost.com/pharming-attack-targets-home-router-dns-settings/111326
http://arstechnica.com/security/2014/03/hackers-hijack-300000-plus-wireless-routers-make-malicious-changes/
CSRF Defense 1: HTML tokens
17
§  Hide token within the page, and check upon form submission
§  Same-Origin Policy keeps this token out of reach for the attacker
some-shop.com
hackedblog.com
Account details page
Account details
Change email address
Sure thing, Philippe
Show latest blog post
Latest blog post
Change email address
CSRF token sadness L
!
!
CSRF Defense 1: HTML tokens
18
§  Hide token within the page, and check upon form submission
§  Same-Origin Policy keeps this token out of reach for the attacker
<form action=“submit.php”>
<input type=“hidden” name=“token”
value=“qasfj8j12adsjadu2223” />
…
</form>
TOKEN-BASED APPROACH
CSRF Defense 2: Origin Header
19
§  Check the origin header sent by the browser
§  Automatically added to state-changing requests (POST, PUT, DELETE)
some-shop.com
hackedblog.com
Change email address
Origin: some-shop.com
Sure thing, Philippe
Show latest blog post
Latest blog post
Change email address
Origin: hackedblog.com
Stranger danger! L
CSRF Defense 3: Transparent Tokens
20
§  Transparent token stored in cookie, checked in header
§  Security depends on the ability to read the cookie from JavaScript
some-shop.com
First request
Set-Cookie: session=…
Set-Cookie: CSRF-Token=123
Cookie: session=…
Cookie: CSRF-Token=123
Only the JS code on the page can
copy cookie value into header
X-CSRF-Token: 123
var csrf = require('csurf');
app.use(csrf());
app.use("/", function(req, res, next) {
res.cookie('XSRF-TOKEN', req.csrfToken());
next();
});
TRANSPARENT TOKENS
CSRF Defense 3: Transparent Tokens
21
§  Transparent token stored in cookie, checked in header
§  Security depends on the ability to read the cookie from JavaScript
§  By default, GET, HEAD and OPTIONS are not covered
Enabled by default for ‘XSRF-TOKEN’
TRANSPARENT TOKENS
Overview
22
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Overview
23
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Cross-Site Scripting (XSS)
24
§  Injection of attacker-controlled script into victim application
§  Very common Web vulnerability
§  Ranked #3 in OWASP’s top 10 (2013)
§  Referred to as the buffer overflow of the Web
§  Why is XSS such a big deal?
§  Attacker can run code with your application’s privileges
§  Full access to page’s contents and resources
§  Full use of granted permissions
§  Launch platform for attack escalation (e.g. malware)
Cross-Site Scripting Example
25
some-shop.com
Show reviews
List of reviews
Add Review
OK
Attacker
Victim
Bleh is awesome!
<script>
alert(‘haha, NOT’)
</script>
Cross-Site Scripting Payloads
26
§  XSS payload is often benign, just to show a proof of exploit
Cross-Site Scripting Payloads
27
§  XSS payload is often benign, just to show a proof of exploit
§  XSS payloads are only limited by your creativity
§  Session hijacking
§  Defacement
§  Undermining defenses (e.g. CSRF)
§  Keylogging
§  Network scanning
§  …
§  Can be used to launch a more elaborate attack
Apache.org Compromise
28
1. Report bug with obscured URL
containing reflected XSS attack
http://tinyurl.com/XXXXXXX
2. Admin opens link,
compromising their session
3. Attacker disable notifications
for a hosted project
4. Attacker changes upload
path to location that can
execute JSP files
5. Attacker added new bug
reports with JSP attachments
6. Attacker browses and copies
filesystem through JSP. Installs
backdoor JSP with webserver
privileges
http://blogs.apache.org/infra/entry/apache_org_04_09_2010
Apache.org Compromise
29
7. Attacker installs JAR to
collect passwords on login
8. Triggered logins by sending
out password reset mails
9. One of the passwords
matched an SSH account with
full sudo access
10. The accessible machine
had user home folders, with
cached subversion credentials
11. From the subversion
machine, privilege escalation
was unsuccessful
http://blogs.apache.org/infra/entry/apache_org_04_09_2010
Different Types of XSS
30
§  Different types of script injection
§  Persistent: stored data used in the response
§  Reflected: part of the URI used in the response
§  DOM-based: data used by client-side scripts
http://www.example.com/search?q=<script>alert(‘XSS’);</script>
<h1>You searched for<script>alert(‘XSS’);</script></h1>
REFLECTED XSS
Different Types of XSS
31
§  Different types of script injection
§  Persistent: stored data used in the response
§  Reflected: part of the URI used in the response
§  DOM-based: data used by client-side scripts
http://www.example.com/search?name=<script>alert(‘XSS’);</script>
<script>
name = document.URL.substring(document.URL.indexOf("name=")+5);
document.write(“<h1>Welcome “ + name + “</h1>”);
</script>
<h1>Welcome <script>alert(‘XSS’);</script></h1>
DOM-BASED XSS
Mitigating XSS
32
§  Secure coding practices
§  Do not rely on simple filters (e.g. removing <, >, &, “, ‘)
§  Use context-sensitive output encoding
•  HTML body <h1>DATA</h1>
•  HTML attributes <div id=‘DATA’>
•  Stylesheet context body { background-color: DATA; }
•  Script context alert(“DATA”);
•  URL context <a href=“http://example.com?arg=DATA”>
§  Additional layers of defense
§  Browsers incorporate reflective XSS filters
§  Content Security Policy allows servers to prevent inline script execution
Overview
33
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
XSS and JS MVC Frameworks
34
§  JS MVC frameworks change the underlying architecture
§  Highly dynamic front ends
§  Data-oriented back ends
§  Difficult to match to traditional XSS countermeasures
§  Two important aspects with regard to XSS
§  Server-involvement in templating
§  Client-side data processing
Server-Side Template Composition
35
§  Traditional web back end with JS MVC front end
§  Server-composed view, with dynamic client-side features
§  Keep doing context-aware XSS protection on the server
<script src=“knockout-2.3.0.js"></script>
<div data-bind="x:alert(1)" />
<script>
ko.applyBindings();
</script>
KNOCKOUT.JS EXAMPLE
https://code.google.com/p/mustache-security/ (Mario Heiderich)
Server-Side Template Composition
36
§  Traditional web back end with JS MVC front end
§  Server-composed view, with dynamic client-side features
§  Keep doing context-aware XSS protection on the server
<script src=“knockout-2.3.0.js"></script>
<div data-bind="x:alert(1)" />
<script>
ko.applyBindings();
</script>
KNOCKOUT.JS EXAMPLE
https://code.google.com/p/mustache-security/ (Mario Heiderich)
Server-Side Template Composition
37
§  Traditional web back end with JS MVC front end
§  Server-composed view, with dynamic client-side features
§  Keep doing context-aware XSS protection on the server
§  JavaScript MVC frameworks change how the DOM works
<graph class="visitor-graph">
<axis position="left"></axis>
<axis position="bottom"></axis>
<line name="typical-week" line-data="model.series.typicalWeek"></line>
<line name="this-week" line-data="model.series.thisWeek"></line>
<line name="last-week" line-data="model.series.lastWeek"></line>
</graph>
EXTENDING THE DOM
Server-Side Template Composition
38
§  Traditional web back end with JS MVC front end
§  Server-composed view, with dynamic client-side features
§  Keep doing context-aware XSS protection on the server
§  JavaScript MVC frameworks change how the DOM works
§  Extensions through elements, attributes, etc.
§  New interfaces
§  Often in combination with templating
§  This seems problematic …
Mustache Security {{ }}
39
§  Project dedicated to JS MVC security pitfalls
§  Assuming there is an injection vector
§  Assuming there is conventional XSS filtering in place
§  What can an attacker do?
§  New behavior often breaks existing security assumptions
§  Bypass currently used security mechanisms
§  Script injection possible whenever a data attribute is allowed
https://code.google.com/p/mustache-security/ (Mario Heiderich)
Mustache Security Examples
40
https://code.google.com/p/mustache-security/ (Mario Heiderich)
<script src=“jquery-1.7.1.min.js"></script>
<script src=“kendo.all.min.js"></script>
<div id="x"># alert(1) #</div>
<script>
var template = kendo.template($("#x").html());
var tasks = [{ id: 1}];
var dataSource = new kendo.data.DataSource({ data: tasks });
dataSource.bind("change", function(e) {
var html = kendo.render(template, this.view());
});
dataSource.read();
</script>
KENDOUI EXAMPLE
Mustache Security Examples
41
https://code.google.com/p/mustache-security/ (Mario Heiderich)
<script src=“jquery-1.7.1.min.js"></script>
<script src=“kendo.all.min.js"></script>
<div id="x"># alert(1) #</div>
<script>
var template = kendo.template($("#x").html());
var tasks = [{ id: 1}];
var dataSource = new kendo.data.DataSource({ data: tasks });
dataSource.bind("change", function(e) {
var html = kendo.render(template, this.view());
});
dataSource.read();
</script>
KENDOUI EXAMPLE
Mustache Security Examples
42
https://code.google.com/p/mustache-security/ (Mario Heiderich)
<script src=“angular1.1.5.min.js"></script>
<div class="ng-app">
{{constructor.constructor('alert(1)')()}}
</div>
ANGULARJS EXAMPLE (< 1.2)
Mustache Security Examples
43
https://code.google.com/p/mustache-security/ (Mario Heiderich)
<script src=“angular1.1.5.min.js"></script>
<div class="ng-app">
{{constructor.constructor('alert(1)')()}}
</div>
ANGULARJS EXAMPLE (< 1.2)
Separating Front End and Back End
44
§  Beware of server-side composition of templates
§  Generally a bad idea, because of dynamic behavior
§  If you must do this, AngularJS 1.2+ enforces quite a good sandbox
§  Separating the front end from the back end
§  Server provides client-side application as static files
§  Server offers data through a well-designed API
§  Client-side application contains the dynamic behavior
§  More security responsibilities for the client-side application
XSS and JS MVC Frameworks
45
§  JS MVC frameworks change the underlying architecture
§  Highly dynamic front ends
§  Data-oriented back ends
§  Difficult to match to traditional XSS countermeasures
§  Two important aspects with regard to XSS
§  Server-involvement in templating
§  Client-side data processing
Mitigating XSS in AngularJS
46
§  AngularJS is a client-side technology
§  Generally cooperates with a RESTful back end
§  RESTful back end is purely data-driven
§  Applying context-sensitive output encoding
§  Back end has no idea where data will be used …
§  So it should be done on the client then?
§  So how does it work in AngularJS?
Example: Allowing User-Provided Images
47
<textarea ng-model=“x”></textarea>
<div>{{x}}</div>
ANGULARJS TEMPLATE
<img src=”http://some-shop.com/coolcar.png" />
USER INPUT
<div>
<img src=”http://some-shop.com/coolcar.png" />
</div>
GENERATED HTML
Example: Allowing User-Provided Images
48
<textarea ng-model=“x”></textarea>
<div ng-bind=”x"></div>
ANGULARJS TEMPLATE
<img src=”http://some-shop.com/coolcar.png" />
USER INPUT
<div ng-bind=”x">
<img src=”http://some-shop.com/coolcar.png" />
</div>
GENERATED HTML
Example: Allowing User-Provided Images
49
<textarea ng-model=“x”></textarea>
<div ng-bind-html=”x"></div>
ANGULARJS TEMPLATE
<img src=”http://some-shop.com/coolcar.png" />
USER INPUT
Error: [$sce:unsafe] Attempting to use
an unsafe value in a safe context.
GENERATED HTML
Dammit
50
Check Documentation
51
Go to StackOverflow
52
And you Find This Little Gem
53
Example: Allowing User-Provided Images
54
<textarea ng-model=“x”></textarea>
<div ng-bind-html=”x | sanitize"></div>
ANGULARJS TEMPLATE
<img src=”http://some-shop.com/coolcar.png" />
USER INPUT
GENERATED HTML
Example: Allowing User-Provided Images
55
<textarea ng-model=“x”></textarea>
<div ng-bind-html=”x | sanitize"></div>
ANGULARJS TEMPLATE
<img src=”http://some-shop.com/coolcar.png"
onerror=“alert(1)” />
USER INPUT
GENERATED HTML
Wait … What?
56
Strict Contextual Escaping
57
§  AngularJS tries to protect you from injection attacks
§  Let it, it’s really good at it!
§  ng-bind will never produce HTML
<textarea ng-model=“x”></textarea>
<div ng-bind=”x"></div>
ANGULARJS TEMPLATE
<div ng-bind=”x">
<img src=”http://some-shop.com/coolcar.png"
onerror=“alert(1)” />
</div>
GENERATED HTML
Strict Contextual Escaping
58
§  AngularJS tries to protect you from injection attacks
§  Let it, it’s really good at it!
§  ng-bind-html can produce HTML, but not without protection
<textarea ng-model=“x”></textarea>
<div ng-bind-html=”x"></div>
ANGULARJS TEMPLATE
Error: [$sce:unsafe] Attempting to use
an unsafe value in a safe context.
GENERATED HTML
Strict Contextual Escaping
59
§  AngularJS tries to protect you from injection attacks
§  Let it, it’s really good at it!
§  ng-bind-html can produce HTML, but not without protection
§  Enable automatic sanitization with ngSanitize
§  Removes dangerous features from content
Strict Contextual Escaping - ngSanitize
60
<textarea ng-model=“x”></textarea>
<div ng-bind-html=”x"></div>
ANGULARJS TEMPLATE
<img src=”http://some-shop.com/coolcar.png"
onerror=“alert(1)” />
USER INPUT
angular.module(“test”, [“ngSanitize”])…
ANGULARJS CODE
GENERATED HTML
<img src=”http://some-…car.png" />
Strict Contextual Escaping
61
§  AngularJS tries to protect you from injection attacks
§  Let it, it’s really good at it!
§  ng-bind-html can output raw trusted HTML
§  $sce.trustAsHtml() allows you to mark HTML as trusted
§  Only use if you are really sure it’s trusted, and checked twice
Strict Contextual Escaping - trustAsHtml
62
Strict Contextual Escaping - trustAsHtml
63
<textarea ng-model=“x”></textarea>
<div ng-bind-html=”x | i_really_know_my_security"></div>
ANGULARJS TEMPLATE
angular.module(“test”,[])
.filter("i_really_know_my_security",
['$sce', function($sce) {
return function(htmlCode){
return $sce.trustAsHtml(htmlCode);
}
}]);
ANGULARJS CODE
Overview
64
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Overview
65
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Content Security Policy
66
your defenses against content injection vulnerabilities
The Essence of CSP
67
§  CSP reduces the harm of content injection vulnerabilities
§  By telling the client where resources should be loaded from
§  By disabling “dangerous features” by default
§  Policy is delivered as an HTTP header by the server
§  Compatible browsers will enforce the policy on the response
§  A policy consists of a set of directives
§  Each directive controls a different kind of resource
CSP Example
68
Content-Security-Policy:
default-src 'self';
img-src *;
object-src media1.some-shop.com media2.some-shop.com
*.cdn.some-shop.com;
script-src trustedscripts.some-shop.com
EXAMPLE POLICY
How CSP Started …
69
§  CSP started as a research paper by the Mozilla team
§  Aim to give administrator control over appearance of site
§  Aim to give users some confidence where data is sent to
§  Even in the presence of an attacker that controls content
§  Policy consists of 9 URI directives giving control over:
§  Source of fonts, images, media, object, script, styles, frames
§  Source of ancestor frames
§  Destination of XHR requests
And what CSP Is Now
70
§  CSP has been well received, and evolved quickly
§  Addition of plugin types, sandbox, child contexts, form destinations
§  Additional spec adds UI Security Directives
§  Deprecates X-FRAME-OPTIONS header
§  Additional features to overcome implementation hurdles
§  Widely supported by browsers
§  Chrome makes CSP mandatory for its components
§  Browser extensions and packaged apps
A Selective View on CSP
71
§  By default, CSP will:
§  Prevent resources from being loaded from non-whitelisted locations
§  default-src
§  Specifies the default sources of all content
§  Can be overwritten with more specific directives for each type
§  img-src
§  Specifies the sources of images
§  font-src, media-src, object-src, …
A Selective View on CSP
72
§  By default, CSP will:
§  Prevent resources from being loaded from non-whitelisted locations
§  Inline content from being executed
§  The use of eval()
§  What is considered inline content?
§  Script blocks embedded in HTML
§  Event handlers that are added as an HTML attribute
§  Style blocks embedded in HTML
§  Style info added with the style attribute
A Selective View on CSP
73
§  By default, CSP will:
§  Prevent resources from being loaded from non-whitelisted locations
§  Inline content from being executed
§  The use of eval()
§  What is considered inline content?
§  Script blocks embedded in HTML
§  Event handlers that are added as an HTML attribute
§  Style blocks embedded in HTML
§  Style info added with the style attribute
WAIT … WHAT?
Examples of Inline Content Problems
74
<script>
function run() {
alert(’booh!');
}
</script>
<a href="#" onclick="run()">…</a>
INLINE SCRIPT
Examples of Inline Content Problems
75
<script>
function run() {
alert(’booh!');
}
</script>
<a href="#" onclick="run()">…</a>
INLINE SCRIPT
Examples of Inline Content Problems
76
<script src="myscript.js"></script>
<a href="#" id="myLink">...</a>
EXTERNALIZED SCRIPT
function run() {
alert('booh!');
}
document.addEventListener('DOMContentReady',
function () {
document.getElementById('myLink')
.addEventListener('click', run);
});
EXTERNALIZED SCRIPT
Lifting Content Restrictions in CSP
77
§  script-src and style-src support the lifting of restrictions
§  By specifying ‘unsafe-inline’ and ‘unsafe-eval’
§  Not recommended, as this renders protection useless
§  CSP 1.1 supports nonces and hashes
§  Inline script and style blocks can be allowed
Content-Security-Policy:
script-src ‘self’ ‘nonce-RANDOM’;
EXAMPLE POLICY WITH A NONCE
<script nonce=“RANDOM”>…</script>
EXAMPLE USE OF A NONCE
Lifting Content Restrictions in CSP
78
§  script-src and style-src support the lifting of restrictions
§  By specifying ‘unsafe-inline’ and ‘unsafe-eval’
§  Not recommended, as this renders protection useless
§  CSP 1.1 supports nonces and hashes
§  Inline script and style blocks can be allowed
Content-Security-Policy:
script-src ‘self’ ‘nonce-a8qzj1r’;
EXAMPLE POLICY WITH A NONCE
<script nonce=“a8qzj1r”>…</script>
EXAMPLE USE OF A NONCE
CSP Examples
79
Goal: Load no external resources
Content-Security-Policy:
default-src ‘self’;
EXAMPLE POLICY
Goal: Load all content over HTTPS
Content-Security-Policy:
default-src https: ‘unsafe-inline’ ‘unsafe-eval’;
EXAMPLE POLICY
CSP Violation Reports
80
§  CSP can report violations back to the resource server
§  Allows for fine-tuning of the CSP policy
§  Gives insights in actual attacks
§  Enabled by using the report-uri directive
§  Points to a handler on the server that can process reports
Content-Security-Policy:
default-src 'self';
report-uri http://some-shop.com/csp-report.cgi
EXAMPLE POLICY
CSP Violation Report Example
81
{
"csp-report": {
"document-uri": "http://some-shop.com/page.html",
"referrer": "http://attacker.com/haxor.html",
"blocked-uri": "http://attacker.com/image.png",
"violated-directive": "default-src 'self'",
"effective-directive": "img-src",
"original-policy": "default-src 'self';
report-uri http://some-shop.com/csp-report.cgi"
}
}
EXAMPLE VIOLATION REPORT
CSP and JS MVC Frameworks
82
§  Default behavior of MVC frameworks is not CSP compatible
§  Dependent on string-to-code functionality
§  Requires unsafe-eval in CSP, which kind of misses the point
CSP and JS MVC Frameworks
83
§  Default behavior of MVC frameworks is not CSP compatible
§  Dependent on string-to-code functionality
§  Requires unsafe-eval in CSP, which kind of misses the point
§  AngularJS offers a special CSP mode
§  Simply specify ng-csp alongside your app
§  Include one tiny stylesheet for CSP compliance
<html ng-app ng-csp> … </html>
CSP-COMPLIANT ANGULARJS
AngularJS and CSP
84
§  So CSP prevents inline scripts from running …
<html ng-app ng-csp>
<body ng-controller="MyController">
<h1 onclick="alert(0)">Click me</h1>
<h1 ng-click="$event.view.alert(1)">Click me</h1>
<h1 ng-mouseover=
"$event.target.ownerDocument.defaultView.alert(2)”>
Hover me
</h1>
</body>
</html>
INLINE CODE IN ANGULARJS
https://code.google.com/p/mustache-security/ (Mario Heiderich)
AngularJS and CSP
85
§  So CSP prevents inline scripts from running …
<html ng-app ng-csp>
<body ng-controller="MyController">
<h1 onclick="alert(0)">Click me</h1>
<h1 ng-click="$event.view.alert(1)">Click me</h1>
<h1 ng-mouseover=
"$event.target.ownerDocument.defaultView.alert(2)”>
Hover me
</h1>
</body>
</html>
INLINE CODE IN ANGULARJS
https://code.google.com/p/mustache-security/ (Mario Heiderich)
Refused to execute inline event handler because it violates
the following Content Security Policy directive: "script-src
'self' http://ajax.googleapis.com 'nonce-bleh'". Either the
'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce
('nonce-...') is required to enable inline execution.
AngularJS and CSP
86
§  So CSP prevents inline scripts from running …
<html ng-app ng-csp>
<body ng-controller="MyController">
<h1 onclick="alert(0)">Click me</h1>
<h1 ng-click="$event.view.alert(1)">Click me</h1>
<h1 ng-mouseover=
"$event.target.ownerDocument.defaultView.alert(2)”>
Hover me
</h1>
</body>
</html>
INLINE CODE IN ANGULARJS
https://code.google.com/p/mustache-security/ (Mario Heiderich)
AngularJS and CSP
87
§  So CSP prevents inline scripts from running …
<html ng-app ng-csp>
<body ng-controller="MyController">
<h1 onclick="alert(0)">Click me</h1>
<h1 ng-click="$event.view.alert(1)">Click me</h1>
<h1 ng-mouseover=
"$event.target.ownerDocument.defaultView.alert(2)”>
Hover me
</h1>
</body>
</html>
INLINE CODE IN ANGULARJS
https://code.google.com/p/mustache-security/ (Mario Heiderich)
AngularJS and CSP
88
§  So how does angular process event handlers?
§  Parse ‘ng’-attributes
§  Create anonymous functions, connected with events
§  Wait for event handler to fire
§  Technically, not inline, and no eval()
§  CSP 1.2.x has a strong sandbox
§  No more references to dangerous objects (e.g. window)
$element.onclick = function($event) {
$event[‘view’][‘alert’](‘1’)
}
https://code.google.com/p/mustache-security/ (Mario Heiderich)
Overview
89
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Overview
90
§  Cross-Site Request Forgery
§  Technicalities and common countermeasures
§  Mitigating CSRF in AngularJS applications
§  Cross-Site Scripting
§  Technicalities and common countermeasures
§  XSS and JS MVC frameworks
§  Content Security Policy
§  CSP as a second line of defense
§  Compatibility of AngularJS with CSP
Action Points for Tomorrow
91
1.  Check whether your APIs are vulnerable to CSRF attacks
§  Enable CSRF mitigation through transparent tokens
2.  Make sure you refrain from server-side templating
§  Let your AngularJS application deal with templating and security
§  Communicate with data-driven APIs
§  Use a proxy to transform existing endpoints into such APIs
§  Enable CSRF mitigation through transparent tokens
3.  Look into deploying CSP
§  Start with a small application, with little third-party dependencies
§  Use the reporting feature to dry-run a policy before deploying
§  Share your findings!
Building Secure Single Page Applications
92
§  Single day training at the OWASP AppSec.eu conference
§  Covers various front end and back end security topics
§  Including the topics from this evening in more depth
§  Hands-on sessions using AngularJS and Express
https://2015.appsec.eu/trainings
Securing your AngularJS Application
Philippe De Ryck
philippe.deryck@cs.kuleuven.be
/in/philippederyck
https://distrinet.cs.kuleuven.be/people/philippe

Weitere ähnliche Inhalte

Was ist angesagt?

Scriptless Attacks - Stealing the Pie without touching the Sill
Scriptless Attacks - Stealing the Pie without touching the SillScriptless Attacks - Stealing the Pie without touching the Sill
Scriptless Attacks - Stealing the Pie without touching the Sill
Mario Heiderich
 
Security Testing Mobile Applications
Security Testing Mobile ApplicationsSecurity Testing Mobile Applications
Security Testing Mobile Applications
Denim Group
 

Was ist angesagt? (20)

Node js
Node jsNode js
Node js
 
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
 
Pros & cons of svelte
Pros & cons of sveltePros & cons of svelte
Pros & cons of svelte
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Scriptless Attacks - Stealing the Pie without touching the Sill
Scriptless Attacks - Stealing the Pie without touching the SillScriptless Attacks - Stealing the Pie without touching the Sill
Scriptless Attacks - Stealing the Pie without touching the Sill
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
 
Mobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android AppMobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android App
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Security Testing Mobile Applications
Security Testing Mobile ApplicationsSecurity Testing Mobile Applications
Security Testing Mobile Applications
 
WebdriverIO: the Swiss Army Knife of testing
WebdriverIO: the Swiss Army Knife of testingWebdriverIO: the Swiss Army Knife of testing
WebdriverIO: the Swiss Army Knife of testing
 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
 
CommitConf 2023 - Spring Framework 6 y Spring Boot 3
CommitConf 2023 - Spring Framework 6 y Spring Boot 3CommitConf 2023 - Spring Framework 6 y Spring Boot 3
CommitConf 2023 - Spring Framework 6 y Spring Boot 3
 
SAST - Desarrollo Seguro ¿Qué es? ¿Por que utilizarlo?
SAST - Desarrollo Seguro ¿Qué es? ¿Por que utilizarlo?SAST - Desarrollo Seguro ¿Qué es? ¿Por que utilizarlo?
SAST - Desarrollo Seguro ¿Qué es? ¿Por que utilizarlo?
 
Nitro for your Grails App: how to improve performance. Greach '18
Nitro for your Grails App: how to improve performance. Greach '18Nitro for your Grails App: how to improve performance. Greach '18
Nitro for your Grails App: how to improve performance. Greach '18
 
XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?
 
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security TeamSecrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
Secrets of Google VRP by: Krzysztof Kotowicz, Google Security Team
 
Automated Security Analysis of Android & iOS Applications with Mobile Securit...
Automated Security Analysis of Android & iOS Applications with Mobile Securit...Automated Security Analysis of Android & iOS Applications with Mobile Securit...
Automated Security Analysis of Android & iOS Applications with Mobile Securit...
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 

Andere mochten auch

Andere mochten auch (12)

Securing your EmberJS Application
Securing your EmberJS ApplicationSecuring your EmberJS Application
Securing your EmberJS Application
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
CP 值很高的 Gulp
CP 值很高的 GulpCP 值很高的 Gulp
CP 值很高的 Gulp
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 

Ähnlich wie Securing your AngularJS Application

OWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgeryOWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgery
Nikola Milosevic
 
Site Security Policy - Yahoo! Security Week
Site Security Policy - Yahoo! Security WeekSite Security Policy - Yahoo! Security Week
Site Security Policy - Yahoo! Security Week
guest9663eb
 
OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery
OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request ForgeryOWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery
OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery
OWASP Khartoum
 
W3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realities
Brad Hill
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
Jeremiah Grossman
 

Ähnlich wie Securing your AngularJS Application (20)

OWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgeryOWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgery
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
 
W3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realities
 
Owasp web application security trends
Owasp web application security trendsOwasp web application security trends
Owasp web application security trends
 
[2.1] Web application Security Trends - Omar Ganiev
[2.1] Web application Security Trends - Omar Ganiev[2.1] Web application Security Trends - Omar Ganiev
[2.1] Web application Security Trends - Omar Ganiev
 
Site Security Policy - Yahoo! Security Week
Site Security Policy - Yahoo! Security WeekSite Security Policy - Yahoo! Security Week
Site Security Policy - Yahoo! Security Week
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
 
Web Application Scanning 101
Web Application Scanning 101Web Application Scanning 101
Web Application Scanning 101
 
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
 
OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery
OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request ForgeryOWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery
OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery
 
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
 
Automatically detecting security vulnerabilities in WordPress
Automatically detecting security vulnerabilities in WordPressAutomatically detecting security vulnerabilities in WordPress
Automatically detecting security vulnerabilities in WordPress
 
W3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realities
 
Why Traditional Web Security Technologies no Longer Suffice to Keep You Safe
Why Traditional Web Security Technologies no Longer Suffice to Keep You SafeWhy Traditional Web Security Technologies no Longer Suffice to Keep You Safe
Why Traditional Web Security Technologies no Longer Suffice to Keep You Safe
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
 
Web security for developers
Web security for developersWeb security for developers
Web security for developers
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka IrongeekMutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
Owasp web security
Owasp web securityOwasp web security
Owasp web security
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Securing your AngularJS Application

  • 1. Securing your AngularJS Application Philippe De Ryck
  • 2. About Me – Philippe De Ryck 2 §  Postdoctoral Researcher @ DistriNet (KU Leuven) §  Focus on (client-side) Web security §  Responsible for the Web Security training program §  Dissemination of knowledge and research results §  Target audiences include industry and researchers §  Main author of the Primer on Client-Side Web Security §  7 attacker models, broken down in 10 capabilities §  13 attacks and their countermeasures §  Overview of security best practices
  • 3. iMinds-DistriNet, KU Leuven 3 §  Headcount: §  10 professors §  65 researchers §  Research Domains §  Secure Software §  Distributed Software §  Part of the iMinds Security Department §  Together with COSIC and ICRI §  Academic and industrial collaboration in 30+ national and European projects https://distrinet.cs.kuleuven.be
  • 5. Web Security has Become Complex 5http://arstechnica.com/security/2015/04/no-joke-googles-april-fools-prank-inadvertently-broke-sites-security/
  • 6. Web Security has Become Complex 6http://arstechnica.com/security/2015/04/match-coms-http-only-login-page-puts-millions-of-passwords-at-risk/
  • 7. Security of the Web Platform 7
  • 8. Towards a Client-centric Web 8 §  The browser has become an application platform §  Think of browser-based OSes §  Think of Chrome’s packaged apps §  Wide set of typical OS features are coming to the Web §  Client-side storage §  Access to system information §  System-level notifications §  Real-time communication
  • 9. Client-Side Web Security 9 §  Browser security policies govern client-side behavior §  Default policies apply to all applications running in the browser §  Same-origin policy restricts interactions within the browser §  Depended upon by numerous countermeasures §  Modern client-side security policies are server-driven §  Tailored towards a specific web application §  Prevent unauthorized actions within the browser §  Often preceded by autonomous client-side countermeasures
  • 10. The Web Security Landscape 10
  • 11. Overview 11 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 12. Overview 12 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 13. Cross-Site Request Forgery Illustrated 13 some-shop.com hackedblog.com Login as Philippe Hello Philippe Show orders List of orders Show latest blog post Latest blog post Change email address Sure thing, Philippe
  • 14. The Essence of CSRF 14 §  The server is confused about the intentions of the user §  Malicious sites can trigger unintended requests from the browser §  Consequence of the ambient authority carried by the cookie §  Common vulnerability §  Illustrated by cases at Google, Facebook, eBay, … §  Ranked #8 on OWASP top 10 (2013) §  Countermeasures require explicit action by the developer §  Often only focus on POST / PUT / DELETE
  • 17. CSRF Defense 1: HTML tokens 17 §  Hide token within the page, and check upon form submission §  Same-Origin Policy keeps this token out of reach for the attacker some-shop.com hackedblog.com Account details page Account details Change email address Sure thing, Philippe Show latest blog post Latest blog post Change email address CSRF token sadness L ! !
  • 18. CSRF Defense 1: HTML tokens 18 §  Hide token within the page, and check upon form submission §  Same-Origin Policy keeps this token out of reach for the attacker <form action=“submit.php”> <input type=“hidden” name=“token” value=“qasfj8j12adsjadu2223” /> … </form> TOKEN-BASED APPROACH
  • 19. CSRF Defense 2: Origin Header 19 §  Check the origin header sent by the browser §  Automatically added to state-changing requests (POST, PUT, DELETE) some-shop.com hackedblog.com Change email address Origin: some-shop.com Sure thing, Philippe Show latest blog post Latest blog post Change email address Origin: hackedblog.com Stranger danger! L
  • 20. CSRF Defense 3: Transparent Tokens 20 §  Transparent token stored in cookie, checked in header §  Security depends on the ability to read the cookie from JavaScript some-shop.com First request Set-Cookie: session=… Set-Cookie: CSRF-Token=123 Cookie: session=… Cookie: CSRF-Token=123 Only the JS code on the page can copy cookie value into header X-CSRF-Token: 123
  • 21. var csrf = require('csurf'); app.use(csrf()); app.use("/", function(req, res, next) { res.cookie('XSRF-TOKEN', req.csrfToken()); next(); }); TRANSPARENT TOKENS CSRF Defense 3: Transparent Tokens 21 §  Transparent token stored in cookie, checked in header §  Security depends on the ability to read the cookie from JavaScript §  By default, GET, HEAD and OPTIONS are not covered Enabled by default for ‘XSRF-TOKEN’ TRANSPARENT TOKENS
  • 22. Overview 22 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 23. Overview 23 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 24. Cross-Site Scripting (XSS) 24 §  Injection of attacker-controlled script into victim application §  Very common Web vulnerability §  Ranked #3 in OWASP’s top 10 (2013) §  Referred to as the buffer overflow of the Web §  Why is XSS such a big deal? §  Attacker can run code with your application’s privileges §  Full access to page’s contents and resources §  Full use of granted permissions §  Launch platform for attack escalation (e.g. malware)
  • 25. Cross-Site Scripting Example 25 some-shop.com Show reviews List of reviews Add Review OK Attacker Victim Bleh is awesome! <script> alert(‘haha, NOT’) </script>
  • 26. Cross-Site Scripting Payloads 26 §  XSS payload is often benign, just to show a proof of exploit
  • 27. Cross-Site Scripting Payloads 27 §  XSS payload is often benign, just to show a proof of exploit §  XSS payloads are only limited by your creativity §  Session hijacking §  Defacement §  Undermining defenses (e.g. CSRF) §  Keylogging §  Network scanning §  … §  Can be used to launch a more elaborate attack
  • 28. Apache.org Compromise 28 1. Report bug with obscured URL containing reflected XSS attack http://tinyurl.com/XXXXXXX 2. Admin opens link, compromising their session 3. Attacker disable notifications for a hosted project 4. Attacker changes upload path to location that can execute JSP files 5. Attacker added new bug reports with JSP attachments 6. Attacker browses and copies filesystem through JSP. Installs backdoor JSP with webserver privileges http://blogs.apache.org/infra/entry/apache_org_04_09_2010
  • 29. Apache.org Compromise 29 7. Attacker installs JAR to collect passwords on login 8. Triggered logins by sending out password reset mails 9. One of the passwords matched an SSH account with full sudo access 10. The accessible machine had user home folders, with cached subversion credentials 11. From the subversion machine, privilege escalation was unsuccessful http://blogs.apache.org/infra/entry/apache_org_04_09_2010
  • 30. Different Types of XSS 30 §  Different types of script injection §  Persistent: stored data used in the response §  Reflected: part of the URI used in the response §  DOM-based: data used by client-side scripts http://www.example.com/search?q=<script>alert(‘XSS’);</script> <h1>You searched for<script>alert(‘XSS’);</script></h1> REFLECTED XSS
  • 31. Different Types of XSS 31 §  Different types of script injection §  Persistent: stored data used in the response §  Reflected: part of the URI used in the response §  DOM-based: data used by client-side scripts http://www.example.com/search?name=<script>alert(‘XSS’);</script> <script> name = document.URL.substring(document.URL.indexOf("name=")+5); document.write(“<h1>Welcome “ + name + “</h1>”); </script> <h1>Welcome <script>alert(‘XSS’);</script></h1> DOM-BASED XSS
  • 32. Mitigating XSS 32 §  Secure coding practices §  Do not rely on simple filters (e.g. removing <, >, &, “, ‘) §  Use context-sensitive output encoding •  HTML body <h1>DATA</h1> •  HTML attributes <div id=‘DATA’> •  Stylesheet context body { background-color: DATA; } •  Script context alert(“DATA”); •  URL context <a href=“http://example.com?arg=DATA”> §  Additional layers of defense §  Browsers incorporate reflective XSS filters §  Content Security Policy allows servers to prevent inline script execution
  • 33. Overview 33 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 34. XSS and JS MVC Frameworks 34 §  JS MVC frameworks change the underlying architecture §  Highly dynamic front ends §  Data-oriented back ends §  Difficult to match to traditional XSS countermeasures §  Two important aspects with regard to XSS §  Server-involvement in templating §  Client-side data processing
  • 35. Server-Side Template Composition 35 §  Traditional web back end with JS MVC front end §  Server-composed view, with dynamic client-side features §  Keep doing context-aware XSS protection on the server <script src=“knockout-2.3.0.js"></script> <div data-bind="x:alert(1)" /> <script> ko.applyBindings(); </script> KNOCKOUT.JS EXAMPLE https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 36. Server-Side Template Composition 36 §  Traditional web back end with JS MVC front end §  Server-composed view, with dynamic client-side features §  Keep doing context-aware XSS protection on the server <script src=“knockout-2.3.0.js"></script> <div data-bind="x:alert(1)" /> <script> ko.applyBindings(); </script> KNOCKOUT.JS EXAMPLE https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 37. Server-Side Template Composition 37 §  Traditional web back end with JS MVC front end §  Server-composed view, with dynamic client-side features §  Keep doing context-aware XSS protection on the server §  JavaScript MVC frameworks change how the DOM works <graph class="visitor-graph"> <axis position="left"></axis> <axis position="bottom"></axis> <line name="typical-week" line-data="model.series.typicalWeek"></line> <line name="this-week" line-data="model.series.thisWeek"></line> <line name="last-week" line-data="model.series.lastWeek"></line> </graph> EXTENDING THE DOM
  • 38. Server-Side Template Composition 38 §  Traditional web back end with JS MVC front end §  Server-composed view, with dynamic client-side features §  Keep doing context-aware XSS protection on the server §  JavaScript MVC frameworks change how the DOM works §  Extensions through elements, attributes, etc. §  New interfaces §  Often in combination with templating §  This seems problematic …
  • 39. Mustache Security {{ }} 39 §  Project dedicated to JS MVC security pitfalls §  Assuming there is an injection vector §  Assuming there is conventional XSS filtering in place §  What can an attacker do? §  New behavior often breaks existing security assumptions §  Bypass currently used security mechanisms §  Script injection possible whenever a data attribute is allowed https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 40. Mustache Security Examples 40 https://code.google.com/p/mustache-security/ (Mario Heiderich) <script src=“jquery-1.7.1.min.js"></script> <script src=“kendo.all.min.js"></script> <div id="x"># alert(1) #</div> <script> var template = kendo.template($("#x").html()); var tasks = [{ id: 1}]; var dataSource = new kendo.data.DataSource({ data: tasks }); dataSource.bind("change", function(e) { var html = kendo.render(template, this.view()); }); dataSource.read(); </script> KENDOUI EXAMPLE
  • 41. Mustache Security Examples 41 https://code.google.com/p/mustache-security/ (Mario Heiderich) <script src=“jquery-1.7.1.min.js"></script> <script src=“kendo.all.min.js"></script> <div id="x"># alert(1) #</div> <script> var template = kendo.template($("#x").html()); var tasks = [{ id: 1}]; var dataSource = new kendo.data.DataSource({ data: tasks }); dataSource.bind("change", function(e) { var html = kendo.render(template, this.view()); }); dataSource.read(); </script> KENDOUI EXAMPLE
  • 42. Mustache Security Examples 42 https://code.google.com/p/mustache-security/ (Mario Heiderich) <script src=“angular1.1.5.min.js"></script> <div class="ng-app"> {{constructor.constructor('alert(1)')()}} </div> ANGULARJS EXAMPLE (< 1.2)
  • 43. Mustache Security Examples 43 https://code.google.com/p/mustache-security/ (Mario Heiderich) <script src=“angular1.1.5.min.js"></script> <div class="ng-app"> {{constructor.constructor('alert(1)')()}} </div> ANGULARJS EXAMPLE (< 1.2)
  • 44. Separating Front End and Back End 44 §  Beware of server-side composition of templates §  Generally a bad idea, because of dynamic behavior §  If you must do this, AngularJS 1.2+ enforces quite a good sandbox §  Separating the front end from the back end §  Server provides client-side application as static files §  Server offers data through a well-designed API §  Client-side application contains the dynamic behavior §  More security responsibilities for the client-side application
  • 45. XSS and JS MVC Frameworks 45 §  JS MVC frameworks change the underlying architecture §  Highly dynamic front ends §  Data-oriented back ends §  Difficult to match to traditional XSS countermeasures §  Two important aspects with regard to XSS §  Server-involvement in templating §  Client-side data processing
  • 46. Mitigating XSS in AngularJS 46 §  AngularJS is a client-side technology §  Generally cooperates with a RESTful back end §  RESTful back end is purely data-driven §  Applying context-sensitive output encoding §  Back end has no idea where data will be used … §  So it should be done on the client then? §  So how does it work in AngularJS?
  • 47. Example: Allowing User-Provided Images 47 <textarea ng-model=“x”></textarea> <div>{{x}}</div> ANGULARJS TEMPLATE <img src=”http://some-shop.com/coolcar.png" /> USER INPUT <div> <img src=”http://some-shop.com/coolcar.png" /> </div> GENERATED HTML
  • 48. Example: Allowing User-Provided Images 48 <textarea ng-model=“x”></textarea> <div ng-bind=”x"></div> ANGULARJS TEMPLATE <img src=”http://some-shop.com/coolcar.png" /> USER INPUT <div ng-bind=”x"> <img src=”http://some-shop.com/coolcar.png" /> </div> GENERATED HTML
  • 49. Example: Allowing User-Provided Images 49 <textarea ng-model=“x”></textarea> <div ng-bind-html=”x"></div> ANGULARJS TEMPLATE <img src=”http://some-shop.com/coolcar.png" /> USER INPUT Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context. GENERATED HTML
  • 53. And you Find This Little Gem 53
  • 54. Example: Allowing User-Provided Images 54 <textarea ng-model=“x”></textarea> <div ng-bind-html=”x | sanitize"></div> ANGULARJS TEMPLATE <img src=”http://some-shop.com/coolcar.png" /> USER INPUT GENERATED HTML
  • 55. Example: Allowing User-Provided Images 55 <textarea ng-model=“x”></textarea> <div ng-bind-html=”x | sanitize"></div> ANGULARJS TEMPLATE <img src=”http://some-shop.com/coolcar.png" onerror=“alert(1)” /> USER INPUT GENERATED HTML
  • 57. Strict Contextual Escaping 57 §  AngularJS tries to protect you from injection attacks §  Let it, it’s really good at it! §  ng-bind will never produce HTML <textarea ng-model=“x”></textarea> <div ng-bind=”x"></div> ANGULARJS TEMPLATE <div ng-bind=”x"> <img src=”http://some-shop.com/coolcar.png" onerror=“alert(1)” /> </div> GENERATED HTML
  • 58. Strict Contextual Escaping 58 §  AngularJS tries to protect you from injection attacks §  Let it, it’s really good at it! §  ng-bind-html can produce HTML, but not without protection <textarea ng-model=“x”></textarea> <div ng-bind-html=”x"></div> ANGULARJS TEMPLATE Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context. GENERATED HTML
  • 59. Strict Contextual Escaping 59 §  AngularJS tries to protect you from injection attacks §  Let it, it’s really good at it! §  ng-bind-html can produce HTML, but not without protection §  Enable automatic sanitization with ngSanitize §  Removes dangerous features from content
  • 60. Strict Contextual Escaping - ngSanitize 60 <textarea ng-model=“x”></textarea> <div ng-bind-html=”x"></div> ANGULARJS TEMPLATE <img src=”http://some-shop.com/coolcar.png" onerror=“alert(1)” /> USER INPUT angular.module(“test”, [“ngSanitize”])… ANGULARJS CODE GENERATED HTML <img src=”http://some-…car.png" />
  • 61. Strict Contextual Escaping 61 §  AngularJS tries to protect you from injection attacks §  Let it, it’s really good at it! §  ng-bind-html can output raw trusted HTML §  $sce.trustAsHtml() allows you to mark HTML as trusted §  Only use if you are really sure it’s trusted, and checked twice
  • 62. Strict Contextual Escaping - trustAsHtml 62
  • 63. Strict Contextual Escaping - trustAsHtml 63 <textarea ng-model=“x”></textarea> <div ng-bind-html=”x | i_really_know_my_security"></div> ANGULARJS TEMPLATE angular.module(“test”,[]) .filter("i_really_know_my_security", ['$sce', function($sce) { return function(htmlCode){ return $sce.trustAsHtml(htmlCode); } }]); ANGULARJS CODE
  • 64. Overview 64 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 65. Overview 65 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 66. Content Security Policy 66 your defenses against content injection vulnerabilities
  • 67. The Essence of CSP 67 §  CSP reduces the harm of content injection vulnerabilities §  By telling the client where resources should be loaded from §  By disabling “dangerous features” by default §  Policy is delivered as an HTTP header by the server §  Compatible browsers will enforce the policy on the response §  A policy consists of a set of directives §  Each directive controls a different kind of resource
  • 68. CSP Example 68 Content-Security-Policy: default-src 'self'; img-src *; object-src media1.some-shop.com media2.some-shop.com *.cdn.some-shop.com; script-src trustedscripts.some-shop.com EXAMPLE POLICY
  • 69. How CSP Started … 69 §  CSP started as a research paper by the Mozilla team §  Aim to give administrator control over appearance of site §  Aim to give users some confidence where data is sent to §  Even in the presence of an attacker that controls content §  Policy consists of 9 URI directives giving control over: §  Source of fonts, images, media, object, script, styles, frames §  Source of ancestor frames §  Destination of XHR requests
  • 70. And what CSP Is Now 70 §  CSP has been well received, and evolved quickly §  Addition of plugin types, sandbox, child contexts, form destinations §  Additional spec adds UI Security Directives §  Deprecates X-FRAME-OPTIONS header §  Additional features to overcome implementation hurdles §  Widely supported by browsers §  Chrome makes CSP mandatory for its components §  Browser extensions and packaged apps
  • 71. A Selective View on CSP 71 §  By default, CSP will: §  Prevent resources from being loaded from non-whitelisted locations §  default-src §  Specifies the default sources of all content §  Can be overwritten with more specific directives for each type §  img-src §  Specifies the sources of images §  font-src, media-src, object-src, …
  • 72. A Selective View on CSP 72 §  By default, CSP will: §  Prevent resources from being loaded from non-whitelisted locations §  Inline content from being executed §  The use of eval() §  What is considered inline content? §  Script blocks embedded in HTML §  Event handlers that are added as an HTML attribute §  Style blocks embedded in HTML §  Style info added with the style attribute
  • 73. A Selective View on CSP 73 §  By default, CSP will: §  Prevent resources from being loaded from non-whitelisted locations §  Inline content from being executed §  The use of eval() §  What is considered inline content? §  Script blocks embedded in HTML §  Event handlers that are added as an HTML attribute §  Style blocks embedded in HTML §  Style info added with the style attribute WAIT … WHAT?
  • 74. Examples of Inline Content Problems 74 <script> function run() { alert(’booh!'); } </script> <a href="#" onclick="run()">…</a> INLINE SCRIPT
  • 75. Examples of Inline Content Problems 75 <script> function run() { alert(’booh!'); } </script> <a href="#" onclick="run()">…</a> INLINE SCRIPT
  • 76. Examples of Inline Content Problems 76 <script src="myscript.js"></script> <a href="#" id="myLink">...</a> EXTERNALIZED SCRIPT function run() { alert('booh!'); } document.addEventListener('DOMContentReady', function () { document.getElementById('myLink') .addEventListener('click', run); }); EXTERNALIZED SCRIPT
  • 77. Lifting Content Restrictions in CSP 77 §  script-src and style-src support the lifting of restrictions §  By specifying ‘unsafe-inline’ and ‘unsafe-eval’ §  Not recommended, as this renders protection useless §  CSP 1.1 supports nonces and hashes §  Inline script and style blocks can be allowed Content-Security-Policy: script-src ‘self’ ‘nonce-RANDOM’; EXAMPLE POLICY WITH A NONCE <script nonce=“RANDOM”>…</script> EXAMPLE USE OF A NONCE
  • 78. Lifting Content Restrictions in CSP 78 §  script-src and style-src support the lifting of restrictions §  By specifying ‘unsafe-inline’ and ‘unsafe-eval’ §  Not recommended, as this renders protection useless §  CSP 1.1 supports nonces and hashes §  Inline script and style blocks can be allowed Content-Security-Policy: script-src ‘self’ ‘nonce-a8qzj1r’; EXAMPLE POLICY WITH A NONCE <script nonce=“a8qzj1r”>…</script> EXAMPLE USE OF A NONCE
  • 79. CSP Examples 79 Goal: Load no external resources Content-Security-Policy: default-src ‘self’; EXAMPLE POLICY Goal: Load all content over HTTPS Content-Security-Policy: default-src https: ‘unsafe-inline’ ‘unsafe-eval’; EXAMPLE POLICY
  • 80. CSP Violation Reports 80 §  CSP can report violations back to the resource server §  Allows for fine-tuning of the CSP policy §  Gives insights in actual attacks §  Enabled by using the report-uri directive §  Points to a handler on the server that can process reports Content-Security-Policy: default-src 'self'; report-uri http://some-shop.com/csp-report.cgi EXAMPLE POLICY
  • 81. CSP Violation Report Example 81 { "csp-report": { "document-uri": "http://some-shop.com/page.html", "referrer": "http://attacker.com/haxor.html", "blocked-uri": "http://attacker.com/image.png", "violated-directive": "default-src 'self'", "effective-directive": "img-src", "original-policy": "default-src 'self'; report-uri http://some-shop.com/csp-report.cgi" } } EXAMPLE VIOLATION REPORT
  • 82. CSP and JS MVC Frameworks 82 §  Default behavior of MVC frameworks is not CSP compatible §  Dependent on string-to-code functionality §  Requires unsafe-eval in CSP, which kind of misses the point
  • 83. CSP and JS MVC Frameworks 83 §  Default behavior of MVC frameworks is not CSP compatible §  Dependent on string-to-code functionality §  Requires unsafe-eval in CSP, which kind of misses the point §  AngularJS offers a special CSP mode §  Simply specify ng-csp alongside your app §  Include one tiny stylesheet for CSP compliance <html ng-app ng-csp> … </html> CSP-COMPLIANT ANGULARJS
  • 84. AngularJS and CSP 84 §  So CSP prevents inline scripts from running … <html ng-app ng-csp> <body ng-controller="MyController"> <h1 onclick="alert(0)">Click me</h1> <h1 ng-click="$event.view.alert(1)">Click me</h1> <h1 ng-mouseover= "$event.target.ownerDocument.defaultView.alert(2)”> Hover me </h1> </body> </html> INLINE CODE IN ANGULARJS https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 85. AngularJS and CSP 85 §  So CSP prevents inline scripts from running … <html ng-app ng-csp> <body ng-controller="MyController"> <h1 onclick="alert(0)">Click me</h1> <h1 ng-click="$event.view.alert(1)">Click me</h1> <h1 ng-mouseover= "$event.target.ownerDocument.defaultView.alert(2)”> Hover me </h1> </body> </html> INLINE CODE IN ANGULARJS https://code.google.com/p/mustache-security/ (Mario Heiderich) Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' http://ajax.googleapis.com 'nonce-bleh'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
  • 86. AngularJS and CSP 86 §  So CSP prevents inline scripts from running … <html ng-app ng-csp> <body ng-controller="MyController"> <h1 onclick="alert(0)">Click me</h1> <h1 ng-click="$event.view.alert(1)">Click me</h1> <h1 ng-mouseover= "$event.target.ownerDocument.defaultView.alert(2)”> Hover me </h1> </body> </html> INLINE CODE IN ANGULARJS https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 87. AngularJS and CSP 87 §  So CSP prevents inline scripts from running … <html ng-app ng-csp> <body ng-controller="MyController"> <h1 onclick="alert(0)">Click me</h1> <h1 ng-click="$event.view.alert(1)">Click me</h1> <h1 ng-mouseover= "$event.target.ownerDocument.defaultView.alert(2)”> Hover me </h1> </body> </html> INLINE CODE IN ANGULARJS https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 88. AngularJS and CSP 88 §  So how does angular process event handlers? §  Parse ‘ng’-attributes §  Create anonymous functions, connected with events §  Wait for event handler to fire §  Technically, not inline, and no eval() §  CSP 1.2.x has a strong sandbox §  No more references to dangerous objects (e.g. window) $element.onclick = function($event) { $event[‘view’][‘alert’](‘1’) } https://code.google.com/p/mustache-security/ (Mario Heiderich)
  • 89. Overview 89 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 90. Overview 90 §  Cross-Site Request Forgery §  Technicalities and common countermeasures §  Mitigating CSRF in AngularJS applications §  Cross-Site Scripting §  Technicalities and common countermeasures §  XSS and JS MVC frameworks §  Content Security Policy §  CSP as a second line of defense §  Compatibility of AngularJS with CSP
  • 91. Action Points for Tomorrow 91 1.  Check whether your APIs are vulnerable to CSRF attacks §  Enable CSRF mitigation through transparent tokens 2.  Make sure you refrain from server-side templating §  Let your AngularJS application deal with templating and security §  Communicate with data-driven APIs §  Use a proxy to transform existing endpoints into such APIs §  Enable CSRF mitigation through transparent tokens 3.  Look into deploying CSP §  Start with a small application, with little third-party dependencies §  Use the reporting feature to dry-run a policy before deploying §  Share your findings!
  • 92. Building Secure Single Page Applications 92 §  Single day training at the OWASP AppSec.eu conference §  Covers various front end and back end security topics §  Including the topics from this evening in more depth §  Hands-on sessions using AngularJS and Express https://2015.appsec.eu/trainings
  • 93. Securing your AngularJS Application Philippe De Ryck philippe.deryck@cs.kuleuven.be /in/philippederyck https://distrinet.cs.kuleuven.be/people/philippe