kartik-v / bootstrap-fileinput

An enhanced HTML 5 file input for Bootstrap 5.x/4.x./3.x with file preview, multiple selection, and more features.
http://plugins.krajee.com/file-input
Other
5.35k stars 2.4k forks source link

Fix compliance with CSP not having `unsafe-inline` policy #1833

Closed reckart closed 3 months ago

reckart commented 1 year ago

Prerequisites

Steps to reproduce the issue

  1. Load the latest bootstrap-fileinput 5.5.2 in a browser on a page that enables CSP but not unsafe-inline

Expected behavior and actual behavior

Errors in the JavaScript console related to using inline styles. They are triggered by calls to JQuery's parseHTML and innerHTML functions from within fileinput.js.

I was expecting that fileinput.js should work without unsafe-inline, in particular since https://github.com/kartik-v/bootstrap-fileinput/issues/1565 has been closed.

Environment

Browsers

Operating System

Libraries

Isolating the problem

kartik-v commented 3 months ago

I do not have a current test environment to test this use case. Could you please share the lines from the plugin code in which the CSP policy error is showing up?

kartik-v commented 3 months ago

Updated with a fix to address most issues (kindly recheck and let know). You may need to also reconfigure your CSP policy to allow scripts from libraries like JQUERY (using a nonce for example) - so that jquery internal functions like parseHTML do not cause a CSP error.