The warning message is thrown when trying to bind to 'style.grid' because the style value is being sanitized as unsafe

I am in the process of developing a system to define and calculate my own reusable grids. Here is an example of the output:

[left-bleed-start] 10.245000000001024px [left-bleed-end content-col-start] 1331.8500000001332px [content-col-end right-bleed-start] 10.245000000001024px [right-bleed-end]/[top-bleed-start] 10.245000000001024px [top-bleed-end link-row-start] 81.9600000000082px [content-row-end footer-row-start] 163.9200000000164px [footer-row-end bottom-bleed-start] 10.245000000001024px [bottom-bleed-end]

When implementing it as follows:

<div class="appCompGrid" [style.grid]="Grid.GridCode"></div>

I encounter a sanitation warning. However, if I manually enter the code like this:

<div class="appCompGrid" style="grid: (same code);"></div>

everything works fine. The CSS class is where I set the display as grid to ensure consistency across different screen sizes. I tried adding + ';' at the end of the grid code assembly function, thinking it might resolve the issue, but the error persists. Inline application of display: grid; was also tested to rule out conflicts between CSS classes and inline styles.

I am using @HostListener to recalibrate the grid when size or orientation changes without issues in Angular. Not sure why this warning is triggered. Below are my component classes:

Base Class

export class GridBuilder {
    Settings : GridInit        = new GridInit();
    GridData : Array<GridType> = new Array();
    Grid     : GridOutput      = new GridOutput();


    constructor() { this.GridData = GridDefs; }

    public buildGrid() {
        const coreSettings : GridInit   = this.Settings;
        const gridData     : GridType[] = this.GridData;

        const w: number     = multiply( coreSettings.Size.Width,  coreSettings.Size.PixelRatio );
        const h: number     = multiply( coreSettings.Size.Height, coreSettings.Size.PixelRatio );
        const o: string     = checkOrientation( w, h );
        const c: CellSpecs  = calcCell( o, w );
        const t: GridType   = gridData.find( a => a.GridName == coreSettings.GridStyle );

        const cols: string  = calcArea( t.Columns, c );
        const rows: string  = calcArea( t.Rows, c );

        this.Grid.GridCode  = cols + '/' + rows + ';';
        this.Grid.GridAreas = t.Areas;
    }
}

Secondary class for app component/ any top-tier container

export class SiteGrid extends GridBuilder {

    constructor(){
        super();
        this.applySizeSettings();
    }

    applySizeSettings(){
        this.Settings.Size.Width       = window.innerWidth;
        this.Settings.Size.Height      = window.innerHeight;
        this.Settings.Size.PixelRatio  = window.devicePixelRatio;
    }
}

The AppComponent

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent extends SiteGrid {
    title = 'app';

    @HostListener( 'window: resize', [ '$event' ] )onResize( event ){ this.applySizeSettings(); this.buildGrid(); }

    constructor(){
        super();
        this.Settings.GridStyle = 'SiteGridA';
        this.buildGrid();
    }
}

This flow may not directly relate to the warning issue, but I included it for context. Any insights on why this warning is popping up?

Answer №1

To ensure the security of your CSS, it is essential to incorporate a sanitizer into your code or find a way to work around it...

constructor(private secureSanitizer: DomSecure) {
    this.securedCSS = secureSanitizer.bypassSecurityTrustStyle(Grid.GridCode);
  }

If you are curious about the importance of this practice, you can check out this informative article and refer to the official documentation on DomSecurer.

The DomSecurer plays a crucial role in preventing Cross Site Scripting Security vulnerabilities (XSS) by cleansing values for safe usage within various DOM environments.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React-Native-Web generates default classes for inline styles and erroneously applies them in a jumbled sequence

Currently working on a project involving react native web and NextJS. I have encountered an issue with inline styles in React that seems to be caused by RN-Web. It appears that there is a mechanism within the framework that automatically generates classes ...

Is there a way to prevent inheriting width properties? Or perhaps how can one revert back to the original width value

After installing the Thank you plugin, I noticed that the button on my test site appears to be strange. Upon further investigation, I discovered that it is inheriting #commentform textarea { width: 45%; } from my theme. While removing the width in the CSS ...

Tips for automatically adjusting the height of the footer

Is there a way to dynamically adjust the height of the footer based on the content length inside the body? I've been exploring solutions like setting the position of the footer as "fixed," but it seems to stay at the bottom of the screen, which is no ...

Error: Unused variable: '_' has been declared but not utilized

While working on my Next.JS project with TypeScript, I encountered an issue when trying to run the build. The error message stated: Type error: '_' is declared but its value is never read. I attempted to resolve this by setting "noUnusedLocals" ...

Exploring the capabilities of using the injectGlobal API from styled-components in a TypeScript

I've been attempting to utilize the simple injectGlobal API, but I am encountering difficulties getting it to work with TypeScript. Here is my setup in theme.tsx: import * as styledComponents from "styled-components"; import { ThemedStyledComponentsM ...

Angular select elements connected through data binding

I am working on selecting values in an Angular application. Specifically, I want to establish a connection between two select elements so that changing the value of one will also change the value of the other. <select class="form-control" id="example ...

What is the best way to align a dropdown menu and a textbox on the same line

I have recently been working on a search bar that includes a Dropdown for Location and a Textbox for Search. Prior to implementing bootstrap, these elements were displayed in a single line. However, after applying bootstrap, they are now stacked vertically ...

Tips for making a div with a single triangular side using Reactjs

Hey there, I'm looking to design a header similar to the one shown in this image. Can someone provide guidance on how I can achieve this UI using React.js? https://i.sstatic.net/zmW5x.jpg ...

centered shape-outside within a div

I'm looking to create a layout with paragraphs displayed in columns, with a middle paragraph centered within the parent div. The text of the paragraphs should wrap around the middle paragraph with some margin. Check out the reference photo Below is ...

"Enhance Your Website with Boostrap Inputs and a Stylish

After changing my navbar to a full-width navbar, the width of my input div and ul with icons also changed. I have tried many solutions but am unable to fix the problem. I suspect that using a container to center the content in the navbar may be causing the ...

The key to highlighting the search terms in bold format

How can I highlight the search terms entered by users in the search box? I want all keywords in every search result to be bolded. For example, when a search term is entered and the results page displays all results with the typed term in bold within each ...

Strategies for Increasing Index Values in JavaScript

I attempted to modify the data attribute in my code snippet below. After clicking on the square, the data attribute should be incremented. However, it appears that the incrementing is not happening as expected. How can I resolve this issue? Additionall ...

Steps for incorporating a scrollbar into the context menu of CKEditor

I am working on adding items to a context menu. However, when too many items are added, they overflow onto the ckeditor area. To solve this issue, I want to implement a scroll bar for the context menu. editor.addMenuItem(suggestionBoxItem, ...

Error: Identical div IDs detected

<div id="tagTree1" class="span-6 border" style='width:280px;height:400px;overflow:auto;float:left;margin:10px; '> <a class="tabheader" style="font-size:large">Data Type</a><br /> <div class="pane">Refine sea ...

Modify the current link's <li> class

I am facing an issue with the code below which is supposed to change the class of li based on whether the browser URL matches the href attribute within that li. The current problem I am encountering is that the code changes the class for all li elements, ...

How can the panel within an accordion be enlarged or minimized?

Currently, I am implementing an accordion feature with the option to expand or collapse all panels using two buttons. My goal is to allow users to manage each panel within the accordion individually. However, I have encountered an issue that needs attenti ...

Enhancing Option Element Height with Padding in Bootstrap 5

Is there a way to adjust the height or increase padding of the option element within a standard select box using Bootstrap 5? More information can be found at: https://getbootstrap.com/docs/5.0/forms/select/ Could you provide an example code to demonstrat ...

Insufficient availability of courses in the Back Tick platform

function Home() { let displayCards = Galeyre.map((item) => { return ` <div class="card_container"> <div class="card"> <div class="face-side"> & ...

Ways to update property values of an array object in JavaScript

I am trying to match values from one array object with another array and update the status if there is a match. Here's the desired output for arrObj: [ { name: "Test1", status: true }, { name: "Test2", status: false }, { name: "Test3", s ...

Raising css properties using jquery

Is there a way to adjust CSS values using jQuery? I am looking to specifically increase values like top and left, but my current attempt is not producing the desired outcome: var left = 5; $(.object).css("left" + 5); The challenge I am facing is that I ...