Skip to content

Commit

Permalink
Revert "ELEMENTS-1759: Remove usage of unsafe-eval from CSP"
Browse files Browse the repository at this point in the history
This reverts commit 02beb92.
  • Loading branch information
alokhyland authored Oct 30, 2024
1 parent 02beb92 commit 28f7067
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions ui/nuxeo-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
import '@polymer/polymer/polymer-legacy.js';

import '@nuxeo/nuxeo-elements/nuxeo-element.js';
import { config } from '@nuxeo/nuxeo-elements';
import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
import { microTask } from '@polymer/polymer/lib/utils/async.js';
import { enqueueDebouncer } from '@polymer/polymer/lib/utils/flush.js';
Expand Down Expand Up @@ -184,25 +185,29 @@ import Interpreter from './js-interpreter/interpreter.js';
let res = false;

try {
const js = new Interpreter(expression, (interpreter, scope) => {
// set scope
interpreter.setProperty(scope, 'this', interpreter.nativeToPseudo(FiltersBehavior));
Object.entries({ document, user }).forEach(([k, obj]) => {
const v = {};
// filter out private properties
Object.getOwnPropertyNames(obj)
.filter((p) => !p.startsWith('_'))
.forEach((p) => {
v[p] = obj[p];
});
interpreter.setProperty(scope, k, interpreter.nativeToPseudo(v));
if (!config.get('expressions.eval', true)) {
const js = new Interpreter(expression, (interpreter, scope) => {
// set scope
interpreter.setProperty(scope, 'this', interpreter.nativeToPseudo(FiltersBehavior));
Object.entries({ document, user }).forEach(([k, obj]) => {
const v = {};
// filter out private properties
Object.getOwnPropertyNames(obj)
.filter((p) => !p.startsWith('_'))
.forEach((p) => {
v[p] = obj[p];
});
interpreter.setProperty(scope, k, interpreter.nativeToPseudo(v));
});
// XXX: 'this' in the scope of native functions is the interpreter instance
Object.assign(interpreter, FiltersBehavior);
});
// XXX: 'this' in the scope of native functions is the interpreter instance
Object.assign(interpreter, FiltersBehavior);
});
js.run();
res = js.value;

js.run();
res = js.value;
} else {
const fn = new Function(['document', 'user'], `return ${expression};`);
res = fn.apply(this, [document, user]);
}
return res;
} catch (err) {
console.error(`${err} in <nuxeo-filter> expression "${expression}"`);
Expand Down
4 changes: 2 additions & 2 deletions ui/viewers/pdfjs/web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

<!-- This snippet is used in production (included from viewer.html) -->
<link rel="resource" type="application/l10n" href="locale/locale.json">
<script src="../build/pdf.mjs" type="module" nonce="dummy"></script>
<script src="../build/pdf.mjs" type="module"></script>

<link rel="stylesheet" href="viewer.css">

<script src="viewer.mjs" type="module" nonce="dummy"></script>
<script src="viewer.mjs" type="module"></script>
</head>

<body tabindex="1">
Expand Down

0 comments on commit 28f7067

Please sign in to comment.