plotly / plotly/plotly.py

Output of renderer 'notebook' violates Content Security Policy

Open
#3,739 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3 security
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Setup description

We have plotly.py setup with pio.renderers.default = "notebook" and we use nbconvert 6.5 to convert executed notebooks to HTML reports with input cells stripped out. These HTMLs are served by a simple node.js front end that has Content Security Policies for script-src setup due to security requirements.

Issue description

The exported HTML contains inline script tags one of which has plotly.js and its dependencies. One of the dependencies seems to violate our script-src Content Security Policy as it is using eval(), new Function(), setTimeout([string], ...) and setInterval([string], ...) for evaluating strings Reference

CSP Error from Chrome:

  1. Content Security Policy of your site blocks the use of 'eval' in JavaScript`
    1. The Content Security Policy (CSP) prevents the evaluation of arbitrary strings as JavaScript to make it more difficult for an attacker to inject unathorized code on your site.

      To solve this issue, avoid using eval()new Function()setTimeout([string], ...) and setInterval([string], ...) for evaluating strings.

      If you absolutely must: you can enable string evaluation by adding unsafe-eval as an allowed source in a script-src directive.

      ⚠️ Allowing string evaluation comes at the risk of inline script injection.

    2. AFFECTED RESOURCES
      1. 1 directive
        1. Source Location Directive Status
          report:14743 script-src blocked
Screen Shot 2022-05-19 at 8 10 12 AM

Ask

Is there a way to provide plotly.py the ability to use the plotly.js strict bundle and hence avoid having to use dependencies that violate CSP?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the notebook renderer configured through pio.renderers.default = "notebook" and trace how it produces the exported HTML. Compare the embedded plotly.js dependencies with the plotly.js strict bundle referenced in the issue. Done means the notebook export works under the stated script-src policy without requiring unsafe-eval.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, python
Domain
data-visualization, frontend, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.