Application Security – Use NPM Request Package for APIs Access

This blog represents code sample and related details that can be used to hack into the system through unprotected APIs. The security vulnerability such as following can be exploited using the code sample given later in this article. Note that the security vulnerabilities mentioned below forms part of OWASP 2017 Top 10 security vulnerabilities.

The code below has made use of NPM request package to send the request to the API hosted ast Paytm Catalog Site. The API below displays electronics items listed on PayTMMall.com.

var request = require('request');

var url = "https://catalog.paytm.com/v2/h/electronics?channel=web&child_site_id=6&site_id=2&version=2&platform_version=S2(New)";
var method = "POST";
var headers = {
"content-type": "application/json",
"accept": "*/*"
};

var data = {"tracking":{"current_page":"https://paytmmall.com/shop/h/electronics","prev_page":""},"context":{"device":{"os":"Linux x86_64","device_type":"PC","browser_uuid":"GA1.2.35123967.1498556341","ua":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0","connection_type":"Unknown"},"channel":"WEB","user":{"ga_id":"GA1.2.35123967.1498556341","user_id":null}}}
var isJSON = true;

request({
url: url,
method: method,
body: data,
json: isJSON,
headers: headers,
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
console.log("Response: " + JSON.stringify(response));
console.log("Error: " + error);
});

Put the code shown above in a file, say, test.js and execute the file using command such as node test.js. The output would display data retrieved from the website.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

Share
Published by
Ajitesh Kumar

Recent Posts

Feature Engineering in Machine Learning: Python Examples

Last updated: 3rd May, 2024 Have you ever wondered why some machine learning models perform…

22 hours ago

Feature Selection vs Feature Extraction: Machine Learning

Last updated: 2nd May, 2024 The success of machine learning models often depends on the…

2 days ago

Model Selection by Evaluating Bias & Variance: Example

When working on a machine learning project, one of the key challenges faced by data…

2 days ago

Bias-Variance Trade-off in Machine Learning: Examples

Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…

3 days ago

Mean Squared Error vs Cross Entropy Loss Function

Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…

3 days ago

Cross Entropy Loss Explained with Python Examples

Last updated: 1st May, 2024 In this post, you will learn the concepts related to…

3 days ago