formio / angular

JSON powered forms for Angular
https://formio.github.io/angular-demo
MIT License
623 stars 465 forks source link

[BUG] Getting error while loading form using form-builder - unsafe-eval #1081

Open vinayrdy966 opened 1 week ago

vinayrdy966 commented 1 week ago

Steps to Reproduce

  1. Just include this meta tag in index.html <meta http-equiv="content-security-policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data:; media-src 'self' data: blob:; object-src 'self' data:; frame-src 'none'; upgrade-insecure-requests" />

angular template: <form-builder class="custom-form-builder" [form]="form" [options]="options"

image
vinayrdy966 commented 3 days ago

If I replace this exiting code which is causing eval error in evaluator.js try { // Ensure we handle copied templates from the ejs files. _template = _template.replace(/ctx\./g, ''); return Evaluator.cache[hash] = _lodash["default"].template(_template, Evaluator.templateSettings); } catch (err) { console.warn('Error while processing template', err, _template); }

with this code I am able to resolve this issue. `try { _template = _template.replace(/ctx./g, ''); // Simple manual interpolation without using eval const context = { / context values / }; _template = _template.replace(/{{\s([^{}\s])\s*}}/g, (match, p1) => { return context[p1] || ''; });

Evaluator.cache[hash] = _template; return _template; } catch (err) { console.warn('Error while processing template', err, _template); }`