question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement non-eval based Vega execution path

See original GitHub issue

For security reasons, many modern web sites lock down their Content Security Policy with the script no-eval CSP rule, which prevents the new Function() code. Vega heavily relies on the dynamically generated expressions. While this may provide some performance benefits, it would be good to have a possibly-slower expression interpreter alternative (configurable).

As an experiment, I have created an alternative sandbox approach, but this might not be suitable to some complex apps: https://github.com/nyurik/csp-vega-test

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:9
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Jan 23, 2018

The (safe) use of a Function constructor underlies multiple Vega features, including not only expressions, but also compilation of visual encoding procedures. It’s unlikely that we (at UW) will focus efforts on building an alternative interpreter for these functions. However, we’re certainly open to reviewing 3rd party contributions.

In Vega 3, Function constructor calls arise due to a single line in the vega-runtime repository. Future extensions might start there, replacing the use of Function.apply with a custom JS parser/evaluator.

For background context, the Vega parser generates output JS code for expressions and visual encoders, included within an output dataflow graph description. The runtime (typically invoked from vega-view) parses this description into a dataflow instance, including instantiation of functions.

Given the effort and potential performance implications of such changes, I recommend first following a sandbox approach if feasible.

0reactions
dlalibertecommented, May 13, 2020

redesigns the encoders to run through the expression parser, such that all code generation will pass through the expression language framework.

This sounds like it will indeed be safer, but it will result in much more code being run through the expression language framework than is minimally necessary. That is what I am seeing after your changes to encode/entry.js:

const colorValue = (type, x, y, z) =>
  `(${type}(${[x, y, z].map(entry).join(',')})+'')`;

In my previous comment, I gave an example of how expressions which would be generated to create a color (like that one) could instead be factored out into a function (makeColorStyle) that could be pre-compiled as part of the library. This would also be just as safe as running the equivalent expression text through the expression language framework, but it would result in much faster runtime performance since the interpreter would not have to be operating over that part of the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Path Mark | Vega
Property Type Description x Number The primary x‑coordinate in pixels. x2 Number The secondary x‑coordinate in pixels. width Number The width of the mark in pixels,...
Read more >
Vega Vulnerability Scanner - Subgraph OS
Vega can help you find and validate SQL Injection, Cross-Site Scripting (XSS), inadvertently disclosed sensitive information, and other vulnerabilities. It is ...
Read more >
Drugs, abuse and a drive to kill: Zane Floyd's path to Nevada ...
The jury found Floyd guilty of four first-degree murders with use of a ... In the 1980s and '90s, drugs were commonplace in...
Read more >
The Twisted Path to Oklahoma's Looming Execution Spree
One week before he was killed in the death chamber at the Oklahoma State Penitentiary, Donald Grant asked a woman named Sue Hosch...
Read more >
South Carolina Supreme Court halts state's plan for firing ...
Though Moore elected execution by firing squad earlier this month, ... South Carolina is one of eight states that still use the electric ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found