SlideShare a Scribd company logo
Security
Created by Johannes Hoppe
ZielAngriffsvektoren aufzeigen.
Strategien besprechen.
Mehr nicht!
FeaturesNeue Angriffsvektoren
Ein Formular
Username:
Password:
Login
<form id="login" action="#">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">
</form>
Formaction
Username:
Password:
Login
Klick mich!
<form id="login" action="#">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">
</form>
<button type="submit" form="login" formaction="http://example.org">
Klick mich!
</button>
SVG
Presto, WebKit, Gecko und sogar Trident 9
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40">
<circle cx="20" cy="20" r="15" fill="yellow" stroke="black"/>
<circle cx="15" cy="15" r="2" fill="black" stroke="black"/>
<circle cx="25" cy="15" r="2" fill="black" stroke="black"/>
<path d="M 13 26 A 5 3 0 0 0 27 26" stroke="black" fill="none" stroke
-width="2"/>
</svg>
SVG
kann JavaScript enthalten!
Test
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="50">
<defs><style> </style></defs>
<circle cx="20" cy="20" r="15" fill="yellow" stroke="black"/>
<circle cx="15" cy="15" r="2" fill="black" stroke="black"/>
<circle cx="25" cy="15" r="2" fill="black" stroke="black"/>
<path d="M 13 26 A 5 3 0 0 0 27 26" stroke="black" fill="none" stroke
-width="2" transform="rotate(180, 20, 28)"/>
<text x="11" y="50" id="display">Test</text>
<script>
</script>
</svg>
<![CDATA[ text { font-size:6pt; } ]]>
alert(document.cookie);
document.getElementById('display').textContent = document.cookie;
2013 05-03 -  HTML5 & JavaScript Security
Business as usual
HTML5 es ist auch nicht schlimmer als HTML 4
» http://html5sec.org
XSSEingeschleuster JavaScript-Code
Oldies but Goldies
index.html?message=Daten gespeichert
index.html?message=<script>alert('XSS')</script>
<script>
var message = $.url().param('message');
if (message) {
Notifier.success(message);
}
</script>
Eval everywhere
Eval is evil
» Demo
<!-- Self-executing onFocus event via autoFocus -->
<input onfocus="alert('XSS onfocus')" autofocus>
<!-- Video OnError -->
<video><source onerror="javascript:alert('XSS onerror')"></video>
<!-- Presto only: Form surveillance -->
<form id=test onforminput=alert('XSS onforminput')>
<input>
</form>
<button form=test onformchange=alert('XSS onformchange')>X</button>
1 2 3
OWASPOpen Web Application Security Project
XSS Filter Evasion Cheat Sheet
<!-- Long UTF-8 Unicode encoding without semicolons -->
<IMG SRC="&#34&#32&#111&#110&#101&#114&#114&#111&#114&#61&#34&#97&#108&
#101&#114&#116&#40&#39&#88&#83&#83&#39&#41&#59">
» Old IE Demo
XSS Vorbeugen
1.Hier sollten dynamische
Daten niemals verwendet werden
<script> </script>
<!-- HIER -->
<div HIER="test"/>
<HIER href="test" />
<style> </style>
HIER
HIER
2.HTML escape
dynamic data
& → &amp;
< → &lt;
> → &gt;
" → &quot;
' → &apos; / &#39;
<div>HTML ESCAPE</div>
Testen?
function htmlEncode(input) {
// jquery.text == document.createTextNode
return ($('<div/>').text(input).html());
}
var saveFormat = function () {
var args = Array.prototype.slice.call(arguments);
var txt = args.shift();
$.each(args, function (i, item) {
item = htmlEncode(item);
txt = txt.replace("{" + i + "}", item);
});
return txt;
};
Testen!
describe("saveFormat", function () {
var original = '{0} - {1} - {2}';
it("should replace placeholders", function () {
var expected = 'A - B - C';
var formated = saveFormat(original, 'A', 'B', 'C');
expect(formated).toEqual(expected);
});
it("should encode injected content", function () {
var expected = 'A - &lt;b&gt;TEST&lt;/b&gt; - C';
var formated = saveFormat(original, 'A', '<b>TEST</b>', 'C');
expect(formated).toEqual(expected);
});
});
Test
finished in 0.007s
••
No try/catch
Jasmine 1.3.1 revision 1354556913
Passing2specs
saveFormat
should replace placeholders
should encode injected content
» Demo
Moment...
describe("saveFormat", function () {
var original = '<a title="{0}">Test</a>';
it("should replace quotes", function () {
var expected = '<a title="&quot;">Test</a>';
var formated = saveFormat(original, '"');
expect(formated).toEqual(expected);
});
});
Richtig testen!
finished in 0.006s
x
No try/catch
Jasmine 1.3.1 revision 1354556913
Failing1spec
1spec|1 failing
saveFormat should replace quotes.
Expected '<a title=""">Test</a>' to equal '<a
title="&quot;">Test</a>'.
Error: Expected '<a title=""">Test</a>' to equal '<a title="&quot;">Test</a>'.
at new jasmine.ExpectationResult (http://localhost:1332/examples/jasmine/lib/j
at null.toEqual (http://localhost:1332/examples/jasmine/lib/jasmine-1.3.1/jasm
at null.<anonymous> (http://localhost:1332/examples/jasmine-demo2/saveFormat.s
at jasmine.Block.execute (http://localhost:1332/examples/jasmine/lib/jasmine-1
at jasmine.Queue.next_ (http://localhost:1332/examples/jasmine/lib/jasmine-1.3
» Demo
3.Attribute escape
dynamic data
a-z A-Z 0-9 → immun
, . - _ → immun
Rest → &#xHH;
<div attr="ATTRIBUTE ESCAPE"></div>
<!-- NIEMALS ohne quotes! -->
<div attr=ATTRIBUTE ESCAPE></div>
4. DO NOTJavaScript escape
dynamic data
HTML parser runs before the JavaScript parser!
you are doing it wrong
Das hier ist Alltag
UserList.cshtml / Kendo UI Template
# if(ID != 0) { #
<a href="javascript:DialogManager.ShowPartialDialog('@Url.Action("UserM
anagement", "Management")', { userId : '#= htmlEncode(ID) #' }, {title:
'#= htmlEncode(Alias) #'})"#= htmlEncode(Alias) #</a>
# } else { #
#= htmlEncode(Alias) #
# } #
?Offensichtlich läuft beim Umgang
mit Daten etwas prinzipiell falsch!
Storage
Egal
ob Cookies
ob Session Storage
ob Local Storage
ob WebSQL
die Daten sind nicht vertrauenswürdig!
Resident XSS
richtig fies!
Vertraulichen Informationen
gehören in die SERVER-Session!
Session Storage bevorzugen!
WebSQL
SQL Injection:
Prepared Statement:
executeSql("SELECT foo FROM bar WHERE value=" + value);
executeSql("SELECT foo FROM bar WHERE value=?", [value]);
Kommunikation
Mashups!
define(['jquery', 'knockout',
'knockout.mapping', 'domReady!'], function ($, ko, mapping) {
var url ='http://search.twitter.com/search.json?q=%23xss&callback=?';
$.getJSON(url).done(function (data) {
var viewModel = mapping.fromJS(data);
ko.applyBindings(viewModel, $('#tweets').get(0));
});
});
Loading...
JSON
JSON with Padding
{"hello": "world"}
<script>
</script>
<script src="http://search.twitter.com/search.json?q=%23dnc13&callback=
foo"></script>
var foo = function(json) {
$('#output').text(JSON.stringify(json, undefined, 2));
};
foo({"hello": "world"});
» Demo
JSONP
SOP
Same origin policy → Not macht erfinderisch (JSONP)
CORS
Cross-Origin Resource Sharing → Access-Control-Allow-Origin: *
WebSockets
do what you want
JS-Recon
Shell of the Future
2013 05-03 -  HTML5 & JavaScript Security
Intranet == Internet
Danke!
2013 05-03 -  HTML5 & JavaScript Security
» Sicherheit von Web-Anwendungen

More Related Content

What's hot (20)

PDF
Speeding up Red Team engagements with carnivorall
Nullbyte Security Conference
 
PDF
Rapid HTML Prototyping with Bootstrap - Chris Griffith
UXPA International
 
PDF
spring_jiaocheng
Shilong Sang
 
PPTX
How to make your users not want to murder you
joe_mcmahon
 
PPT
PHPUG Presentation
Damon Cortesi
 
PDF
Java script programms
Mukund Gandrakota
 
PPTX
Presentation1
Victor Andreev
 
ODP
Concern of Web Application Security
Mahmud Ahsan
 
PPT
SQL Injection in PHP
Dave Ross
 
PDF
OWASP Top 10 at International PHP Conference 2014 in Berlin
Tobias Zander
 
PDF
Intro to OAuth
mfrost503
 
PDF
T1
TH Schee
 
PDF
HTML5, the open web, and what it means for you -Tech4Africa
Robert Nyman
 
PDF
파이썬 플라스크로 배우는 웹프로그래밍 #4 (ABCD)
성일 한
 
TXT
Index
antseex
 
KEY
Page Caching Resurrected
Ben Scofield
 
PDF
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
Loiane Groner
 
PDF
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
QADay
 
KEY
Bestpractices nl
Wilfred Nas
 
Speeding up Red Team engagements with carnivorall
Nullbyte Security Conference
 
Rapid HTML Prototyping with Bootstrap - Chris Griffith
UXPA International
 
spring_jiaocheng
Shilong Sang
 
How to make your users not want to murder you
joe_mcmahon
 
PHPUG Presentation
Damon Cortesi
 
Java script programms
Mukund Gandrakota
 
Presentation1
Victor Andreev
 
Concern of Web Application Security
Mahmud Ahsan
 
SQL Injection in PHP
Dave Ross
 
OWASP Top 10 at International PHP Conference 2014 in Berlin
Tobias Zander
 
Intro to OAuth
mfrost503
 
HTML5, the open web, and what it means for you -Tech4Africa
Robert Nyman
 
파이썬 플라스크로 배우는 웹프로그래밍 #4 (ABCD)
성일 한
 
Index
antseex
 
Page Caching Resurrected
Ben Scofield
 
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
Loiane Groner
 
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
QADay
 
Bestpractices nl
Wilfred Nas
 

Viewers also liked (6)

PDF
DMDW 8. Student Presentation - Groovy to MongoDB
Johannes Hoppe
 
PPTX
Ria 09 trends_and_technologies
Johannes Hoppe
 
PPTX
Ria 03 - Hello ASP.NET MVC
Johannes Hoppe
 
PDF
2013-03-23 - NoSQL Spartakiade
Johannes Hoppe
 
PDF
2013-06-24 - Software Craftsmanship with JavaScript
Johannes Hoppe
 
PDF
2011-12-13 NoSQL aus der Praxis
Johannes Hoppe
 
DMDW 8. Student Presentation - Groovy to MongoDB
Johannes Hoppe
 
Ria 09 trends_and_technologies
Johannes Hoppe
 
Ria 03 - Hello ASP.NET MVC
Johannes Hoppe
 
2013-03-23 - NoSQL Spartakiade
Johannes Hoppe
 
2013-06-24 - Software Craftsmanship with JavaScript
Johannes Hoppe
 
2011-12-13 NoSQL aus der Praxis
Johannes Hoppe
 
Ad

Similar to 2013 05-03 - HTML5 & JavaScript Security (20)

PDF
Applications secure by default
Slawomir Jasek
 
PDF
Applications secure by default
SecuRing
 
PDF
Packing it all: JavaScript module bundling from 2000 to now
Derek Willian Stavis
 
PDF
Webpack packing it all
Criciúma Dev
 
PPTX
Django Web Application Security
levigross
 
PPT
Javascript1
anas Mohtaseb
 
ODP
2009 Barcamp Nashville Web Security 101
brian_dailey
 
PDF
My app is secure... I think
Wim Godden
 
PPT
General Principles of Web Security
jemond
 
KEY
#NewMeetup Performance
Justin Cataldo
 
PDF
Evolution Of Web Security
Chris Shiflett
 
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
PPT
12-security.ppt - PHP and Arabic Language - Index
webhostingguy
 
PPT
Security.ppt
webhostingguy
 
PPSX
Introduction to Html5
www.netgains.org
 
PDF
Rails and security
Andrey Tokarchuk
 
PDF
Whatever it takes - Fixing SQLIA and XSS in the process
guest3379bd
 
DOCX
Unit 2_Blacklisting & Whitelisting User Input in Python.docx
ChatanBawankar
 
PPTX
Random numbers
Positive Hack Days
 
PDF
Reutov, yunusov, nagibin random numbers take ii
DefconRussia
 
Applications secure by default
Slawomir Jasek
 
Applications secure by default
SecuRing
 
Packing it all: JavaScript module bundling from 2000 to now
Derek Willian Stavis
 
Webpack packing it all
Criciúma Dev
 
Django Web Application Security
levigross
 
Javascript1
anas Mohtaseb
 
2009 Barcamp Nashville Web Security 101
brian_dailey
 
My app is secure... I think
Wim Godden
 
General Principles of Web Security
jemond
 
#NewMeetup Performance
Justin Cataldo
 
Evolution Of Web Security
Chris Shiflett
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
12-security.ppt - PHP and Arabic Language - Index
webhostingguy
 
Security.ppt
webhostingguy
 
Introduction to Html5
www.netgains.org
 
Rails and security
Andrey Tokarchuk
 
Whatever it takes - Fixing SQLIA and XSS in the process
guest3379bd
 
Unit 2_Blacklisting & Whitelisting User Input in Python.docx
ChatanBawankar
 
Random numbers
Positive Hack Days
 
Reutov, yunusov, nagibin random numbers take ii
DefconRussia
 
Ad

More from Johannes Hoppe (20)

PDF
2017 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
PPTX
NoSQL - Hands on
Johannes Hoppe
 
PDF
Einführung in Angular 2
Johannes Hoppe
 
PDF
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
Johannes Hoppe
 
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
PDF
2012-06-25 - MapReduce auf Azure
Johannes Hoppe
 
PDF
2013-06-15 - Software Craftsmanship mit JavaScript
Johannes Hoppe
 
PDF
2013 02-26 - Software Tests with Mongo db
Johannes Hoppe
 
PDF
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
Johannes Hoppe
 
PDF
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
Johannes Hoppe
 
PDF
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
Johannes Hoppe
 
PDF
2012-09-18 - HTML5 & WebGL
Johannes Hoppe
 
PDF
2012-09-17 - WDC12: Node.js & MongoDB
Johannes Hoppe
 
PDF
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
PDF
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
Johannes Hoppe
 
PDF
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
Johannes Hoppe
 
PDF
2012-04-12 - AOP .NET UserGroup Niederrhein
Johannes Hoppe
 
PDF
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
Johannes Hoppe
 
PDF
2012-01-31 NoSQL in .NET
Johannes Hoppe
 
PPTX
2011-06-27 - AOP - .NET User Group Rhein Neckar
Johannes Hoppe
 
2017 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
NoSQL - Hands on
Johannes Hoppe
 
Einführung in Angular 2
Johannes Hoppe
 
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
Johannes Hoppe
 
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
2012-06-25 - MapReduce auf Azure
Johannes Hoppe
 
2013-06-15 - Software Craftsmanship mit JavaScript
Johannes Hoppe
 
2013 02-26 - Software Tests with Mongo db
Johannes Hoppe
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
Johannes Hoppe
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
Johannes Hoppe
 
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
Johannes Hoppe
 
2012-09-18 - HTML5 & WebGL
Johannes Hoppe
 
2012-09-17 - WDC12: Node.js & MongoDB
Johannes Hoppe
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
Johannes Hoppe
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
Johannes Hoppe
 
2012-04-12 - AOP .NET UserGroup Niederrhein
Johannes Hoppe
 
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
Johannes Hoppe
 
2012-01-31 NoSQL in .NET
Johannes Hoppe
 
2011-06-27 - AOP - .NET User Group Rhein Neckar
Johannes Hoppe
 

Recently uploaded (20)

PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
Open Source Milvus Vector Database v 2.6
Zilliz
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
Open Source Milvus Vector Database v 2.6
Zilliz
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Kubernetes - Architecture & Components.pdf
geethak285
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 

2013 05-03 - HTML5 & JavaScript Security

  • 4. Ein Formular Username: Password: Login <form id="login" action="#"> Username: <input type="text" name="username"> Password: <input type="password" name="password"> <input type="submit" value="Login"> </form>
  • 5. Formaction Username: Password: Login Klick mich! <form id="login" action="#"> Username: <input type="text" name="username"> Password: <input type="password" name="password"> <input type="submit" value="Login"> </form> <button type="submit" form="login" formaction="http://example.org"> Klick mich! </button>
  • 6. SVG Presto, WebKit, Gecko und sogar Trident 9 <?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"> <circle cx="20" cy="20" r="15" fill="yellow" stroke="black"/> <circle cx="15" cy="15" r="2" fill="black" stroke="black"/> <circle cx="25" cy="15" r="2" fill="black" stroke="black"/> <path d="M 13 26 A 5 3 0 0 0 27 26" stroke="black" fill="none" stroke -width="2"/> </svg>
  • 7. SVG kann JavaScript enthalten! Test <?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" width="200" height="50"> <defs><style> </style></defs> <circle cx="20" cy="20" r="15" fill="yellow" stroke="black"/> <circle cx="15" cy="15" r="2" fill="black" stroke="black"/> <circle cx="25" cy="15" r="2" fill="black" stroke="black"/> <path d="M 13 26 A 5 3 0 0 0 27 26" stroke="black" fill="none" stroke -width="2" transform="rotate(180, 20, 28)"/> <text x="11" y="50" id="display">Test</text> <script> </script> </svg> <![CDATA[ text { font-size:6pt; } ]]> alert(document.cookie); document.getElementById('display').textContent = document.cookie;
  • 9. Business as usual HTML5 es ist auch nicht schlimmer als HTML 4 » http://html5sec.org
  • 11. Oldies but Goldies index.html?message=Daten gespeichert index.html?message=<script>alert('XSS')</script> <script> var message = $.url().param('message'); if (message) { Notifier.success(message); } </script>
  • 12. Eval everywhere Eval is evil » Demo <!-- Self-executing onFocus event via autoFocus --> <input onfocus="alert('XSS onfocus')" autofocus> <!-- Video OnError --> <video><source onerror="javascript:alert('XSS onerror')"></video> <!-- Presto only: Form surveillance --> <form id=test onforminput=alert('XSS onforminput')> <input> </form> <button form=test onformchange=alert('XSS onformchange')>X</button> 1 2 3
  • 13. OWASPOpen Web Application Security Project XSS Filter Evasion Cheat Sheet <!-- Long UTF-8 Unicode encoding without semicolons --> <IMG SRC="&#34&#32&#111&#110&#101&#114&#114&#111&#114&#61&#34&#97&#108& #101&#114&#116&#40&#39&#88&#83&#83&#39&#41&#59"> » Old IE Demo
  • 15. 1.Hier sollten dynamische Daten niemals verwendet werden <script> </script> <!-- HIER --> <div HIER="test"/> <HIER href="test" /> <style> </style> HIER HIER
  • 16. 2.HTML escape dynamic data & → &amp; < → &lt; > → &gt; " → &quot; ' → &apos; / &#39; <div>HTML ESCAPE</div>
  • 17. Testen? function htmlEncode(input) { // jquery.text == document.createTextNode return ($('<div/>').text(input).html()); } var saveFormat = function () { var args = Array.prototype.slice.call(arguments); var txt = args.shift(); $.each(args, function (i, item) { item = htmlEncode(item); txt = txt.replace("{" + i + "}", item); }); return txt; };
  • 18. Testen! describe("saveFormat", function () { var original = '{0} - {1} - {2}'; it("should replace placeholders", function () { var expected = 'A - B - C'; var formated = saveFormat(original, 'A', 'B', 'C'); expect(formated).toEqual(expected); }); it("should encode injected content", function () { var expected = 'A - &lt;b&gt;TEST&lt;/b&gt; - C'; var formated = saveFormat(original, 'A', '<b>TEST</b>', 'C'); expect(formated).toEqual(expected); }); });
  • 19. Test finished in 0.007s •• No try/catch Jasmine 1.3.1 revision 1354556913 Passing2specs saveFormat should replace placeholders should encode injected content » Demo
  • 20. Moment... describe("saveFormat", function () { var original = '<a title="{0}">Test</a>'; it("should replace quotes", function () { var expected = '<a title="&quot;">Test</a>'; var formated = saveFormat(original, '"'); expect(formated).toEqual(expected); }); });
  • 21. Richtig testen! finished in 0.006s x No try/catch Jasmine 1.3.1 revision 1354556913 Failing1spec 1spec|1 failing saveFormat should replace quotes. Expected '<a title=""">Test</a>' to equal '<a title="&quot;">Test</a>'. Error: Expected '<a title=""">Test</a>' to equal '<a title="&quot;">Test</a>'. at new jasmine.ExpectationResult (http://localhost:1332/examples/jasmine/lib/j at null.toEqual (http://localhost:1332/examples/jasmine/lib/jasmine-1.3.1/jasm at null.<anonymous> (http://localhost:1332/examples/jasmine-demo2/saveFormat.s at jasmine.Block.execute (http://localhost:1332/examples/jasmine/lib/jasmine-1 at jasmine.Queue.next_ (http://localhost:1332/examples/jasmine/lib/jasmine-1.3 » Demo
  • 22. 3.Attribute escape dynamic data a-z A-Z 0-9 → immun , . - _ → immun Rest → &#xHH; <div attr="ATTRIBUTE ESCAPE"></div> <!-- NIEMALS ohne quotes! --> <div attr=ATTRIBUTE ESCAPE></div>
  • 23. 4. DO NOTJavaScript escape dynamic data HTML parser runs before the JavaScript parser! you are doing it wrong
  • 24. Das hier ist Alltag UserList.cshtml / Kendo UI Template # if(ID != 0) { # <a href="javascript:DialogManager.ShowPartialDialog('@Url.Action("UserM anagement", "Management")', { userId : '#= htmlEncode(ID) #' }, {title: '#= htmlEncode(Alias) #'})"#= htmlEncode(Alias) #</a> # } else { # #= htmlEncode(Alias) # # } #
  • 25. ?Offensichtlich läuft beim Umgang mit Daten etwas prinzipiell falsch!
  • 27. Egal ob Cookies ob Session Storage ob Local Storage ob WebSQL die Daten sind nicht vertrauenswürdig!
  • 31. WebSQL SQL Injection: Prepared Statement: executeSql("SELECT foo FROM bar WHERE value=" + value); executeSql("SELECT foo FROM bar WHERE value=?", [value]);
  • 33. Mashups! define(['jquery', 'knockout', 'knockout.mapping', 'domReady!'], function ($, ko, mapping) { var url ='http://search.twitter.com/search.json?q=%23xss&callback=?'; $.getJSON(url).done(function (data) { var viewModel = mapping.fromJS(data); ko.applyBindings(viewModel, $('#tweets').get(0)); }); });
  • 35. JSON JSON with Padding {"hello": "world"} <script> </script> <script src="http://search.twitter.com/search.json?q=%23dnc13&callback= foo"></script> var foo = function(json) { $('#output').text(JSON.stringify(json, undefined, 2)); }; foo({"hello": "world"}); » Demo
  • 36. JSONP
  • 37. SOP Same origin policy → Not macht erfinderisch (JSONP) CORS Cross-Origin Resource Sharing → Access-Control-Allow-Origin: * WebSockets do what you want
  • 43. » Sicherheit von Web-Anwendungen