Skip to content

CSP compatibility: inline styles/scripts and event handlers require disabling strict Content Security Policy #36

@yann120

Description

@yann120

Hi,

First: thanks for the gem. I tested solid_queue_monitor as a possible replacement for mission_control-jobs in a Rails app, and the feature set looks very good.

I ran into one integration issue: the current UI is not compatible with a strict Content Security Policy.

My app uses a CSP similar to:

config.content_security_policy do |policy|
  policy.default_src :self
  policy.font_src    :self
  policy.img_src     :self, :data
  policy.object_src  :none
  policy.script_src  :self
  policy.style_src   :self
end

config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
config.content_security_policy_nonce_directives = ["script-src", "style-src"]

With that setup, solid_queue_monitor loads but the UI is broken because the browser blocks:

  • inline <style> tags
  • inline <script> tags
  • inline event handlers like onclick / onchange
  • runtime inline style mutations via element.style.*

From what I saw locally, this comes from the current self-contained rendering approach:

  • CSS generated inline
  • JS generated inline
  • some presenters using inline handlers
  • some JS toggling visibility/opacity with direct inline styles

My current workaround is to disable CSP only for the monitor controller:

Rails.application.config.to_prepare do
  SolidQueueMonitor::ApplicationController.content_security_policy false
end

This works for evaluation and internal tooling, but it weakens defense in depth for that interface, so it is not ideal as a long-term solution.

Would you be open to discussing a CSP-compatible mode or refactor?
Possible directions:

  • move CSS to an engine stylesheet asset
  • move JS to engine JS assets
  • replace inline event handlers with addEventListener
  • replace element.style.* mutations with CSS classes
  • optionally keep the current self-contained mode as a fallback for API-only / zero-setup installs

I understand why the gem is implemented this way: it makes installation extremely simple and keeps the UI self-contained. But CSP compatibility seems important for production Rails apps with stricter security defaults.

If this direction sounds reasonable, I’d be happy to help narrow down the incompatible pieces more precisely.

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions