Original Message:
Sent: Mon February 20, 2023 07:07 AM
From: Steve Linn
Subject: JSON SQL injection attack prevention using gatewayscript
Hi Vyasavardhan,
For your error:
Cannot read property 'match' of undefined at Object.<anonymous> (local:///SQL-json.js:48:16)'
The match function is part of a string object, but the variable you're doing the match is undefined per the error message, ie,
var input = context.get('request.body');var match = input.match(regexp); // if input is undefined this will generate the same error.
I'm not sure how you are populating your input variable. Checking for a valid input prior to doing the match is one way to avoid this error, for example, if you had an HTTP GET operation you may not have an input
var input = context.get('request.body');if (input) { var match = input.match(regexp); // if input has been checked to be defined so this will not create this error}
Best Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Mon February 20, 2023 06:55 AM
From: Vyasavardhan Ramagiri
Subject: JSON SQL injection attack prevention using gatewayscript
We tried but got the following error.
GatewayScript processing Error 'TypeError: Cannot read property 'match' of undefined In file 'local:///SQL-json.js' line:48, stack:TypeError: Cannot read property 'match' of undefined at Object.<anonymous> (local:///SQL-json.js:48:16)'
Unable to open the script module file 'match'
Please help us to achieve this.
Thanks in Advance!!
------------------------------
Vyasavardhan Ramagiri
Original Message:
Sent: Fri February 17, 2023 03:41 PM
From: Steve Linn
Subject: JSON SQL injection attack prevention using gatewayscript
Hi Vyasavardhan,
Assuming input is a string, input.includes doesn't take a regex as an argument.
Try
var match = input.match(regexPattern);
If it finds a match you'll have an array of the matched string in the first array element, and any capture group in the regex will be shown in the subsequent array elements. If no match a null is returned.
Best Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM