SlideShare a Scribd company logo
M E T E O R ( H T T P S : / / B L O G . D E S I G N V E L O P E R . C O M / C A T E G O R Y / M E T E O R / )
NoSQL Injection in Meteor.js Application
FYI:
This is one of two topics of our 2nd Meteor Meetup on July 9th, 2016. The author is Son Le, a young talent member of Designveloper.
Those who were not able to attend our 2nd Meteor Ho Chi Minh meetup (https://blog.designveloper.com/2016/07/11/2nd-meteor-ho-chi-minh-meetup-review/)
at July 9th could nd all about NoSQL Injection in Meteor.js Application – one of the main topics (https://blog.designveloper.com/2016/08/02/how-to-deploy-
and-scale-your-meteor-apps/) of the meetup – in this blog.
Before digging into every facet of this post, you are required to have a fairly good background of Meteor (https://www.meteor.com/) and MongoDB
(https://www.mongodb.com/), which is the most widely used NOSQL database. If you are a Meteor-novice, no worries! You can discover more about this full-
stack JavaScript platform for developing single-page, real time web and mobile apps at Meteor.com (https://guide.meteor.com)
Now, are you ready to get what you missed at our Meetup?
SQL INJECTION
SQL Injection is de ned as a code injection technique, used to attack data-driven applications, in which nefarious SQL statement are inserted into an entry eld
for execution. (Source: Wikipedia)
In other words, SQL injection is a technique where malicious users inject SQL commands into an SQL statement to change it and compromises the security of a
web application with SQL database.
There are 4 common forms of technical implementations of SQL injection:
Incorrectly Filtered Escape Characters with this line of code:
statement = "SELECT*FROMusersWHERE name = '" + userName + "';"
Incorrectly Type Handling:
B y Va n D o ( h t t p s : // b l o g . d e s i g n v e l o p e r. c o m / a u t h o r / v a n d o / ) o n A u g u s t 6 , 2 0 1 6
statement := "SELECT*FROMuserinfoWHEREid=" + a_variable + ";"
Blind SQL Injection:
SELECT*FROMbookreviewsWHEREID='Value(ID)';
Second order SQL injection
I am going to give you an example of Incorrectly Filtered Character. Here I want to get a user data with username Peter and password “$PWQ”, the query looks
something like this:
// query
SELECT * FROMusers
WHERE username='peter’
AND (password=('$PWD'))
If I use a “weird” input, for example:
// input
' OR '1'='1’
The result query is:
// result
SELECT * FROM users
WHERE username='peter' AND (password='' OR '1'='1')
As you can see, the condition (password=” OR ‘1’=’1′) is always true. That’s why the result query is always successful. By this way, attackers can get any
arbitrary user data, given the username.
NOSQL INJECTION
Now, although NoSQL is still a popular attacking technique, it’s no longer as widespread as it used to be. Many modern apps use NoSQL databases such as
MongoDB for its simplicity and speed. Unlike SQL in which queries use STRINGs as the control mechanism, NoSQL queries use OBJECTs instead. With NoSQL
Injection, instead of injecting STRINGS as parameters, attackers use SUB-OBJECTs as parameters to inject database queries.
The SQL statement that we used above to query the user login details will be written like this in MongoDB:
db.users.find({username: username, password: password});
As mentioned before, attackers can use subobjects as parameters to inject to NoSQL database queries, for example:
db.users.find({
username: “peter”,
password: { $gt: “” }
})
In the above query, the $gt operators stands for “greater than”. The password is not validated to ensure that it is string. Therefore, when the JSON document is
deserialized, that eld may contain anything but string that can be used to manipulate the structure of the query. You can get that what the query does is
comparing the password of “peter” with an empty string, so this condition is always true.
In MongoDB, there’re many similar operators, like $gt that attackers can take advantage of, such as: $gte (greater than or equal to), $lt (less than), $lte (less
than or equal to), $ne (not equal to), $nin (matches none of the values speci ed in an array), etc.
NOSQL INJECTION IN METEOR APPLICATION
Here comes the Meteor part. Typically the default data layer of Meteor applications in MongoDB, which puts Meteor apps in the risk of being exploited using the
NoSQL Injection technique. Let’s get into one demo application for testing NoSQL Injection: meteor-shop. you can clone the app from
https://github.com/sonlexqt/meteor-shop (https://github.com/sonlexqt/meteor-shop). This web application is written in Meteor. Please follow the instruction in
README.md le for how to setup and run the app in your local machine.
In the scope of Meteor, attackers usually take advantage of publication functions and methods. For example, you can see that in the publication.js le we have
this publication function:
// Get the products, filtered by their vendor
Meteor.publish("products-by-vendor", function(slug){
return Products.find({"vendor.slug" : slug})
});
We (as developer) are expecting the slug information to be a string, but haven’t check for that condition. So whatever input can be injected into this function,
which makes it vulnerable to NoSQL Injection. For example. an attackers can do this (in browser console) to get all the documents in the Products collections:
Meteor.subscribe(“products-by-vendor”, { $ne: null })
Products.find().fetch() // Now all products in the database are shown !
You can take a look at the server/publication.js le and meetup.js le. Those les contain some examples to help you play around with NoSQL in the demo app.
SOLUTION TO THE PROBLEM
Through those example above, hopefully you can see the potential of NoSQL Injection being a threat to apps using NoSQL databases. So how do we prevent
this problem?
Fortunately, it’s pretty easy in the scope of Meteor to prevent the app from being attacked by NoSQL Injection. In general, there’s only one thing to keep in mind:
Never completely trust user inputs. We must always get them validated before passing them as parameters to publication functions and methods. Meteor has
a handy package which do the exact same thing called check (https://atmospherejs.com/meteor/check). This package will allow us developers to check if the
input parameter match the de ned type. So, one can’t inject a JavaScript object as parameter to a function which requires a string, for example.
The check package is quite useful but what if your project has so many publication functions/methods that you don’t know if their parameters have been
checked or not? Then here comes audit-argument-check (https://atmospherejs.com/meteor/audit-argument-checks) and check-checker
(https://github.com/East5th/check-checker), those package will throw warnings if there’re methods that haven’t been checked by the check package.
Wrapping Up!
Walking through this blog, we’ve discovered more about NoSQL Injection:
How it works and some examples
How to prevent it in general and in the scope of Meteor
So, did you nd some great information of your own in this blog? What am I missing? Let me know in the comments and I’ll add it in!
If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter or Facebook. Thank you!

More Related Content

PPT
D:\Technical\Ppt\Sql Injection
PPTX
Sql injection
PPT
Sql Injection Attacks Siddhesh
PPTX
Sql injection - security testing
PDF
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
PPT
SQL Injection
PPTX
Ppt on sql injection
PDF
Sql Injection and XSS
D:\Technical\Ppt\Sql Injection
Sql injection
Sql Injection Attacks Siddhesh
Sql injection - security testing
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
SQL Injection
Ppt on sql injection
Sql Injection and XSS

What's hot (20)

PPT
Sql injection
PDF
Sql Injection - Vulnerability and Security
PDF
PPT
Sql injection attack
PPTX
SQL Injection Defense in Python
PDF
XSS And SQL Injection Vulnerabilities
PDF
Sql Injection Myths and Fallacies
PDF
Understanding advanced blind sqli attack
PDF
Regular Expression Injection
PPTX
Sql injections - with example
PDF
Rails and security
PDF
How to identify and prevent SQL injection
PDF
Security testing addons
PDF
Expression language Injection
PPTX
seminar report on Sql injection
PPTX
Jsp session 3
PPT
Advanced Topics On Sql Injection Protection
PPTX
ASP.NET MVC 3 in area of Javascript and Ajax improvement
PPT
How To Detect Xss
DOCX
androidSample
Sql injection
Sql Injection - Vulnerability and Security
Sql injection attack
SQL Injection Defense in Python
XSS And SQL Injection Vulnerabilities
Sql Injection Myths and Fallacies
Understanding advanced blind sqli attack
Regular Expression Injection
Sql injections - with example
Rails and security
How to identify and prevent SQL injection
Security testing addons
Expression language Injection
seminar report on Sql injection
Jsp session 3
Advanced Topics On Sql Injection Protection
ASP.NET MVC 3 in area of Javascript and Ajax improvement
How To Detect Xss
androidSample
Ad

Viewers also liked (14)

PPTX
Agile Cincinnati Conference 2016 - Sprint Review
PPSX
TUBAB Nacho Zubelzu
PDF
Boletim de maio BE
PPTX
Razonar y pensar las ideas
PPSX
Escuela tradicional
DOC
Rpp fisika kls x a 2011 2012
PPTX
Measuring Sprint review
PPTX
Tarea dufli
DOC
CV Zayo 07-16
PDF
Branding is the most cringeworthy term you want to know about
PDF
Better Together 2014 Branch Manager Sales Conference Newsletter
PPTX
Visulising solid shapes
PDF
Marcas que destacan más y obtienen mejores resultados
PDF
エスノグラフィック・デザインアプローチ
Agile Cincinnati Conference 2016 - Sprint Review
TUBAB Nacho Zubelzu
Boletim de maio BE
Razonar y pensar las ideas
Escuela tradicional
Rpp fisika kls x a 2011 2012
Measuring Sprint review
Tarea dufli
CV Zayo 07-16
Branding is the most cringeworthy term you want to know about
Better Together 2014 Branch Manager Sales Conference Newsletter
Visulising solid shapes
Marcas que destacan más y obtienen mejores resultados
エスノグラフィック・デザインアプローチ
Ad

Similar to No sql injection in meteor.js application (20)

PDF
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
DOCX
Repository Pattern in MVC3 Application with Entity Framework
PDF
We continue checking Microsoft projects: analysis of PowerShell
PDF
Basic API Creation with Node.JS
PDF
StackMob & Appcelerator Module Part One
PPT
Overview of CSharp MVC3 and EF4
PPT
Php & Web Security - PHPXperts 2009
DOC
Attackers Vs Programmers
DOCX
ASP.NET MVC3 RAD
PPSX
DOCX
SQL Injection - Newsletter
PPT
Struts 2 Overview
PPTX
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
PDF
AngularJS Basics
PPTX
What is Swagger?
PDF
Leveraging Playwright for API Testing.pdf
PDF
Nt1310 Unit 3 Language Analysis
DOCX
Learning MVC Part 3 Creating MVC Application with EntityFramework
PPTX
Sql Injection and Entity Frameworks
PDF
Understanding router state in angular 7 passing data through angular router s...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Repository Pattern in MVC3 Application with Entity Framework
We continue checking Microsoft projects: analysis of PowerShell
Basic API Creation with Node.JS
StackMob & Appcelerator Module Part One
Overview of CSharp MVC3 and EF4
Php & Web Security - PHPXperts 2009
Attackers Vs Programmers
ASP.NET MVC3 RAD
SQL Injection - Newsletter
Struts 2 Overview
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
AngularJS Basics
What is Swagger?
Leveraging Playwright for API Testing.pdf
Nt1310 Unit 3 Language Analysis
Learning MVC Part 3 Creating MVC Application with EntityFramework
Sql Injection and Entity Frameworks
Understanding router state in angular 7 passing data through angular router s...

More from Designveloper (20)

PDF
Let us take care of your brand image
PDF
5 java script frameworks to watch in 2017
PDF
Happy international women's day!
PDF
Typing racer game - a nice break from work
PDF
Should we work remotely?
PDF
Meet song nhi your virtual financial assistance
PDF
Why pair programming is a good idea
PDF
5 worst mistakes of diy websites
PDF
Basic glossary of web design terms for non designers (part 2)
PDF
Single page web application development using meteor js
PDF
Multiplayer game with unity3 d and meteor
PDF
Awesome free resources for learning javascript
PDF
What is the best java script frameworks to learn?
PDF
Travelling forms a young man
PDF
5 compelling reasons your website should be responsive
PDF
Reactive programming with tracker
PDF
Benefits of using single page websites
PDF
What is the best programming language for beginner?
PDF
How to deploy and scale your meteor apps
PDF
Meetup groups you need to join if you are new to tech
Let us take care of your brand image
5 java script frameworks to watch in 2017
Happy international women's day!
Typing racer game - a nice break from work
Should we work remotely?
Meet song nhi your virtual financial assistance
Why pair programming is a good idea
5 worst mistakes of diy websites
Basic glossary of web design terms for non designers (part 2)
Single page web application development using meteor js
Multiplayer game with unity3 d and meteor
Awesome free resources for learning javascript
What is the best java script frameworks to learn?
Travelling forms a young man
5 compelling reasons your website should be responsive
Reactive programming with tracker
Benefits of using single page websites
What is the best programming language for beginner?
How to deploy and scale your meteor apps
Meetup groups you need to join if you are new to tech

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
MYSQL Presentation for SQL database connectivity
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
20250228 LYD VKU AI Blended-Learning.pptx
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
Assigned Numbers - 2025 - Bluetooth® Document
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
A comparative analysis of optical character recognition models for extracting...
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MYSQL Presentation for SQL database connectivity

No sql injection in meteor.js application

  • 1. M E T E O R ( H T T P S : / / B L O G . D E S I G N V E L O P E R . C O M / C A T E G O R Y / M E T E O R / )
  • 2. NoSQL Injection in Meteor.js Application FYI: This is one of two topics of our 2nd Meteor Meetup on July 9th, 2016. The author is Son Le, a young talent member of Designveloper. Those who were not able to attend our 2nd Meteor Ho Chi Minh meetup (https://blog.designveloper.com/2016/07/11/2nd-meteor-ho-chi-minh-meetup-review/) at July 9th could nd all about NoSQL Injection in Meteor.js Application – one of the main topics (https://blog.designveloper.com/2016/08/02/how-to-deploy- and-scale-your-meteor-apps/) of the meetup – in this blog. Before digging into every facet of this post, you are required to have a fairly good background of Meteor (https://www.meteor.com/) and MongoDB (https://www.mongodb.com/), which is the most widely used NOSQL database. If you are a Meteor-novice, no worries! You can discover more about this full- stack JavaScript platform for developing single-page, real time web and mobile apps at Meteor.com (https://guide.meteor.com) Now, are you ready to get what you missed at our Meetup? SQL INJECTION SQL Injection is de ned as a code injection technique, used to attack data-driven applications, in which nefarious SQL statement are inserted into an entry eld for execution. (Source: Wikipedia) In other words, SQL injection is a technique where malicious users inject SQL commands into an SQL statement to change it and compromises the security of a web application with SQL database. There are 4 common forms of technical implementations of SQL injection: Incorrectly Filtered Escape Characters with this line of code: statement = "SELECT*FROMusersWHERE name = '" + userName + "';" Incorrectly Type Handling: B y Va n D o ( h t t p s : // b l o g . d e s i g n v e l o p e r. c o m / a u t h o r / v a n d o / ) o n A u g u s t 6 , 2 0 1 6
  • 3. statement := "SELECT*FROMuserinfoWHEREid=" + a_variable + ";" Blind SQL Injection: SELECT*FROMbookreviewsWHEREID='Value(ID)'; Second order SQL injection I am going to give you an example of Incorrectly Filtered Character. Here I want to get a user data with username Peter and password “$PWQ”, the query looks something like this: // query SELECT * FROMusers WHERE username='peter’ AND (password=('$PWD')) If I use a “weird” input, for example: // input ' OR '1'='1’ The result query is: // result SELECT * FROM users WHERE username='peter' AND (password='' OR '1'='1') As you can see, the condition (password=” OR ‘1’=’1′) is always true. That’s why the result query is always successful. By this way, attackers can get any arbitrary user data, given the username. NOSQL INJECTION Now, although NoSQL is still a popular attacking technique, it’s no longer as widespread as it used to be. Many modern apps use NoSQL databases such as MongoDB for its simplicity and speed. Unlike SQL in which queries use STRINGs as the control mechanism, NoSQL queries use OBJECTs instead. With NoSQL Injection, instead of injecting STRINGS as parameters, attackers use SUB-OBJECTs as parameters to inject database queries.
  • 4. The SQL statement that we used above to query the user login details will be written like this in MongoDB: db.users.find({username: username, password: password}); As mentioned before, attackers can use subobjects as parameters to inject to NoSQL database queries, for example: db.users.find({ username: “peter”, password: { $gt: “” } }) In the above query, the $gt operators stands for “greater than”. The password is not validated to ensure that it is string. Therefore, when the JSON document is deserialized, that eld may contain anything but string that can be used to manipulate the structure of the query. You can get that what the query does is comparing the password of “peter” with an empty string, so this condition is always true. In MongoDB, there’re many similar operators, like $gt that attackers can take advantage of, such as: $gte (greater than or equal to), $lt (less than), $lte (less than or equal to), $ne (not equal to), $nin (matches none of the values speci ed in an array), etc. NOSQL INJECTION IN METEOR APPLICATION Here comes the Meteor part. Typically the default data layer of Meteor applications in MongoDB, which puts Meteor apps in the risk of being exploited using the NoSQL Injection technique. Let’s get into one demo application for testing NoSQL Injection: meteor-shop. you can clone the app from https://github.com/sonlexqt/meteor-shop (https://github.com/sonlexqt/meteor-shop). This web application is written in Meteor. Please follow the instruction in README.md le for how to setup and run the app in your local machine.
  • 5. In the scope of Meteor, attackers usually take advantage of publication functions and methods. For example, you can see that in the publication.js le we have this publication function: // Get the products, filtered by their vendor Meteor.publish("products-by-vendor", function(slug){ return Products.find({"vendor.slug" : slug}) });
  • 6. We (as developer) are expecting the slug information to be a string, but haven’t check for that condition. So whatever input can be injected into this function, which makes it vulnerable to NoSQL Injection. For example. an attackers can do this (in browser console) to get all the documents in the Products collections: Meteor.subscribe(“products-by-vendor”, { $ne: null }) Products.find().fetch() // Now all products in the database are shown ! You can take a look at the server/publication.js le and meetup.js le. Those les contain some examples to help you play around with NoSQL in the demo app. SOLUTION TO THE PROBLEM Through those example above, hopefully you can see the potential of NoSQL Injection being a threat to apps using NoSQL databases. So how do we prevent this problem? Fortunately, it’s pretty easy in the scope of Meteor to prevent the app from being attacked by NoSQL Injection. In general, there’s only one thing to keep in mind: Never completely trust user inputs. We must always get them validated before passing them as parameters to publication functions and methods. Meteor has a handy package which do the exact same thing called check (https://atmospherejs.com/meteor/check). This package will allow us developers to check if the input parameter match the de ned type. So, one can’t inject a JavaScript object as parameter to a function which requires a string, for example. The check package is quite useful but what if your project has so many publication functions/methods that you don’t know if their parameters have been checked or not? Then here comes audit-argument-check (https://atmospherejs.com/meteor/audit-argument-checks) and check-checker (https://github.com/East5th/check-checker), those package will throw warnings if there’re methods that haven’t been checked by the check package. Wrapping Up! Walking through this blog, we’ve discovered more about NoSQL Injection: How it works and some examples How to prevent it in general and in the scope of Meteor So, did you nd some great information of your own in this blog? What am I missing? Let me know in the comments and I’ll add it in! If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter or Facebook. Thank you!