SlideShare a Scribd company logo
Ajax Security
DouglasCrockford
Yahoo!
javascript.crockford.com/security.ppt
Security
Thenumber 1 biggest problem with
thewholeWorld WideWeb.
Thebrowser isnot asafe
programming environment.
It isinherently insecure.
What can an attacker do if he
getssomescript into your page?
An attacker can request additional
scriptsfrom any server in theworld.
Onceit getsafoothold, it can obtain
all of thescriptsit needs.
An attacker can makerequestsof
your server.
Your server cannot detect that the
request did not originatewith your
application.
An attacker can read the
document.
Theattacker can seeeverything the
user sees.
An attacker hascontrol over the
display and can request information
from theuser.
Theuser cannot detect that the
request did not originatewith your
application.
An attacker can send information to
serversanywherein theworld.
Thebrowser doesnot prevent
any of these.
That'swhy they happen.
Theconsequencesof asuccessful
attack arehorrible.
Harm to customers. Lossof trust.
Legal liabilities.
Possiblecriminal penalties.
Thisisnot aWeb 2.0 problem.
All of theseproblemscamewith
Netscape2 in 1995.
TheTurducken Problem
• Many Languages:
HTTP, HTML, URL, CSS, JavaScript, XML,
JSON, plaintext, SQL...
• Each languagehasdifferent quoting and
commenting conventions.
• Thelanguagescan benested insideeach other.
A text that isbenign in onecontext
might bedangerousin another.
Sloppy encoding allowsinjection of
evil scripts
A SimpleAttack
http://yourdomain.com/
<script>alert("XSS");</script>
<html><body>
<p>File not found:
<script>alert("XSS");</script>
</p></body></html>
• Thescript runswith theauthority of your site.
A SimpleAttack
http://yourdomain.com/
<script>alert("XSS");</script>
<html><body>
<p>File not found:
&lt;script>alert("XSS");&lt;/script>
</p></body></html>
• Proper escapement providessomesafety.
Another Example
• Bad text
" + alert("XSS") + "
• Bad encoding
{"json": "" + alert("XSS") + ""}
• Good encoding
{"json": "" + alert("XSS") + ""}
Coding hygieneiscritical for
avoiding turducken attacks.
Usegood encoders. json.org/json2.js
Do not usesimpleconcatenation.
Never trust thebrowser.
Validateall input.
CrossSiteDataAccess
It isextremely useful to
obtain datafrom other
sitesand mash it up.
SameOrigin Policy
Preventsuseful things.
Allowsdangerousthings.
Script Tag Hack
• Scripts(strangely) areexempt from Same
Origin Policy.
• A dynamic script tag can makeaGET request
from aserver.
receiver(jsontext);
• Extremely dangerous. It isimpossibleto
assurethat theserver did not send an evil
script.
JavaScript'sGlobal Object
Theroot causeof XSSattacks.
All scriptsrun with thesame
authority.
JavaScript isan insecure
language.
TheES4 Proposal iseven worse.
It should beabandoned.
Document Object Model
All nodesarelinked to all other nodes
and to thenetwork.
Cookies
Ambient authority leadsto confusion
and impersonation (XSRF)
Remedy: Crumbs
An explicit secret should besent with
theambient cookie.
FrustratesXSRF attacks.
Not effectiveagainst XSSattacks.
Excellent CodeQuality
If codeisclean and readable, it isless
likely to contain insecurities.
JSLint
• JSLint definesaprofessional subset of
JavaScript.
• It imposesaprogramming disciplinethat
makesmemuch moreconfident in adynamic,
loosely-typed environment.
http://www.JSLint.com/
Warning!
JSLint will hurt your
feelings.
If theweb asbeen totally screwed up
from thebeginning, why should we
worry about it now?
1. Escalating legal penalties
2. Mashups
3. Competition
Mashups
Themost interesting innovation in
softwaredevelopment in 20 years.
Mashupsareinsecure.
Mashupsmust not haveaccessto
any confidential information.
If thereisscript from two or more
sources, theapplication isnot secure.
Period.
Advertising isamashup.
Competition to displacetheweb.
Silverlight.
AIR.
JavaFX.
That wouldn't betheend of the
world.
It would just betheend of theWWW.
A ThreeProng Strategy to
Fix theWeb
1. SafeJavaScript subsets.
2. Small browser improvements.
3. Massivebrowser improvements.
Thiscould takeawhile, so weshould proceed on
all threeimmediately.
1. SafeJavaScript Subsets.
Theeasiest way to improve
JavaScript isto makeit smaller.
ADsafe
• A JSLint option.
• It definesasafeHTML/JavaScript subset.
• Removesfrom JavaScript all featuresthat are
unsafeor suspect.
• Allowsforeign adsand widgetsto safely
interact.
ADsafe
• No global variablesor functionsmay be
defined.
• No global variablesor functionscan be
accessed except theADSAFE object.
• The[] subscript operator may not beused.
• Thesewordscannot beused: apply call
callee caller constructor eval
new prototype this watch
• Wordsstarting with _ cannot beused.
Dangers
• Theremay still beundiscovered weaknessesin
ECMAScript and itsmany implementations.
• Browser implementationsarechanging,
introducing new weaknesses.
• TheDOM wrappersmust beflawless.
• Wearestill subject to XSSattacks.
2. Add SimpleFeatures
to theBrowsers.
Even simpleimprovementscan takea
long timeto distribute.
JSONRequest for safedata
interchange.
Vats
Communicating computational containment vessels
HTML ProvidesNo Modules
• It wasconceived to beadocument format.
• Weareusing it asan application format.
• Applicationsrequiresmodules.
• Modulesprotect their contents.
• Modulescommunicateby exposing clean
interfaces.
Vats
• Adapting Google'sGearsor Adobe'sAIR to
providecommunicating containment.
• Providescooperation under mutual suspicion.
• Heavyweight.
• Distribution isdifficult.
• Still subject to XSSattacks.
3. Weneed to replaceJavaScript
and theDOM.
Aslong asweareusing insecure
languages, wewill besubject to XSS
attacks.
Start with theADsafesubset, and
then carefully add featuresto
enhanceexpressiveness.
A isan Object.
Object A hasstate
and behavior.
Object A hasa
referenceto
Object B.
An object can have
referencesto other objects.
has-a
...becauseit hasa
referenceto
Object B.
Object A can
communicatewith
Object B...
Object B provides
an interfacethat
constrainsaccess
to itsown state
and references.
Every object isamicro vat.
Object A doesnot haveareferenceto
Object C, so Object A cannot
communicatewith Object C.
In an Object Capability
System, an object can only
communicatewith objects
that it hasreferencesto.
An Object Capability System is
produced by constraining theways
that referencesareobtained.
A referencecannot beobtained
simply by knowing thenameof a
global variableor apublic class.
Thereareexactly threewaysto obtain
areference.
1. By Creation.
2. By Construction.
3. By Introduction.
1. By Creation
If afunction createsan object, it gets
areferenceto that object.
2. By Construction
An object may beendowed by itsconstructor with
references.
Thiscan includereferencesin theconstructor's
context and inherited references.
3. By Introduction
A hasareferencesto B and C.
B hasno references, so it cannot communicatewith A or C.
C hasno references, so it cannot communicatewith A or B.
3. By Introduction
A callsB, passing areferenceto C.
3. By Introduction
B isnow ableto communicatewith C.
It hasthecapability.
Weaknessesto avoid include
1. Arrogation.
2. Corruption.
3. Confusion.
4. Collusion.
Thereisno security in obscurity
Tricksand puzzlesarenot effective.
Speed bumpsarenot effective.
Falsesecurity increasesthe
danger.
Ineffectivemeasuresmakethings
worse.
Thesecurity problemsarenot
new.
Theproblemsaregetting harder to
ignore.
Ultimately
• Weneed to replaceJavaScript with asecure
language.
• Thecurrent ES4 proposal isnot that language.
• Weneed to replaceHTML and theDOM with
asecureapplication delivery system.
• Thecurrent HTML5 proposal isnot that either.
Ultimately
• Secureprogramming languageto replace
JavaScript.
• A modular application framework to replace
theDOM and CSS.
• A common text representation and protocol to
replaceHTTPand theAjax stack.
• Otherwise, theweb may fall to newer
proprietary systems.
Meanwhile
• Never trust thebrowser.
• Formally validateeverything you receivefrom the
browser.
• Properly encodeeverything you send to thebrowser
or database.
• Do not circumvent what littlesecurity thebrowser
offers.
• Never put dataon thewireunlessyou want it to be
delivered.
• Don't takeineffectivemeasures.
BeRigorous
• SloppinessaidstheEnemy.
• Neatnesscounts.
• Usegood encoders.
• Avoid concatenation.
• Beparanoid.
Turducken

More Related Content

PPT
Test slideshow
PPT
XSS filter on Server side
PDF
Bug Bounty Hunter's Manifesto V1.0
PDF
Hacker halted2
PDF
Passwords and Botnets and Zombies (oh my!)
PDF
Bug Bounty - Hackers Job
PPTX
2018 Hacked Website Trends
PDF
Yet another talk on bug bounty
Test slideshow
XSS filter on Server side
Bug Bounty Hunter's Manifesto V1.0
Hacker halted2
Passwords and Botnets and Zombies (oh my!)
Bug Bounty - Hackers Job
2018 Hacked Website Trends
Yet another talk on bug bounty

What's hot (18)

PPTX
Bug bounty hunting
PPTX
Backup-File Artifacts - OWASP Khartoum InfoSec Sessions 2016 - Mazin Ahmed
PDF
Bug bounty null_owasp_2k17
PDF
When love kills
PPTX
Introduction to Hacking
PPTX
Webinar: CWAF for Mid Market/Enterprise Organizations
PPTX
PPT
GNUCITIZEN Pdp Owasp Day September 2007
PPTX
Bug Bounty
PDF
4774.projectb.securitysquad
PDF
Web Security: A Primer for Developers
PPT
Security Challenges Today
PDF
Session hijacking by rahul tyagi
PPTX
LKNOG3 - Bug Bounty
PDF
Cyber security-awareness-for-social-media-users - Devsena Mishra
PDF
5 Tips to Successfully Running a Bug Bounty Program
DOCX
Punto 16
DOCX
Punto 16
Bug bounty hunting
Backup-File Artifacts - OWASP Khartoum InfoSec Sessions 2016 - Mazin Ahmed
Bug bounty null_owasp_2k17
When love kills
Introduction to Hacking
Webinar: CWAF for Mid Market/Enterprise Organizations
GNUCITIZEN Pdp Owasp Day September 2007
Bug Bounty
4774.projectb.securitysquad
Web Security: A Primer for Developers
Security Challenges Today
Session hijacking by rahul tyagi
LKNOG3 - Bug Bounty
Cyber security-awareness-for-social-media-users - Devsena Mishra
5 Tips to Successfully Running a Bug Bounty Program
Punto 16
Punto 16
Ad

Viewers also liked (20)

PDF
Pl ams 2015_unicode_dveeden
KEY
Character sets
KEY
mod_rewrite
PPT
Explain that explain
DOCX
Rubrics
PDF
Apostila tc
PPTX
Assignment 8. Blog.
PPTX
"Miguel Sánchez López" High School Inventory
PPTX
Shelf talker displays
PDF
Storytelling1
PDF
PDF
Závěrečný úkol KPI
PPTX
RESTful Architecture
PDF
FITC - Bootstrap Unleashed
PDF
150 طريقه لبر الام
PPTX
Javascript Security
PPTX
Facial performance enhancement using dynamic shape space analysis
PPT
15 protips for mysql users pfz
PDF
More mastering the art of indexing
PPTX
Sea level rise
Pl ams 2015_unicode_dveeden
Character sets
mod_rewrite
Explain that explain
Rubrics
Apostila tc
Assignment 8. Blog.
"Miguel Sánchez López" High School Inventory
Shelf talker displays
Storytelling1
Závěrečný úkol KPI
RESTful Architecture
FITC - Bootstrap Unleashed
150 طريقه لبر الام
Javascript Security
Facial performance enhancement using dynamic shape space analysis
15 protips for mysql users pfz
More mastering the art of indexing
Sea level rise
Ad

Similar to Security for javascript (20)

PDF
Douglas - Real JavaScript
PPT
Test slideshow
PPT
Test slideshow
PPT
Test slideshow
PDF
Locking the Throne Room - How ES5+ might change views on XSS and Client Side ...
PPTX
Web security: Securing Untrusted Web Content in Browsers
PPT
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
PDF
Secure java script-for-developers
PPTX
Java Secure Coding Practices
PDF
Locking the Throneroom 2.0
PDF
C01461422
PPTX
Html5 security
PDF
Node Security: The Good, Bad & Ugly
PPT
Douglas Crockford - Ajax Security
PPTX
Cos 432 web_security
PPTX
Application Security Vulnerabilities: OWASP Top 10 -2007
PPTX
Web security: Securing untrusted web content at browsers
PPTX
Deconstructing website attacks - Eric Vanderburg
PPT
(In)Security Implication in the JS Universe
PPTX
Browser Security ppt.pptx
Douglas - Real JavaScript
Test slideshow
Test slideshow
Test slideshow
Locking the Throne Room - How ES5+ might change views on XSS and Client Side ...
Web security: Securing Untrusted Web Content in Browsers
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
Secure java script-for-developers
Java Secure Coding Practices
Locking the Throneroom 2.0
C01461422
Html5 security
Node Security: The Good, Bad & Ugly
Douglas Crockford - Ajax Security
Cos 432 web_security
Application Security Vulnerabilities: OWASP Top 10 -2007
Web security: Securing untrusted web content at browsers
Deconstructing website attacks - Eric Vanderburg
(In)Security Implication in the JS Universe
Browser Security ppt.pptx

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Machine Learning_overview_presentation.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
cuic standard and advanced reporting.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
A Presentation on Artificial Intelligence
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Tartificialntelligence_presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
SOPHOS-XG Firewall Administrator PPT.pptx
A comparative analysis of optical character recognition models for extracting...
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Programs and apps: productivity, graphics, security and other tools
Machine learning based COVID-19 study performance prediction
Machine Learning_overview_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
cuic standard and advanced reporting.pdf
Getting Started with Data Integration: FME Form 101
Spectral efficient network and resource selection model in 5G networks
A Presentation on Artificial Intelligence
MIND Revenue Release Quarter 2 2025 Press Release

Security for javascript