Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSP not compatible if the Grid's column widths are defined #7434

Closed
martintabakov opened this issue Jul 13, 2023 · 2 comments
Closed

CSP not compatible if the Grid's column widths are defined #7434

martintabakov opened this issue Jul 13, 2023 · 2 comments
Assignees

Comments

@martintabakov
Copy link
Contributor

Bug report

A directive violation error occurs if you try to use CSP when the Grid's columns widths are defined.

Reproduction of the problem

  1. Run the attached project with http-server
  2. Open the browser console
    test1.zip

Current behavior

A dozen of errors are thrown on the console

Expected/desired behavior

No errors should be thrown

Environment

  • Kendo UI version: 2023.2.606
  • Browser: [all]
@github-actions github-actions bot added the FP: Unplanned Sync status with associated Feedback Item label Jul 13, 2023
@martintabakov martintabakov changed the title CSP not compatible with if the Grid's column widths are defined CSP not compatible if the Grid's column widths are defined Jul 13, 2023
@Iankodj Iankodj self-assigned this Jul 13, 2023
@github-actions github-actions bot added FP: Planned Sync status with associated Feedback Item and removed FP: Unplanned Sync status with associated Feedback Item labels Jul 13, 2023
@github-actions github-actions bot added FP: Completed Sync status with associated Feedback Item and removed FP: Planned Sync status with associated Feedback Item labels Jul 14, 2023
@kahanam
Copy link

kahanam commented Jul 24, 2023

Is it possible to see what fix was for this issue? It may help me understand and solve some of my own CSP issues.

@Iankodj
Copy link
Contributor

Iankodj commented Jul 25, 2023

@kahanam The fix is related to removing the unsafe-inline value of the style-src directive (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src).

Such issues are related when using style attribute for decoration instead of properties. And the solution for this (and for all similar situations) is to move any style attribute assigns to style property assigns.

In the case of jQuery this would be:

Not CSP compatible:

    $("<span style='background-color: red;'>span</span>").appendTo(document.body);

CSP compatible:

    $("<span>span</span>").css("background-color", "red").appendTo(document.body);

And without jQuery:

Not CSP compatible:

    const span = document.createElement('span');
    span.innerText = "span";
    span.setAttribute("style", "background-color: red;");
    document.body.appendChild(span);

CSP compatible:

    const span = document.createElement('span');
    span.innerText = "span";
    span.style.backgroundColor = "red";
    document.body.appendChild(span);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants