SlideShare a Scribd company logo
How do JavaScript frameworks impact
the security of applications?
Ksenia Peguero
• Current: Sr. Research Engineer
at Synopsys, part of the
Security Research Lab
• Prior: Principle Consultant at
Cigital/Synopsys
• PhD candidate at GWU
• Mother
• @KseniaDmitrieva
whoami
Language popularity by open pull request
according the Octoverse report from 2014 to
2018:
• JavaScript has been the leading programming
language for the last 5 years
• JavaScript is used for web applications on
client-side and server-side, in mobile
applications, desktop applications and IoT
software.
Why JavaScipt?
https://octoverse.github.com/projects#languages
State of the Client-Side JavaScript Field Today
• Client-side: over 50 frameworks, according to the
https://jsreport.io/
• Angular, React, Vue
• Server-side: over 40 frameworks, according to
http://nodeframework.com/
• Express, Koa, Sails
• Full-stack frameworks
• Meteor, Aurelia, Derby, MEAN.js
• Desktop frameworks
• Electron
• Mobile frameworks
• Phonegap, Cordova
How many frameworks are there?
• Frameworks provide functionality, easiness of prototyping and development, performance…
Hm,… security, anyone?
• Following the “shift-left” paradigm in software security, we should not only identify and fix
vulnerabilities earlier in the software development lifecycle, but also prevent them earlier.
• Questions:
• Does the security of a framework help to make applications more secure?
• Does building security controls into a framework result in “shifting-left” the security of the
application?
What is there in the framework for security?
• A vulnerability may be mitigated at the following levels in
relation to the framework:
• L0 - No mitigation in place. Baseline – no protection
• L1 - Custom function. A security control written by developers
• L2 - An external library that provides a security control
• L3 - A framework plugin. A third-party code used by
developers which tightly integrates with the framework
• L4 - Built-in mitigation control implemented in the framework
as a function or feature
Levels of Vulnerability Mitigation
proposed by John Steven
Developer code
Framework
3rd party library
function sanitize() {}
plugin
L1
L2
L3
L4
• L1 - Custom function: developer
implementation
• L2 - An external library:
ESAPI (The OWASP Enterprise Security API) –
a security control library
https://github.com/ESAPI/esapi-java-legacy
• L3 - A framework plugin:
the csurf plugin for Express
https://www.npmjs.com/package/csurf
• L4 - Built-in mitigation control:
Spring Security
https://spring.io/projects/spring-security
Mitigation Levels Examples
function cors (res) {
res.set({
'Access-Control-Allow-Origin': '*’,
'Access-Control-Allow-Headers': 'Origin, X-Requested-With,
Content-Type, Accept’
})
return res
}
https://xkcd.com/221/
The closer the mitigation is located to the framework itself,
the fewer vulnerabilities the code will have.
Hypothesis
FrameworkDeveloper code
Give me the data!
• XSS is “a type of injection, in which malicious scripts are injected into otherwise benign and trusted
websites.” (OWASP)
• Common protections:
• Output encoding
• Input validation
• Sanitization
• Special case: need to allow users to use some HTML, but not malicious JavaScript, for example, blog posts,
marketing letters, CMS.
• How to implement: display raw HTML and let the browser render it.
• How to protect from XSS: only allow a safe subset of HTML (sanitizing the “bad” HTML or using alternative
markup languages like Markdown)
Case Study 1: XSS
• Use case: the application needs to display user input that contains HTML markup
• Application Selection Criteria:
• Application type: blog or CMS
• Full-stack JavaScript applications
• Template engines: Jade/Pug, EJS, AngularJS
• Filters:
• last commit no later than 2013
• at least 1 star
• the language is JavaScript, HTML, CSS
Data Selection for XSS (2016)
https://insights.bookbub.com/creative-blog-post-ideas-authors/
Total of 170 projects:
• 65 Jade/Pug
• 54 EJS
• 51 AngularJS
Resulting Dataset
• Jade/Pug:
• Escaping: curly braces, equals sign for tags
• Interpolation: bang-sign, no sanitization
• EJS:
• Escaping: special braces '<%=' and '%>'
• Interpolation: '<%-' and '%>', no sanitization
• AngularJS:
• Escaping: contextually-aware escaping with double curly braces
• Interpolation: safe subset with 'ng-bind-html',
trustAsHtml() for raw HTML interpolation
Escaping and Interpolation in Frameworks
h1=title
p {article.name}
p!=article.content
div !{post.body}
<%=article.title%>
<%-article.body%>
<a href="{{post.url}}">
{{post.title}} </a>
<p ng-bind-html=
"post.description"></p>
Analysis Pipeline
Jade/Pug
Extended pug-lexer
and pug-parser
EJS
Extended EJS core
project, custom analyzer
AngularJS
ESLint with a custom rule
Download project
info and template files
from GitHub
Run parser and analyzer
for each template engine
Perform manual review Perform statistical
analysis of the results
Case Study 1: Results
Mitigation Levels:
L1 - Custom function
L2 - An external library
L3 - A framework plugin
L4 - Built-in mitigation control
Template
engine
Number of
projects
Number of
vulnerabilities
Number of
vulnerable
projects
% of vulnerable
projects
Mitigation level
Jade/Pug 65 72 25 38% L1 or L2
EJS 54 96 23 43% L1 or L2
AngularJS 51 12 6 12% L4
Percentage of applications vulnerable to XSS
• What if AngularJS developers are just better / smarter / more experienced than developers
writing Jade/Pug and EJS?
• We use ANOVA statistical analysis to verify our results against other factors
Confounding Variables Analysis for XSS
Criteria P-value
Developer’s overall experience 0.319279
Developer’s JavaScript experience 0.132049
Project size 0.431335
Project popularity (stars) 0.200649
Project reuse (forks) 0.211615
Template engine 0.001021
The statistically significant difference is shown by a p-value < 0.05. The choice of a
template engine is the only factor affecting the number of vulnerabilities.
Hypothesis proved (for XSS): the closer the mitigation is located to the framework itself,
the fewer vulnerabilities the code will have
value < 0.05
CSRF - “an attack that forces an end user to execute unwanted actions on a web
application in which they're currently authenticated” (OWASP)
Protection methods:
• Server-Side:
• CSRF tokens
 In POST parameters
 Double-submit cookie
• Two-factor authentication
• Not using session cookies:
• JWT
• Using web socket session
Case Study 2: CSRF
• Client-side:
• Same-site cookies
• White-listing
expected origins
• Allowed referrer lists
https://linuxsecurityblog.com/2016/02/11/defending-against-csrf-attacks/
Use case: authenticated users call sensitive functionality that change the server state
Application Selection Criteria:
• Application type:
• Blog
• CMS
• E-commerce
• REST API
• JavaScript server-side applications
• Frameworks: Express, Koa, Hapi, Sails, Meteor*
Selection goal:
• 100 applications per framework
Data Selection for CSRF (2018)
http://leanport.com/effective-ways-to-improve-e-commerce-marketing/
Total of 364 projects
Resulting Dataset
Framework Blog CMS E-commerce REST API Total
Express 29 35 45 0 109
Koa 68 26 6 0 100
Hapi 26 3 9 10 48
Sails 72 20 15 0 107
Express:
• Plugins csurf L3
Koa:
• Plugin koa-csrf L3
Hapi:
• Plugin crumb L3
Sails:
• Framework configuration L4
Meteor:
• Framework architecture L?
CSRF Protection in Frameworks
const express = require('express');
const csrf = require('csurf');
const cookieParser = require('cookie-parser');
const app = express();
app.use(cookieParser());
app.use(csrf({cookie: true}));
Express
const Koa = require('koa');
const session = require('koa-session');
const CSRF = require('koa-csrf');
const app = new Koa();
app.use(session(app));
app.use(new CSRF());
Koa
const Hapi = require('hapi');
const Crumb = require('crumb');
const server = new Hapi.Server({port: 8000});
(async () => {
await server.register({
plugin: Crumb,
options: {restful: true}
});
...
Hapi
module.exports.csrf = {
csrf.grantTokenViaAjax: true,
csrf.origin: 'example.com'
}
Sails
Express:
• Plugins csurf L3
Koa:
• Plugin koa-csrf L3
Hapi:
• Plugin crumb L3
Sails:
• Framework configuration L4
Meteor:
• Framework architecture L?
CSRF Protection in Frameworks
A CSRF attack depends on a session being maintained in a cookie. If there is no cookie,
the attack is not possible.
Meteor:
• Meteor uses custom Distributed Data Protocol (DDP) for client-server
communication
• DDP runs on WebSockets instead of HTTP
• A session is maintained via a long-lived WebSocket connection
• A third party cannot send a forged request over an established
WebSocket connection
JSON Web Token (JWT):
• Developed as access tokens, but used as session tokens
• Not stored in cookies, but transmitted in HTTP headers, which are not added to cross-origin
requests by the browser
• Have other limitations, but do protect from CSRF
Special Case: Meteor and JWT
• A vulnerability may be mitigated at the following levels in relation to
the framework:
• L0 - No mitigation in place. Baseline – no protection
• L1 - Custom function. A security control written by developers
• L2 - An external library that provides a security control
• L3 - A framework plugin. A third-party code used by developers which
tightly integrates with the framework
• L4 - Built-in mitigation control implemented in the framework as a
function or feature
• L5 – Architecture level mitigation control. A framework is
designed in a way that makes the attack impossible.
Levels of Vulnerability Mitigation
Developer code
Framework
3rd party library
function sanitize() {}
plugin
L1
L2
L3
L4
Framework design/platformL5
The closer the mitigation is located to the framework itself,
the fewer vulnerabilities the code will have.
Hypothesis
FrameworkDeveloper code
Does it work for
CSRF?
CSRF plugins:
csurf, csrf, alt-XSRF,
koa-csrf, crumb, lusca
Sails configuration
JWT plugins
Download project
from GitHub
Run ESLint with
custom rules
Perform manual review Perform statistical
analysis of the results
Analysis Pipeline
Framework Number of
projects
CSRF
protection
JWT Total
protected
% of
protected
projects
Mitigation
level
Express 109 6 9 15 14% L3
Koa 100 6 14 19* 19% L3
Hapi 48 0 17 17 35% L3
Sails 107 7 8 15 14% L4
Mitigation Levels:
L1 - Custom function
L2 - An external library
L3 - A framework plugin
L4 - Built-in mitigation control
Percentage of applications protected from CSRF
Case Study 2: Results
Results of confounding variables analysis using ANOVA statistical tests
Criteria P-value
Developer’s overall experience 0.165714
Developer’s JavaScript experience 0.161450
Project size 0.263872
Project popularity (stars) 0.411852
Project reuse (forks) 0.513946
Framework 0.507734
The statistically significant difference is shown by a p-value < 0.05. However, none of the calculated
p-values are smaller than 0.05. Thus, none of the confounding variables show a correlation.
For CSRF, the hypothesis is not proved. There is no correlation between the level of CSRF
mitigation and the presence of the CSRF of vulnerability in the application, except for L5 (Meteor).
Confounding Variables Analysis for CSRF
• Compare the percentage of protected projects by mitigation level/framework:
Why?
• L4 protection in Angular is enabled by default
• L4 protection in Sails is disabled by default
 Secure defaults are as important as the implementation levels of security controls
Comparing XSS and CSRF Results
Recommendations to the framework developers and maintainers:
 Implementing security controls as third-party plugins does not ensure secure applications
 Other solutions:
 Processes: secure coding guidelines, training
 Secure SDLC: secure code review, linting rules on every build, static analysis, penetration testing
 Instead, build security controls into the framework
 Ensure that the default settings are secure and that the security control is enabled
 When possible, design a framework in a way that eliminates the possibility of the
vulnerability at the architecture level
Conclusion
Ksenia Peguero
ksenia@synopsys.com
Twitter: @KseniaDmitrieva
https://www.synopsys.com/software
Thank You!

More Related Content

What's hot (20)

PPT
Top Ten Web Application Defenses v12
Jim Manico
 
PPT
Top Ten Proactive Web Security Controls v5
Jim Manico
 
PPTX
Cross Site Scripting (XSS) Defense with Java
Jim Manico
 
PDF
Java Web Application Security - Utah JUG 2011
Matt Raible
 
PPTX
Access Control Pitfalls v2
Jim Manico
 
PPT
Ajax Security
Roberto Suggi Liverani
 
PPTX
Geecon 2017 Anatomy of Java Vulnerabilities
Steve Poole
 
PPTX
Dzhengis 93098 ajax - security
dzhengo44
 
PPT
The Anatomy of Java Vulnerabilities (Devoxx UK 2017)
Steve Poole
 
DOC
Santosh_Resume_Java
SANTOSH PATTNAIK
 
PPTX
Java ee 8 + security overview
Rudy De Busscher
 
PDF
Java Web Application Security - Jazoon 2011
Matt Raible
 
PPTX
Octopus framework; Permission based security framework for Java EE
Rudy De Busscher
 
PPT
Java EE and Spring Side-by-Side
Reza Rahman
 
PDF
Breaking Bad CSP
Lukas Weichselbaum
 
PDF
Java EE 8: On the Horizon
Josh Juneau
 
PDF
Beyond OWASP Top 10 - Hack In Paris 2017
Aaron Hnatiw
 
PPT
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
Brian Huff
 
PDF
API SECURITY
Tubagus Rizky Dharmawan
 
PDF
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Top Ten Web Application Defenses v12
Jim Manico
 
Top Ten Proactive Web Security Controls v5
Jim Manico
 
Cross Site Scripting (XSS) Defense with Java
Jim Manico
 
Java Web Application Security - Utah JUG 2011
Matt Raible
 
Access Control Pitfalls v2
Jim Manico
 
Ajax Security
Roberto Suggi Liverani
 
Geecon 2017 Anatomy of Java Vulnerabilities
Steve Poole
 
Dzhengis 93098 ajax - security
dzhengo44
 
The Anatomy of Java Vulnerabilities (Devoxx UK 2017)
Steve Poole
 
Santosh_Resume_Java
SANTOSH PATTNAIK
 
Java ee 8 + security overview
Rudy De Busscher
 
Java Web Application Security - Jazoon 2011
Matt Raible
 
Octopus framework; Permission based security framework for Java EE
Rudy De Busscher
 
Java EE and Spring Side-by-Side
Reza Rahman
 
Breaking Bad CSP
Lukas Weichselbaum
 
Java EE 8: On the Horizon
Josh Juneau
 
Beyond OWASP Top 10 - Hack In Paris 2017
Aaron Hnatiw
 
OWASP Top 10 Security Vulnerabilities, and Securing them with Oracle ADF
Brian Huff
 
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 

Similar to How do JavaScript frameworks impact the security of applications? (20)

PDF
OWASP SF - Reviewing Modern JavaScript Applications
Lewis Ardern
 
PDF
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
Lewis Ardern
 
PDF
Prominent Back-end frameworks to consider in 2022!
Shelly Megan
 
PDF
Bridging The Cloud and Application Security Gaps Meetup 15102024
lior mazor
 
PPT
Code Quality - Security
sedukull
 
PPTX
Ruby on Rails Penetration Testing
3S Labs
 
PDF
Apache Drill (ver. 0.2)
Camuel Gilyadov
 
PPTX
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Christian Heindel
 
PDF
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
Philippe Gamache
 
PDF
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
Philippe Gamache
 
PDF
End-to-end HTML5 APIs - The Geek Gathering 2013
Alexandre Morgaut
 
PPTX
SANS_PentestHackfest_2022-PurpleTeam_Cloud_Identity.pptx
JasonOstrom1
 
DOC
mitra_resume-2
Sangamitra Reddy Katamreddy
 
PPTX
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
PPT
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
Vagner Santana
 
PDF
How-To Find Malicious Backdoors and Business Logic Vulnerabilities in Your Code
DevOps.com
 
PDF
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Denim Group
 
PPTX
Web security: Securing untrusted web content at browsers
Phú Phùng
 
PDF
Surrogate dependencies (in node js) v1.0
Dinis Cruz
 
PDF
stackconf 2024 | How to hack and defend (your) open source by Roman Zhukov.pdf
NETWAYS
 
OWASP SF - Reviewing Modern JavaScript Applications
Lewis Ardern
 
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
Lewis Ardern
 
Prominent Back-end frameworks to consider in 2022!
Shelly Megan
 
Bridging The Cloud and Application Security Gaps Meetup 15102024
lior mazor
 
Code Quality - Security
sedukull
 
Ruby on Rails Penetration Testing
3S Labs
 
Apache Drill (ver. 0.2)
Camuel Gilyadov
 
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Christian Heindel
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
Philippe Gamache
 
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
Philippe Gamache
 
End-to-end HTML5 APIs - The Geek Gathering 2013
Alexandre Morgaut
 
SANS_PentestHackfest_2022-PurpleTeam_Cloud_Identity.pptx
JasonOstrom1
 
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
Vagner Santana
 
How-To Find Malicious Backdoors and Business Logic Vulnerabilities in Your Code
DevOps.com
 
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Denim Group
 
Web security: Securing untrusted web content at browsers
Phú Phùng
 
Surrogate dependencies (in node js) v1.0
Dinis Cruz
 
stackconf 2024 | How to hack and defend (your) open source by Roman Zhukov.pdf
NETWAYS
 
Ad

Recently uploaded (20)

PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PPTX
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Ad

How do JavaScript frameworks impact the security of applications?

  • 1. How do JavaScript frameworks impact the security of applications? Ksenia Peguero
  • 2. • Current: Sr. Research Engineer at Synopsys, part of the Security Research Lab • Prior: Principle Consultant at Cigital/Synopsys • PhD candidate at GWU • Mother • @KseniaDmitrieva whoami
  • 3. Language popularity by open pull request according the Octoverse report from 2014 to 2018: • JavaScript has been the leading programming language for the last 5 years • JavaScript is used for web applications on client-side and server-side, in mobile applications, desktop applications and IoT software. Why JavaScipt? https://octoverse.github.com/projects#languages
  • 4. State of the Client-Side JavaScript Field Today
  • 5. • Client-side: over 50 frameworks, according to the https://jsreport.io/ • Angular, React, Vue • Server-side: over 40 frameworks, according to http://nodeframework.com/ • Express, Koa, Sails • Full-stack frameworks • Meteor, Aurelia, Derby, MEAN.js • Desktop frameworks • Electron • Mobile frameworks • Phonegap, Cordova How many frameworks are there?
  • 6. • Frameworks provide functionality, easiness of prototyping and development, performance… Hm,… security, anyone? • Following the “shift-left” paradigm in software security, we should not only identify and fix vulnerabilities earlier in the software development lifecycle, but also prevent them earlier. • Questions: • Does the security of a framework help to make applications more secure? • Does building security controls into a framework result in “shifting-left” the security of the application? What is there in the framework for security?
  • 7. • A vulnerability may be mitigated at the following levels in relation to the framework: • L0 - No mitigation in place. Baseline – no protection • L1 - Custom function. A security control written by developers • L2 - An external library that provides a security control • L3 - A framework plugin. A third-party code used by developers which tightly integrates with the framework • L4 - Built-in mitigation control implemented in the framework as a function or feature Levels of Vulnerability Mitigation proposed by John Steven Developer code Framework 3rd party library function sanitize() {} plugin L1 L2 L3 L4
  • 8. • L1 - Custom function: developer implementation • L2 - An external library: ESAPI (The OWASP Enterprise Security API) – a security control library https://github.com/ESAPI/esapi-java-legacy • L3 - A framework plugin: the csurf plugin for Express https://www.npmjs.com/package/csurf • L4 - Built-in mitigation control: Spring Security https://spring.io/projects/spring-security Mitigation Levels Examples function cors (res) { res.set({ 'Access-Control-Allow-Origin': '*’, 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept’ }) return res } https://xkcd.com/221/
  • 9. The closer the mitigation is located to the framework itself, the fewer vulnerabilities the code will have. Hypothesis FrameworkDeveloper code Give me the data!
  • 10. • XSS is “a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites.” (OWASP) • Common protections: • Output encoding • Input validation • Sanitization • Special case: need to allow users to use some HTML, but not malicious JavaScript, for example, blog posts, marketing letters, CMS. • How to implement: display raw HTML and let the browser render it. • How to protect from XSS: only allow a safe subset of HTML (sanitizing the “bad” HTML or using alternative markup languages like Markdown) Case Study 1: XSS
  • 11. • Use case: the application needs to display user input that contains HTML markup • Application Selection Criteria: • Application type: blog or CMS • Full-stack JavaScript applications • Template engines: Jade/Pug, EJS, AngularJS • Filters: • last commit no later than 2013 • at least 1 star • the language is JavaScript, HTML, CSS Data Selection for XSS (2016) https://insights.bookbub.com/creative-blog-post-ideas-authors/
  • 12. Total of 170 projects: • 65 Jade/Pug • 54 EJS • 51 AngularJS Resulting Dataset
  • 13. • Jade/Pug: • Escaping: curly braces, equals sign for tags • Interpolation: bang-sign, no sanitization • EJS: • Escaping: special braces '<%=' and '%>' • Interpolation: '<%-' and '%>', no sanitization • AngularJS: • Escaping: contextually-aware escaping with double curly braces • Interpolation: safe subset with 'ng-bind-html', trustAsHtml() for raw HTML interpolation Escaping and Interpolation in Frameworks h1=title p {article.name} p!=article.content div !{post.body} <%=article.title%> <%-article.body%> <a href="{{post.url}}"> {{post.title}} </a> <p ng-bind-html= "post.description"></p>
  • 14. Analysis Pipeline Jade/Pug Extended pug-lexer and pug-parser EJS Extended EJS core project, custom analyzer AngularJS ESLint with a custom rule Download project info and template files from GitHub Run parser and analyzer for each template engine Perform manual review Perform statistical analysis of the results
  • 15. Case Study 1: Results Mitigation Levels: L1 - Custom function L2 - An external library L3 - A framework plugin L4 - Built-in mitigation control Template engine Number of projects Number of vulnerabilities Number of vulnerable projects % of vulnerable projects Mitigation level Jade/Pug 65 72 25 38% L1 or L2 EJS 54 96 23 43% L1 or L2 AngularJS 51 12 6 12% L4 Percentage of applications vulnerable to XSS
  • 16. • What if AngularJS developers are just better / smarter / more experienced than developers writing Jade/Pug and EJS? • We use ANOVA statistical analysis to verify our results against other factors Confounding Variables Analysis for XSS Criteria P-value Developer’s overall experience 0.319279 Developer’s JavaScript experience 0.132049 Project size 0.431335 Project popularity (stars) 0.200649 Project reuse (forks) 0.211615 Template engine 0.001021 The statistically significant difference is shown by a p-value < 0.05. The choice of a template engine is the only factor affecting the number of vulnerabilities. Hypothesis proved (for XSS): the closer the mitigation is located to the framework itself, the fewer vulnerabilities the code will have value < 0.05
  • 17. CSRF - “an attack that forces an end user to execute unwanted actions on a web application in which they're currently authenticated” (OWASP) Protection methods: • Server-Side: • CSRF tokens  In POST parameters  Double-submit cookie • Two-factor authentication • Not using session cookies: • JWT • Using web socket session Case Study 2: CSRF • Client-side: • Same-site cookies • White-listing expected origins • Allowed referrer lists https://linuxsecurityblog.com/2016/02/11/defending-against-csrf-attacks/
  • 18. Use case: authenticated users call sensitive functionality that change the server state Application Selection Criteria: • Application type: • Blog • CMS • E-commerce • REST API • JavaScript server-side applications • Frameworks: Express, Koa, Hapi, Sails, Meteor* Selection goal: • 100 applications per framework Data Selection for CSRF (2018) http://leanport.com/effective-ways-to-improve-e-commerce-marketing/
  • 19. Total of 364 projects Resulting Dataset Framework Blog CMS E-commerce REST API Total Express 29 35 45 0 109 Koa 68 26 6 0 100 Hapi 26 3 9 10 48 Sails 72 20 15 0 107
  • 20. Express: • Plugins csurf L3 Koa: • Plugin koa-csrf L3 Hapi: • Plugin crumb L3 Sails: • Framework configuration L4 Meteor: • Framework architecture L? CSRF Protection in Frameworks const express = require('express'); const csrf = require('csurf'); const cookieParser = require('cookie-parser'); const app = express(); app.use(cookieParser()); app.use(csrf({cookie: true})); Express const Koa = require('koa'); const session = require('koa-session'); const CSRF = require('koa-csrf'); const app = new Koa(); app.use(session(app)); app.use(new CSRF()); Koa
  • 21. const Hapi = require('hapi'); const Crumb = require('crumb'); const server = new Hapi.Server({port: 8000}); (async () => { await server.register({ plugin: Crumb, options: {restful: true} }); ... Hapi module.exports.csrf = { csrf.grantTokenViaAjax: true, csrf.origin: 'example.com' } Sails Express: • Plugins csurf L3 Koa: • Plugin koa-csrf L3 Hapi: • Plugin crumb L3 Sails: • Framework configuration L4 Meteor: • Framework architecture L? CSRF Protection in Frameworks
  • 22. A CSRF attack depends on a session being maintained in a cookie. If there is no cookie, the attack is not possible. Meteor: • Meteor uses custom Distributed Data Protocol (DDP) for client-server communication • DDP runs on WebSockets instead of HTTP • A session is maintained via a long-lived WebSocket connection • A third party cannot send a forged request over an established WebSocket connection JSON Web Token (JWT): • Developed as access tokens, but used as session tokens • Not stored in cookies, but transmitted in HTTP headers, which are not added to cross-origin requests by the browser • Have other limitations, but do protect from CSRF Special Case: Meteor and JWT
  • 23. • A vulnerability may be mitigated at the following levels in relation to the framework: • L0 - No mitigation in place. Baseline – no protection • L1 - Custom function. A security control written by developers • L2 - An external library that provides a security control • L3 - A framework plugin. A third-party code used by developers which tightly integrates with the framework • L4 - Built-in mitigation control implemented in the framework as a function or feature • L5 – Architecture level mitigation control. A framework is designed in a way that makes the attack impossible. Levels of Vulnerability Mitigation Developer code Framework 3rd party library function sanitize() {} plugin L1 L2 L3 L4 Framework design/platformL5
  • 24. The closer the mitigation is located to the framework itself, the fewer vulnerabilities the code will have. Hypothesis FrameworkDeveloper code Does it work for CSRF?
  • 25. CSRF plugins: csurf, csrf, alt-XSRF, koa-csrf, crumb, lusca Sails configuration JWT plugins Download project from GitHub Run ESLint with custom rules Perform manual review Perform statistical analysis of the results Analysis Pipeline
  • 26. Framework Number of projects CSRF protection JWT Total protected % of protected projects Mitigation level Express 109 6 9 15 14% L3 Koa 100 6 14 19* 19% L3 Hapi 48 0 17 17 35% L3 Sails 107 7 8 15 14% L4 Mitigation Levels: L1 - Custom function L2 - An external library L3 - A framework plugin L4 - Built-in mitigation control Percentage of applications protected from CSRF Case Study 2: Results
  • 27. Results of confounding variables analysis using ANOVA statistical tests Criteria P-value Developer’s overall experience 0.165714 Developer’s JavaScript experience 0.161450 Project size 0.263872 Project popularity (stars) 0.411852 Project reuse (forks) 0.513946 Framework 0.507734 The statistically significant difference is shown by a p-value < 0.05. However, none of the calculated p-values are smaller than 0.05. Thus, none of the confounding variables show a correlation. For CSRF, the hypothesis is not proved. There is no correlation between the level of CSRF mitigation and the presence of the CSRF of vulnerability in the application, except for L5 (Meteor). Confounding Variables Analysis for CSRF
  • 28. • Compare the percentage of protected projects by mitigation level/framework: Why? • L4 protection in Angular is enabled by default • L4 protection in Sails is disabled by default  Secure defaults are as important as the implementation levels of security controls Comparing XSS and CSRF Results
  • 29. Recommendations to the framework developers and maintainers:  Implementing security controls as third-party plugins does not ensure secure applications  Other solutions:  Processes: secure coding guidelines, training  Secure SDLC: secure code review, linting rules on every build, static analysis, penetration testing  Instead, build security controls into the framework  Ensure that the default settings are secure and that the security control is enabled  When possible, design a framework in a way that eliminates the possibility of the vulnerability at the architecture level Conclusion