Angular 7 How To Access Domsanitizer Object inside a static function


I am trying to resolve the checkmarx issue which says application embeds untrusted data in the generated output.This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.So to prevent this I am using Angular 7 Domsanitizer. So the checkmarx error appear on this line

const search = new URLSearchParams(

My complete code-:


 import { DomSanitizer } from '@angular/platform-browser';

export class Utils {

    static _sanitize:any;
    constructor(private cookieService: CookieService,sanitizer: DomSanitizer) { 
          Utils._sanitize = sanitizer

static getParam(param: string): string | null {
        if ( {
            const search = new URLSearchParams(Utils._sanitize.bypassSecurityTrustUrl(;
            const value = search.get(param);
            return value && value !== 'null' && value !== 'undefined' ? value : null;
        return null;

But in this case I am getting error that bypassSecurityTrustUrl is not defined as inside the static function DomSanitizer object is not obtained.
Also I cannot pass Utils._sanitizer in params as this function is accessed by many files in complete project. Please help and give some suggestions

Source: Angular Questions


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us