react-remove-scroll: Violates safe CSPs because of dependency applying style tags

I originally submitted this issue at https://github.com/reach/reach-ui/issues/469, which uses your library as a dependency in their Dialog component.

react-remove-scroll has a dependency called react-style-singleton, of which you are also the author.

My understanding is react-style-singleton creates and modifies inline style tags after application mount. This is somewhat unsafe and if you are using a Content Security Policy (CSP), I don’t think there is any way for this library to work as expected without allowing style-src 'unsafe-inline'.

Here is the trace from my CSP error: image

I may be completely missing a secure way to handle this problem.

Thoughts?

Cheers.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 24 (9 by maintainers)

Most upvoted comments

Posting to keep the issue from closing.

Thanks @TheThirdRace. I was looking at CSP rule details and it was clear that neither inline <style/> nor style="" would just work and totally missed the .style option.

And so for the second option one can use css-variable set via js + static style provided as pure css. Combine the best of both words.

That is a very interesting solution and I don’t see any reason why it can’t be implemented. The underlaying react-remove-scroll-bar is doing many things - https://github.com/theKashey/react-remove-scroll-bar/blob/master/src/component.tsx#L17 - but actually it just needs to mend body only style, and the functionality for “other exposed class names” is already duplication by cssVariable, which works way better and gives more control.

Proposal:

  • release a v2 for react-remove-scroll-bar, with all code made imperative, removing all unnecessary functionality
  • use version resolution to replace v1 by v2 and test how it’s working for some particular use case.
  • update this package and reach-ui. The latter should be safe, as “extra functionality” is not used (while it should).