Skip to content

Commit

Permalink
More sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
randywoods1 committed Sep 10, 2024
1 parent b1150ee commit 6748f2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<th colspan="2">Specific Component Name</th>
</tr>
<tr *ngFor="let q of questions; let i = index">
<td>{{ utilitiesSvc.removeHtmlTags(q.componentName, true) }}</td>
<td>{{ utilitiesSvc.removeHtmlTags(q.componentName) }}</td>
<td>
<div class="btn-group btn-group-toggle answer-group" data-toggle="buttons" style="float:right;">
<label *ngIf="showThisOption('Y')" class="btn btn-yes form-check-label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ComponentQuestionListComponent implements OnInit, OnChanges {
*/
ngOnChanges(): void {
this.data.forEach(x => {
x.componentName = this.utilitiesSvc.removeHtmlTags(x.componentName, true);
x.componentName = this.utilitiesSvc.removeHtmlTags(x.componentName);
});
}
}
13 changes: 11 additions & 2 deletions CSETWebNg/src/app/services/utilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,24 @@ export class Utilities {
/**
*
*/
public removeHtmlTags(input: string, replaceWithSpace: boolean): string {
public removeHtmlTags(input: string): string {

// convert <br> tag to space to avoid words smashed together in output
input = input.replace(/<br[^>]*>/g, ' ');

const div = document.createElement('div');
div.innerHTML = input;

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
input = div.textContent || div.innerText;


// Remove script tags first to prevent potential XSS attacks
input = input.replace(/<script[^>]*?>.*?<\/script>/gi, '');

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.

Check failure

Code scanning / CodeQL

Bad HTML filtering regexp High

This regular expression does not match script end tags like </script >.

// Remove style tags to avoid unwanted formatting
input = input.replace(/<style[^>]*?>.*?<\/style>/gi, '');

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<style
, which may cause an HTML element injection vulnerability.

// Remove all other HTML tags and attributes
input = input.replace(/<[^>]*>/g, replaceWithSpace ? ' ' : '');
input = input.replace(/<[^>]*>/g, '');

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.

return input;
}
Expand Down

0 comments on commit 6748f2a

Please sign in to comment.