Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE-719 Fix parameter tampering #68

Merged
merged 4 commits into from
Dec 10, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/rest/dbroutes.js
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ const dbroutes = (router, platform) => {
const channel_genesis_hash = req.params.channel_genesis_hash;
const blockNum = parseInt(req.params.blocknum);
let txid = parseInt(req.params.txid);
const orgs = requtil.orgsArrayToString(req.query.orgs);
const orgs = requtil.orgsArrayToString(req.query);
const { from, to } = requtil.queryDatevalidator(
req.query.from,
req.query.to
@@ -207,7 +207,7 @@ const dbroutes = (router, platform) => {
async (req, res) => {
const channel_genesis_hash = req.params.channel_genesis_hash;
const blockNum = parseInt(req.params.blocknum);
const orgs = requtil.orgsArrayToString(req.query.orgs);
const orgs = requtil.orgsArrayToString(req.query);
const { from, to } = requtil.queryDatevalidator(
req.query.from,
req.query.to
32 changes: 23 additions & 9 deletions app/rest/requestutils.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

const queryString = require('query-string');
/**
*
*
@@ -88,18 +89,31 @@ function reqPayload(req) {
return requestPayload;
}

const orgsArrayToString = function(orgs) {
const orgsArrayToString = function(reqQuery) {
let temp = '';
if (Array.isArray(orgs) || typeof orgs === 'object') {
orgs.forEach((element, i) => {
temp += `'${element}'`;
if (orgs.length - 1 !== i) {
temp += ',';
if (reqQuery) {
// eslint-disable-next-line spellcheck/spell-checker
// workaround 'Type confusion through parameter tampering', see `https //lgtm dot com/rules/1506301137371 `
const orgsStr = queryString.stringify(reqQuery);

if (orgsStr) {
const parsedReq = queryString.parse(orgsStr);
if (parsedReq && parsedReq.orgs) {
const orgsArray = parsedReq.orgs.toString().split(',');
console.log('requestutils.orgsArrayToString.orgsArray ', orgsArray);
// format DB value for IN clause, ex: in ('a', 'b', 'c')
if (orgsArray) {
orgsArray.forEach((element, i) => {
temp += `'${element}'`;
if (orgsArray.length - 1 !== i) {
temp += ',';
}
});
}
}
});
} else if (orgs) {
temp = `'${orgs}'`;
}
}
console.log('comma separated organizations: ', temp);
return temp;
};

2 changes: 2 additions & 0 deletions lgtm.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# SPDX-License-Identifier: Apache-2.0


@@ -7,6 +8,7 @@ queries:
- exclude: "js/stack-trace-exposure"
- exclude: "js/useless-assignment-to-local"
- exclude: "js/react/unused-or-undefined-state-property"
- exclude: "js/superfluous-trailing-arguments"
extraction:
javascript:
index:
23 changes: 21 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
"pg-pool": "^2.0.7",
"prettyjson": "^1.2.1",
"prop-types": "^15.6.2",
"query-string": "^6.9.0",
"save": "^2.3.3",
"stomp-broker-js": "^0.1.3",
"stompjs": "^2.3.3",