Reputation: 3
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
Upvotes: 0
Views: 777
Reputation: 36
You need to make sanitizer: DomSanitizer
as private to make it accessible in code as : private sanitizer: DomSanitizer
Upvotes: 2