SlideShare a Scribd company logo
NodeJS Security:
The Good, Bad & Ugly
A look at Server Side JS History.
   How old do you think it is?
1996 (LiveWire). Rhino (1997).
    50+ more since then
something went wrong…
JS not interesting   Slow JS Engines
    to many




           JS is               Lack of a
       misunderstood.         compelling
        Under-rated          browser war
Lead to blazing fast engines
                  Google V8 (NodeJS uses this),
The Browser War
                   FF SpiderMonkey, MS Chakra



        So why now?
Why is it so HOT?
Speed. Performance. JS to do it all.
Adoption: 11/11
Adoption: 02/12
(5 min Tech Primer)
Event-driven. Asynchronous.
      Single-threaded
Traditional Platforms
• A sample code
 data = readFromDatabase();
 printData(data);
 doSomethingUnrelated();



• Pitfalls
   – The program blocked when reading from db
   – Lots of processor cycles wasted
In Node
• A typical code

    readFromDatabase(function(data)
    {
    printData(data);
    });
    doSomethingUnrelated();


• Gains
    –   not have to wait for slow file I/O or db ops. Aka non-blocking server
    –   everything runs in parallel. doSomethingUnrelated() doesn’t wait.
    –   printData(data) called when finished reading
    –   insanely fast
    –   serve millions concurrent connections at once
A production
     Web Framework / MVC Arch.
Enter – Express, Mustache, Jade

     (What is MISSING?)
             A DB server.
  Enter – NoSQL (MongoDB, CouchDB)


       A full stack dev libraries.
              Enter – NPM
(In)Security
“JavaScript has so much expressive power that they are able to do useful things in it,
                                       anyway.”
                   http://javascript.crockford.com/javascript.html


      "JavaScript is the world's most misunderstood programming language.”
                  http://www.crockford.com/javascript/private.html




                                  (Mostly B’coz)

                                                With Power comes
                                              Responsibility
Property: Implied Globals
              Abuse: Namespace Pollution
          Impact: what’s the worst you can think?


               (The Ugly Parts)
Property: eval (new Function,setTimeout,setInterval)
             Abuse: JSON Parse, shortcuts
              Impact: Host Compromise


               Property: process privilege
            Abuse: run as root (even Express)
      Impact: Why does Apache run as nobody/nobody?
Global Namespace Pollution




   JS is a global lang. By default – all variables, functions, objects are
                           implied to global scope
(In contrast, with PHP (or others), each request lives in it’s unique scope.)
Global Namespace Pollution
 WEB USER 1                                                       WEB USER 2




               # Any request will share the same global scope.
      # As seen , for two different users, each request increased gbl by 1
         (Try yourself: http://46.137.9.100:1314/)


      An equivalent code in PHP will always print 1 for every request.
Exploits: Namespace Pollution
• Overriding / Hijacking Sensitive Globals. Host Compromise
• How? imagine XSS and SOP. think your browser is now server
• Another innocent sample
    – Bob sets is_valid to true for operation X but forgets to call it as “var”.
        Y.mojito.controller = {
                 index: function(ac) {
                           var is_valid = true;


    – Alice coding on the same project also forgets “var” and initialized is_valid to false.
        Y.mojito.controller = {
                 index: function(ac) {
                           if (is_valid){
                           // get access to user data or some functions

• Attack Surface?
    – NPM: malicious library. Insecure library
    – Malicious coder
    – Innocent coder
eval is EVIL




            USE CASE # treats data as code. Very powerful. Very very popular.
EXPLOIT # CODE EXECUTION. COMMAND EXECUTION. SHELL EXECUTION. NEVER USE IT!
           SIDE NOTE: exists in NPM. Audit. Audit. Audit.



eval has cousins – setTimeout, setInterval, new Function.
                         DON‘T USE THEM
eval is EVIL




        Try yourself: http://46.137.9.100:1313
Exploit code: response.end(“my first ssi”)
Runtime Privilege Context




  # By default, NodeJS runs as privileged user
  # By default, Express runs as privileged user
        Why? Remote Shell Exploits.
     Why Apache runs as nobody/nobody?
Property: with                Property: switch
  Abuse: shorthand typos         Abuse: faulty fallthru
Impact: Context dependent      Impact: Context dependent


                (The Bad Parts)
           Property: single threaded / interpreted
           Abuse: incomplete exception handling
                       Impact: DoS


     Property: templating engines [mu, jade, ejs, haml]
        Abuse: context sensitive output escaping
                       Impact: XSS
with is EVIL (exploitable on Cocktails)




              Use Case# welcome message
              What went wrong # typo,…
with is EVIL (exploitable on Cocktails)




                      Exploit # Depends
        (Try yourself: http://46.137.9.100:1315/)
DoS (*doesn’t affect Express)

                                                          Generate a simple
                                                             exception




JS is interpreted, NOT compiled. Code itself shouldn’t be faulty. Else it’s a
                   self-DoS. Very difficult to ENSURE this.
switch is EVIL (an old foe)




     Use Case# Valued Customer be given 10% discount only
      Exploit # missing break leading to privilege escalation
switch is EVIL (an old foe)




     Exploit # Valued Customer getting more discount
 (Try Yourself: http://46.137.9.100:1317/)
No CSAS Output Escaper
• What is the #1 web security issue?
    XSS (going to spiral further)

• All templating engines for NodeJS only provide HTML
Context Escaping
     Good, but shouldn’t an excellent new technology
    attempt to fix the remaining BAD things?
        <a href=“$url”> my url </a>
           $url = javascript:alert(1)
        <body onload=“bingbang(‘$id’)”>
           $id = ‘);alert(1);
        <script> var a = $b </script>
           $b = ; alert(0);
        <div name=$c>
           $c =    onload=alert(1);
        many more….

• We ported Google AutoEscape to NodeJS, nicknamed Joe
     Will be open sourced soon…
<!-- Research In Progress -->
• Can you do cross-domain (SetSecurityToken,
  RunInContext)?
  – Exploiting hosted environments
• NPM packages
  – Think external JS. Malicious? Insecure?
  – Now even C libraries
• Are other JSLint bad practices exploitable?
  – Is Automatic Semicolon Insertion exploitable?
  – Many more…. Read “The Good Parts” once again
Training                JSLint



            (SOLUTION)
Secure Dev Frameworks


                         Coding Guideline


        EcmaScript5
Bare bone web server.
                Remember NetBSD?
Isn’t configured / capable more than what you want.
            Unlike Apache, Tomcat, IIS?


                (The Good Parts)
                          But why is it good?
                  More features, bigger attack surface.
       Bigger attack surface, more chances of things going wrong.
            And something that can go wrong will go wrong.
             E.g. 1.3 zillion BO exploits world has seen
// end of a beginning
       twitter: b1shan / yukinying
blog: http://bishankochher.blogspot.com/
Ad

More Related Content

What's hot (20)

React for Dummies
React for DummiesReact for Dummies
React for Dummies
Mitch Chen
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
MicroPyramid .
 
CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
Kongu Engineering College, Perundurai, Erode
 
CSS Grid
CSS GridCSS Grid
CSS Grid
Digital Surgeons
 
Expressjs
ExpressjsExpressjs
Expressjs
Yauheni Nikanovich
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxGetting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Ilesh Mistry
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
React hooks
React hooksReact hooks
React hooks
Sadhna Rana
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
Russ Weakley
 
CSS Layout Techniques
CSS Layout TechniquesCSS Layout Techniques
CSS Layout Techniques
Harshal Patil
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
Mindy McAdams
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
Ravi Bhadauria
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
Bharat_Kumawat
 
Cross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering PerformanceCross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering Performance
Igalia
 
Css pseudo-classes
Css pseudo-classesCss pseudo-classes
Css pseudo-classes
Webtech Learning
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
AnmolPandita7
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
Mitch Chen
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
MicroPyramid .
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxGetting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Ilesh Mistry
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
Russ Weakley
 
CSS Layout Techniques
CSS Layout TechniquesCSS Layout Techniques
CSS Layout Techniques
Harshal Patil
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
Mindy McAdams
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
Ravi Bhadauria
 
Cross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering PerformanceCross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering Performance
Igalia
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 

Viewers also liked (10)

NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise Middleware
Behrad Zari
 
Apache spark linkedin
Apache spark linkedinApache spark linkedin
Apache spark linkedin
Yukti Kaura
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
AppDynamics
 
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
Adrian Cockcroft
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scale
Sudhir Tonse
 
10 Tips for failing at microservices
10 Tips for failing at microservices10 Tips for failing at microservices
10 Tips for failing at microservices
David Schmitz
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
NodejsFoundation
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
Sam Newman
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise Middleware
Behrad Zari
 
Apache spark linkedin
Apache spark linkedinApache spark linkedin
Apache spark linkedin
Yukti Kaura
 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
AppDynamics
 
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
Adrian Cockcroft
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scale
Sudhir Tonse
 
10 Tips for failing at microservices
10 Tips for failing at microservices10 Tips for failing at microservices
10 Tips for failing at microservices
David Schmitz
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
NodejsFoundation
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
Sam Newman
 
Ad

Similar to Node Security: The Good, Bad & Ugly (20)

Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
RootedCON
 
Foolangjs
FoolangjsFoolangjs
Foolangjs
Amjad Masad
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
Eric Bottard
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
Frontend automation and stability
Frontend automation and stabilityFrontend automation and stability
Frontend automation and stability
Máté Nádasdi
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
Jackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
elliando dias
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
Tech in Asia ID
 
Java Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky ProblemJava Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky Problem
Will Iverson
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBusters
Elena-Oana Tabaranu
 
GWT is Smarter Than You
GWT is Smarter Than YouGWT is Smarter Than You
GWT is Smarter Than You
Robert Cooper
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
The Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web DevelopmentThe Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web Development
twopoint718
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
bobmcwhirter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
Felix Geisendörfer
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
RootedCON
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
Eric Bottard
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
Frontend automation and stability
Frontend automation and stabilityFrontend automation and stability
Frontend automation and stability
Máté Nádasdi
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
Jackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
Tech in Asia ID
 
Java Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky ProblemJava Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky Problem
Will Iverson
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBusters
Elena-Oana Tabaranu
 
GWT is Smarter Than You
GWT is Smarter Than YouGWT is Smarter Than You
GWT is Smarter Than You
Robert Cooper
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
The Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web DevelopmentThe Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web Development
twopoint718
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
bobmcwhirter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
Felix Geisendörfer
 
Ad

Recently uploaded (20)

Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 

Node Security: The Good, Bad & Ugly

  • 2. A look at Server Side JS History. How old do you think it is?
  • 3. 1996 (LiveWire). Rhino (1997). 50+ more since then
  • 4. something went wrong… JS not interesting Slow JS Engines to many JS is Lack of a misunderstood. compelling Under-rated browser war
  • 5. Lead to blazing fast engines Google V8 (NodeJS uses this), The Browser War FF SpiderMonkey, MS Chakra So why now?
  • 6. Why is it so HOT? Speed. Performance. JS to do it all.
  • 9. (5 min Tech Primer) Event-driven. Asynchronous. Single-threaded
  • 10. Traditional Platforms • A sample code data = readFromDatabase(); printData(data); doSomethingUnrelated(); • Pitfalls – The program blocked when reading from db – Lots of processor cycles wasted
  • 11. In Node • A typical code readFromDatabase(function(data) { printData(data); }); doSomethingUnrelated(); • Gains – not have to wait for slow file I/O or db ops. Aka non-blocking server – everything runs in parallel. doSomethingUnrelated() doesn’t wait. – printData(data) called when finished reading – insanely fast – serve millions concurrent connections at once
  • 12. A production Web Framework / MVC Arch. Enter – Express, Mustache, Jade (What is MISSING?) A DB server. Enter – NoSQL (MongoDB, CouchDB) A full stack dev libraries. Enter – NPM
  • 14. “JavaScript has so much expressive power that they are able to do useful things in it, anyway.” http://javascript.crockford.com/javascript.html "JavaScript is the world's most misunderstood programming language.” http://www.crockford.com/javascript/private.html (Mostly B’coz) With Power comes Responsibility
  • 15. Property: Implied Globals Abuse: Namespace Pollution Impact: what’s the worst you can think? (The Ugly Parts) Property: eval (new Function,setTimeout,setInterval) Abuse: JSON Parse, shortcuts Impact: Host Compromise Property: process privilege Abuse: run as root (even Express) Impact: Why does Apache run as nobody/nobody?
  • 16. Global Namespace Pollution JS is a global lang. By default – all variables, functions, objects are implied to global scope (In contrast, with PHP (or others), each request lives in it’s unique scope.)
  • 17. Global Namespace Pollution WEB USER 1 WEB USER 2 # Any request will share the same global scope. # As seen , for two different users, each request increased gbl by 1 (Try yourself: http://46.137.9.100:1314/) An equivalent code in PHP will always print 1 for every request.
  • 18. Exploits: Namespace Pollution • Overriding / Hijacking Sensitive Globals. Host Compromise • How? imagine XSS and SOP. think your browser is now server • Another innocent sample – Bob sets is_valid to true for operation X but forgets to call it as “var”. Y.mojito.controller = { index: function(ac) { var is_valid = true; – Alice coding on the same project also forgets “var” and initialized is_valid to false. Y.mojito.controller = { index: function(ac) { if (is_valid){ // get access to user data or some functions • Attack Surface? – NPM: malicious library. Insecure library – Malicious coder – Innocent coder
  • 19. eval is EVIL USE CASE # treats data as code. Very powerful. Very very popular. EXPLOIT # CODE EXECUTION. COMMAND EXECUTION. SHELL EXECUTION. NEVER USE IT! SIDE NOTE: exists in NPM. Audit. Audit. Audit. eval has cousins – setTimeout, setInterval, new Function. DON‘T USE THEM
  • 20. eval is EVIL Try yourself: http://46.137.9.100:1313 Exploit code: response.end(“my first ssi”)
  • 21. Runtime Privilege Context # By default, NodeJS runs as privileged user # By default, Express runs as privileged user Why? Remote Shell Exploits. Why Apache runs as nobody/nobody?
  • 22. Property: with Property: switch Abuse: shorthand typos Abuse: faulty fallthru Impact: Context dependent Impact: Context dependent (The Bad Parts) Property: single threaded / interpreted Abuse: incomplete exception handling Impact: DoS Property: templating engines [mu, jade, ejs, haml] Abuse: context sensitive output escaping Impact: XSS
  • 23. with is EVIL (exploitable on Cocktails) Use Case# welcome message What went wrong # typo,…
  • 24. with is EVIL (exploitable on Cocktails) Exploit # Depends (Try yourself: http://46.137.9.100:1315/)
  • 25. DoS (*doesn’t affect Express) Generate a simple exception JS is interpreted, NOT compiled. Code itself shouldn’t be faulty. Else it’s a self-DoS. Very difficult to ENSURE this.
  • 26. switch is EVIL (an old foe) Use Case# Valued Customer be given 10% discount only Exploit # missing break leading to privilege escalation
  • 27. switch is EVIL (an old foe) Exploit # Valued Customer getting more discount (Try Yourself: http://46.137.9.100:1317/)
  • 28. No CSAS Output Escaper • What is the #1 web security issue? XSS (going to spiral further) • All templating engines for NodeJS only provide HTML Context Escaping  Good, but shouldn’t an excellent new technology attempt to fix the remaining BAD things?  <a href=“$url”> my url </a> $url = javascript:alert(1)  <body onload=“bingbang(‘$id’)”> $id = ‘);alert(1);  <script> var a = $b </script> $b = ; alert(0);  <div name=$c> $c = onload=alert(1);  many more…. • We ported Google AutoEscape to NodeJS, nicknamed Joe  Will be open sourced soon…
  • 29. <!-- Research In Progress --> • Can you do cross-domain (SetSecurityToken, RunInContext)? – Exploiting hosted environments • NPM packages – Think external JS. Malicious? Insecure? – Now even C libraries • Are other JSLint bad practices exploitable? – Is Automatic Semicolon Insertion exploitable? – Many more…. Read “The Good Parts” once again
  • 30. Training JSLint (SOLUTION) Secure Dev Frameworks Coding Guideline EcmaScript5
  • 31. Bare bone web server. Remember NetBSD? Isn’t configured / capable more than what you want. Unlike Apache, Tomcat, IIS? (The Good Parts) But why is it good? More features, bigger attack surface. Bigger attack surface, more chances of things going wrong. And something that can go wrong will go wrong. E.g. 1.3 zillion BO exploits world has seen
  • 32. // end of a beginning twitter: b1shan / yukinying blog: http://bishankochher.blogspot.com/