-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make DataView Grouping
compileAccumulatorLoop
CSP safe (#1295)
* feat: make DataView Grouping `compileAccumulatorLoop` CSP safe
- Loading branch information
1 parent
1984576
commit af82208
Showing
6 changed files
with
229 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
docs/column-functionalities/editors/Autocomplete-Editor-(Kraaden-lib).md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## CSP Compliance | ||
The library is now, at least mostly, CSP (Content Security Policy) compliant since `v4.0`, however there are some exceptions to be aware of. When using any html string as template (for example with Custom Formatter returning an html string), you will not be fully compliant unless you return `TrustedHTML`. You can achieve this by using the `sanitizer` method in combo with [DOMPurify](https://github.com/cure53/DOMPurify) to return `TrustedHTML` as shown below and with that in place you should be CSP compliant. | ||
|
||
> **Note** the default sanitizer in Slickgrid-Universal is actually already configured to return `TrustedHTML` but the CSP safe in the DataView is opt-in via `useCSPSafeFilter` | ||
```typescript | ||
import DOMPurify from 'dompurify'; | ||
import { Slicker, SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle'; | ||
|
||
// DOM Purify is already configured in Slickgrid-Universal with the configuration shown below | ||
this.gridOptions = { | ||
sanitizer: (html) => DOMPurify.sanitize(html, { RETURN_TRUSTED_TYPE: true }), | ||
// you could also optionally use the sanitizerOptions instead | ||
// sanitizerOptions: { RETURN_TRUSTED_TYPE: true } | ||
} | ||
this.sgb = new Slicker.GridBundle(gridContainerElm, this.columnDefinitions, this.gridOptions, this.dataset); | ||
``` | ||
with this code in place, we can use the following CSP meta tag (which is what we use in the lib demo, ref: [index.html](https://github.com/ghiscoding/slickgrid-universal/blob/master/examples/vite-demo-vanilla-bundle/index.html#L8-L14)) | ||
```html | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'nonce-random-string'; require-trusted-types-for 'script'; trusted-types dompurify"> | ||
``` | ||
|
||
#### DataView | ||
Since we use the DataView, you will also need to enable a new `useCSPSafeFilter` flag to be CSP safe as the name suggest. This option is opt-in because it has a slight performance impact when enabling this option (it shouldn't be noticeable unless you use a very large dataset). | ||
|
||
```typescript | ||
import DOMPurify from 'dompurify'; | ||
import { Slicker, SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle'; | ||
|
||
// DOM Purify is already configured in Slickgrid-Universal with the configuration shown below | ||
this.gridOptions = { | ||
// you could also optionally use the sanitizerOptions instead | ||
// sanitizerOptions: { RETURN_TRUSTED_TYPE: true } | ||
dataView: { | ||
useCSPSafeFilter: true | ||
}, | ||
} | ||
this.sgb = new Slicker.GridBundle(gridContainerElm, this.columnDefinitions, this.gridOptions, this.dataset); | ||
``` | ||
|
||
### Custom Formatter using native HTML | ||
We now also allow passing native HTML Element as a Custom Formatter instead of HTML string in order to avoid the use of `innerHTML` and stay CSP safe. We also have a new grid option named `enableHtmlRendering`, which is enabled by default and is allowing the use of `innerHTML` in the library (by Formatters and others), however when disabled it will totally restrict the use of `innerHTML` which will help to stay CSP safe. | ||
|
||
You can take a look at the original SlickGrid library with this new [Filtered DataView with HTML Formatter - CSP Header (Content Security Policy)](https://6pac.github.io/SlickGrid/examples/example4-model-html-formatters.html) example which uses this new approach. There was no new Example created in Slickgrid-Universal specifically for this but the approach is the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.