So I have a simple app where a user can insert a URL into an iframe window. Problem is this allows for html injection which screws up the display.
Is there a simple way to prevent this from happening? Like a regex escape function etc?
TS/JS code for iframe window:
public renderPlot(): void {
let ht: string = '';
let url: string = this.configPBg[EConfigPKeys.IFrameAddress];
if (url == undefined || url.length === 0) {
this.renderWarningMessage('No valid address configured');
return;
}
// auto stream with url like this : https://www.youtube.com/embed/jdnhfg?&autoplay=1&mute=1
ht += '<iframe width="' + this.chartWindowSize.width + '" height="' + this.chartWindowSize.plotHeight + '" ';
ht += 'src="' + url + '" ';
ht += 'frameborder="0" ';
ht += '>';
ht += '</iframe>';
I tried adding this but failed to catch anything:
url.replace(/</g, "<").replace(/>/g, ">");
the URL entry form looks like this: