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

When JS contains a large number of commented code, the CPU is not released due to sandbox regular matching. Is there any good way to remove the commented code? #130

Open
MrLi2018 opened this issue Aug 24, 2022 · 1 comment

Comments

@MrLi2018
Copy link

The JS content is as follows:
//
// return main();
//
// function main() {
// return getResource_name(context.test.data[0]);
// }
//
// function getResource_name(node) {
// var params = {
// resourceType: "test",
// test: {
// logOp: "and",
// test: [{
// name: "type_id",
// operator: "equal",
// value: "5"
// }, {
// name: "test",
// operator: "equal",
// value: node
// }],
// complex: null
// }
// })
// };
// if (isNull(results)) {
// return currentValue;
// }
// var resIdArr=[];
// for (var i in results) {
// resIdArr.push(results[i]);
// }
// return resIdArr[0].test;
// }
//
// function isNull(value) {
// if (value === null || value === undefined) {
// return true;
// }
// var valstr = value.toString();
// if (valstr === 'null' || valstr === 'undefined' || valstr === '' || valstr == '{}' || valstr == '[]') {
// return true;
// }
// return false;
// }
// var LOGPREFIX = '[test] test';
// var phyOrVmList = [];
// try {
// main();
// } catch (e) {
//
// }
// return phyOrVmList;
//
// function main() {
// var neName = context.test.;
// var neName = context.test;
// phyOrVmList = queryPhyVmName('test');
// }
//
// function queryPhyVmName(neName) {
// var params = {
// resourceType: "test",
// selectFields: ["test"]
// };
// params.condition = buildCondition(neName);
// var list = [];
// if (results != null && results != undefined && results.size() > 0) {
// for (var i = 0; i < results.size(); i++) {
// var temp = results.get(i).Value.split(",");
// list = list.concat(temp);
// }
// }
// return list.sort();
// }
//
// function buildCondition(neName) {
// filter: {
// logOp: "and",
// simple: [{
// name: "test",
// operator: "in",
// value: ["test", "test", "test"]
// }, {
// name: "test",
// operator: "equal",
// value: neName
// }, {
// name: "Field",
// operator: "in",
// value: ["test", "test"]
// }],
// complex: null
// }
// });
// }
return ['aa','bb'];
The CPU information is as follows:

image
Monitoring finds that regular matching is being performed:
4D9D5ECB-09A1-4B9B-80C2-C69E2E95BC0F

@mxro
Copy link
Collaborator

mxro commented Aug 24, 2022

Thank you for raising this issue!

Maybe you could use logic as the following to apply to the code before submitting it to the Sandbox: https://github.com/javadelight/delight-nashorn-sandbox/blob/master/src/main/java/delight/nashornsandbox/internal/RemoveComments.java ?

As far as I see, that should already be applied before injectInterrputionCalls:

https://github.com/javadelight/delight-nashorn-sandbox/blob/master/src/main/java/delight/nashornsandbox/internal/JsSanitizer.java#L281

So maybe either this logic is not working correctly or there is some other issue in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants