0

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(window.location.search)

My complete code-:

Utils.ts

 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 (window.location.search) {
            const search = new URLSearchParams(Utils._sanitize.bypassSecurityTrustUrl(window.location.search));
            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

1 Answer 1

2

You need to make sanitizer: DomSanitizer as private to make it accessible in code as : private sanitizer: DomSanitizer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.