Skip to content

Commit

Permalink
Identify CSP test functions (elastic#184456)
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego authored May 30, 2024
1 parent 71ea578 commit 3e44cca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export const Template: FunctionComponent<Props> = ({
</div>

<script>
{`
{`// kbnUnsafeInlineTest do not remove this comment:
// it is used for filtering out expected CSP failures, and must be the first piece of content in this script block.
// Since this is an unsafe inline script, this code will not run
// in browsers that support content security policy(CSP). This is
// intentional as we check for the existence of __kbnCspNotEnforced__ in
Expand Down
4 changes: 3 additions & 1 deletion packages/kbn-handlebars/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export function transformLiteralToPath(node: { path: hbs.AST.PathExpression | hb

export function allowUnsafeEval() {
try {
new Function();
// Do not remove the `kbnUnsafeEvalTest` parameter.
// It is used for filtering out expected CSP failures, and must be the first piece of content in this function.
new Function('kbnUnsafeEvalTest', 'return true;');
return true;
} catch (e) {
return false;
Expand Down

0 comments on commit 3e44cca

Please sign in to comment.