Skip to content

Commit

Permalink
✨ Added checks for window object access in template strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgrozav committed May 24, 2022
1 parent 680c968 commit 567f85d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/workflow/src/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ export class Expression {

// @ts-ignore
data.document = {};
data.global = {};
data.window = {};
data.Window = {};
data.this = {};
data.alert = {};

// Prevent Remote Code Execution
data.eval = {};
data.setTimeout = {};
data.setInterval = {};
data.Function = {};

// Prevent requests
data.fetch = {};
data.XMLHttpRequest = {};

// @ts-ignore
data.DateTime = DateTime;
Expand All @@ -129,8 +144,18 @@ export class Expression {

// Execute the expression
try {
if (
parameterValue.includes('window') &&
!/([a-zA-Z.]window|window[a-zA-Z]|['"](?!\s*[\\+\-*/|]+\s*)[^'"]*window)/g.test(
parameterValue,
)
) {
throw new Error(`window is not allowed`);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
const returnValue = tmpl.tmpl(parameterValue, data);

if (typeof returnValue === 'function') {
throw new Error('Expression resolved to a function. Please add "()"');
} else if (returnValue !== null && typeof returnValue === 'object') {
Expand Down Expand Up @@ -368,6 +393,7 @@ export class Expression {
if (parameterValue === null || parameterValue === undefined) {
return parameterValue;
}

// Data is an object
const returnData: INodeParameters = {};
// eslint-disable-next-line no-restricted-syntax
Expand All @@ -381,6 +407,7 @@ export class Expression {
if (returnObjectAsString && typeof returnData === 'object') {
return this.convertObjectValueToString(returnData);
}

return returnData;
}
}

0 comments on commit 567f85d

Please sign in to comment.