@itentialopensource/adapter-utils 5.3.9 → 5.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ## 5.3.10 [03-06-2024]
3
+
4
+ * Fix some security vulnerabilities
5
+
6
+ See merge request itentialopensource/adapter-utils!289
7
+
8
+ ---
9
+
2
10
  ## 5.3.9 [03-04-2024]
3
11
 
4
12
  * Resolve ADAPT-3296
@@ -416,10 +416,12 @@ function returnStub(request, entitySchema, callProperties) {
416
416
  if (reqBody && (!entitySchema || !entitySchema.requestDatatype
417
417
  || entitySchema.requestDatatype.toUpperCase() === 'JSON' || entitySchema.requestDatatype.toUpperCase() === 'URLENCODE')) {
418
418
  let reqBdObj = null;
419
- if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') {
420
- reqBdObj = querystring.parse(reqBody.trim());
421
- } else {
422
- reqBdObj = JSON.parse(reqBody.trim());
419
+ if (typeof reqBody === 'string') {
420
+ if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') {
421
+ reqBdObj = querystring.parse(reqBody.trim());
422
+ } else {
423
+ reqBdObj = JSON.parse(reqBody.trim());
424
+ }
423
425
  }
424
426
 
425
427
  specificResp = checkBodyData(uriPath, method, reqBdObj, mockresponses, entitySchema.responseDatatype);
@@ -687,7 +689,10 @@ function makeRequest(request, entitySchema, callProperties, startTrip, attempt,
687
689
  // add the data for each field into the form
688
690
  const mykeys = Object.keys(mybody);
689
691
  if (mykeys.length === 2 && mykeys[0] === 'file' && mykeys[1] === 'convertBase64ToBuffer') {
690
- const filePart = mybody[mykeys[0]].split(';');
692
+ let filePart = mybody[mykeys[0]];
693
+ if (typeof filePart === 'string') {
694
+ filePart = filePart.split(';');
695
+ }
691
696
  let fileName = null;
692
697
  // see if we have a filename that we should add to the formdata
693
698
  for (let p = 1; p < filePart.length; p += 1) {
@@ -710,11 +715,20 @@ function makeRequest(request, entitySchema, callProperties, startTrip, attempt,
710
715
  for (let k = 0; k < mykeys.length; k += 1) {
711
716
  if (mykeys[k] === 'file') {
712
717
  let fileVal = mybody[mykeys[k]];
713
- if (fileVal.indexOf('@') === 0) {
718
+ if ((typeof fileVal === 'string') && (fileVal.indexOf('@') === 0)) {
714
719
  // if there are multiple parts - first part is full path to file, other part can be name (starts with name=)
715
720
  const filePart = fileVal.split(';');
716
721
  let fileName = null;
717
- fileVal = fs.readFileSync(filePart[0].substring(1));
722
+
723
+ // get the path for the specific file
724
+ // const dataFile = path.join(__dirname, `/uploads/${filePart[0].substring(1)}`);
725
+ // const dataFile = path.join(__dirname, '/../uploads/filetoupload');
726
+ // Read the action from the file system
727
+ if (request.filePath) {
728
+ fileVal = fs.readFileSync(request.filePath);
729
+ } else {
730
+ fileVal = '';
731
+ }
718
732
 
719
733
  // see if we have a filename that we should add to the formdata
720
734
  for (let p = 1; p < filePart.length; p += 1) {
@@ -142,9 +142,40 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
142
142
  const origin = `${id}-restHandler-handleRestRequest`;
143
143
  log.trace(origin);
144
144
 
145
+ // copy the request so lint does not complain about update
146
+ const newReqObj = request;
147
+
148
+ // this is only something in Form data with files
149
+ if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'FORM') {
150
+ // need to convert request.body back to JSON
151
+ let mybody = newReqObj.body;
152
+ if (typeof mybody === 'string') {
153
+ try {
154
+ mybody = JSON.parse(newReqObj.body);
155
+ } catch (ex) {
156
+ log.debug('Rest Handler can not parse Form Body');
157
+ }
158
+ }
159
+ // set the filePath into the request object
160
+ const mykeys = Object.keys(mybody);
161
+ for (let k = 0; k < mykeys.length; k += 1) {
162
+ if (mykeys[k] === 'file') {
163
+ const itemVal = mybody[mykeys[k]];
164
+ if ((typeof itemVal === 'string') && (itemVal.indexOf('@') === 0)) {
165
+ const fileVal = itemVal;
166
+ if (fileVal.indexOf('@') === 0) {
167
+ const filePart = fileVal.split(';');
168
+ newReqObj.filePath = filePart[0].substring(1);
169
+ }
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ }
175
+
145
176
  try {
146
177
  // perform the request to get entity(ies)
147
- return connectorInst.performRequest(request, entitySchema, callProperties, (resObj, perror) => {
178
+ return connectorInst.performRequest(newReqObj, entitySchema, callProperties, (resObj, perror) => {
148
179
  if (perror) {
149
180
  let retError = null;
150
181
  const retErrorObj = perror;
@@ -219,13 +250,13 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
219
250
 
220
251
  if (entitySchema.responseObjects) {
221
252
  const responseKeys = entitySchema.responseObjects;
222
- const uriPath = request.origPath;
223
- const method = request.method.toUpperCase();
224
- const reqBody = request.body;
225
- const reqPath = request.path;
253
+ const uriPath = newReqObj.origPath;
254
+ const method = newReqObj.method.toUpperCase();
255
+ const reqBody = newReqObj.body;
256
+ const reqPath = newReqObj.path;
226
257
 
227
258
  // if there is a request body, see if there is something that matches a specific input
228
- if (reqBody && (!entitySchema || !entitySchema.requestDatatype
259
+ if (reqBody && (typeof reqBody === 'string') && (!entitySchema || !entitySchema.requestDatatype
229
260
  || entitySchema.requestDatatype.toUpperCase() === 'JSON' || entitySchema.requestDatatype.toUpperCase() === 'URLENCODE')) {
230
261
  let reqBdObj = null;
231
262
  if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "5.3.9",
3
+ "version": "5.3.10",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "postinstall": "node utils/setup.js",
Binary file