Skip to content

Commit

Permalink
[OGUI-1428] Remove usage of eval from front-end (#2151)
Browse files Browse the repository at this point in the history
* removes the usage of `eval` in InfoLogger project and passes the functions to backend as string
  • Loading branch information
graduta authored Oct 5, 2023
1 parent a776199 commit c126061
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions InfoLogger/public/log/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export default class Log extends Observable {
}
if (this.filter.setCriteria(field, operator, value)) {
if (this.isLiveModeRunning()) {
this.model.ws.setFilter(this.model.log.filter.toFunction());
this.model.ws.setFilter(this.model.log.filter.toStringifyFunction());
this.model.notification.show(
`The current live session has been adapted to the new filter configuration.`, 'primary', 2000);
} else if (this.isActiveModeQuery()) {
Expand Down Expand Up @@ -415,7 +415,7 @@ export default class Log extends Observable {
// kill this interval when live mode is off
this.liveInterval = setInterval(this.notify.bind(this), 1000);

this.model.ws.setFilter(this.model.log.filter.toFunction());
this.model.ws.setFilter(this.model.log.filter.toStringifyFunction());

this.notify();
}
Expand Down
5 changes: 2 additions & 3 deletions InfoLogger/public/logFilter/LogFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class LogFilter extends Observable {
* Output of function is boolean.
* @return {function.<WebSocketMessage, boolean>}
*/
toFunction() {
toStringifyFunction() {
/**
* This function will be stringified then sent to server so it can filter logs
* 'DATA_PLACEHOLDER' will be replaced by the stringified filters too so the function contains de data
Expand Down Expand Up @@ -283,8 +283,7 @@ export default class LogFilter extends Observable {
const criteriasJSON = JSON.stringify(this.criterias);
const functionAsString = filterFunction.toString();
const functionWithCriterias = functionAsString.replace('\'DATA_PLACEHOLDER\'', criteriasJSON);
const functionPure = eval(`(${functionWithCriterias})`);
return functionPure;
return functionWithCriterias;
}

/**
Expand Down

0 comments on commit c126061

Please sign in to comment.