SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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/

Más contenido relacionado

La actualidad más candente

NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA  NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA Pramendra Gupta
 
나의 이직 이야기
나의 이직 이야기나의 이직 이야기
나의 이직 이야기종립 이
 
Web assembly: a brief overview
Web assembly: a brief overviewWeb assembly: a brief overview
Web assembly: a brief overviewPavlo Iatsiuk
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.jsSmile Gupta
 
Massive service basic
Massive service basicMassive service basic
Massive service basicDaeMyung Kang
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다Arawn Park
 
Présentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de SymfonyPrésentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de SymfonyRaphaël Kueny
 
How to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elementsHow to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elementsMarcellKiss7
 
예외처리가이드
예외처리가이드예외처리가이드
예외처리가이드도형 임
 
서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)수보 김
 
Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1 나무기술(주) 최유석 20170912
Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1  나무기술(주) 최유석 20170912Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1  나무기술(주) 최유석 20170912
Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1 나무기술(주) 최유석 20170912Yooseok Choi
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipesKnoldus Inc.
 
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017Amazon Web Services Korea
 
NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020Milad Heydari
 
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティスコンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
コンポーネント指向による、ReactのベストプラクティスとバッドプラクティスKohei Asai
 

La actualidad más candente (20)

NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA  NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA
 
나의 이직 이야기
나의 이직 이야기나의 이직 이야기
나의 이직 이야기
 
Web assembly: a brief overview
Web assembly: a brief overviewWeb assembly: a brief overview
Web assembly: a brief overview
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.js
 
Node js
Node jsNode js
Node js
 
Massive service basic
Massive service basicMassive service basic
Massive service basic
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
 
Présentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de SymfonyPrésentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de Symfony
 
Fetch API Talk
Fetch API TalkFetch API Talk
Fetch API Talk
 
How to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elementsHow to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elements
 
예외처리가이드
예외처리가이드예외처리가이드
예외처리가이드
 
서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)
 
Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1 나무기술(주) 최유석 20170912
Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1  나무기술(주) 최유석 20170912Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1  나무기술(주) 최유석 20170912
Bigquery와 airflow를 이용한 데이터 분석 시스템 구축 v1 나무기술(주) 최유석 20170912
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipes
 
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
 
NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020
 
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティスコンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
 
React vac pattern
React vac patternReact vac pattern
React vac pattern
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 

Destacado

NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystemYukti Kaura
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise MiddlewareBehrad Zari
 
Apache spark linkedin
Apache spark linkedinApache spark linkedin
Apache spark linkedinYukti 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 2016Adrian Cockcroft
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleSudhir Tonse
 
10 Tips for failing at microservices
10 Tips for failing at microservices10 Tips for failing at microservices
10 Tips for failing at microservicesDavid Schmitz
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.jsNodejsFoundation
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocitySam Newman
 

Destacado (10)

NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise Middleware
 
Apache spark linkedin
Apache spark linkedinApache spark linkedin
Apache spark linkedin
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
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
 
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scale
 
10 Tips for failing at microservices
10 Tips for failing at microservices10 Tips for failing at microservices
10 Tips for failing at microservices
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
 

Similar a Node Security: The Good, Bad & Ugly

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 PracticesEric 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::SynchronyKyle Drake
 
Frontend automation and stability
Frontend automation and stabilityFrontend automation and stability
Frontend automation and stabilityMáté Nádasdi
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
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 backendDavid Padbury
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 
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 talkAarti 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 ProblemWill Iverson
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersElena-Oana Tabaranu
 
GWT is Smarter Than You
GWT is Smarter Than YouGWT is Smarter Than You
GWT is Smarter Than YouRobert Cooper
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris 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 Developmenttwopoint718
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011bobmcwhirter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 

Similar a 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]
 
Foolangjs
FoolangjsFoolangjs
Foolangjs
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
 
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
 
Frontend automation and stability
Frontend automation and stabilityFrontend automation and stability
Frontend automation and stability
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
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
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
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
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
"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)
 
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
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBusters
 
GWT is Smarter Than You
GWT is Smarter Than YouGWT is Smarter Than You
GWT is Smarter Than You
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
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
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 

Último

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Último (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

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/