Giter VIP home page Giter VIP logo

Comments (3)

jejacks0n avatar jejacks0n commented on July 18, 2024 8

I had adjusted the config/content_security_policy.rb and disallowed inline script tags. I had to adjust the enable them in development.

Here's more or less what I ended up with in case anybody else ends up in this same place since it's actually a recommended step when setting up webpacker and vue with rails.

Rails.application.config.content_security_policy do |policy|
  if Rails.env.development?
    policy.script_src :self, :https, :unsafe_eval, :unsafe_inline
  else
    policy.script_src :self, :https
  end
end

from graphiql-rails.

sambostock avatar sambostock commented on July 18, 2024 2

I'm investigating addressing the root cause of needing 'unsafe-eval' in the CSP, but I want to share an alternative workaround for the time being:

if defined?(GraphiQL::Rails)
  # While the gem is loaded up front, its controller is autoloaded.
  # Therefore we must ensure our patch runs after loading, every time.
  Rails.autoloaders.main.on_load("GraphiQL::Rails::EditorsController") do
    GraphiQL::Rails::EditorsController.content_security_policy do |policy|
      policy.script_src(*policy.script_src, :unsafe_eval)
    end
  end
end

Rather than add 'unsafe-eval' to the entire host app's CSP, this only adds it to the relevant controller.

If for some reason it is impossible to address the unsafely eval'ing JS in GraphiQL itself (e.g. new Function("return this;")), then we can update this gem to do the controller level CSP change itself, but ideally we'll fix it upstream.

from graphiql-rails.

philiplambok avatar philiplambok commented on July 18, 2024

Thank you @jejacks0n

from graphiql-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.