Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions apps/gateway/src/interceptors/sanitize.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,36 @@ export class SanitizeInterceptor implements NestInterceptor {
*/

private sanitizeString(value: string): string {
let sanitized = value;
let previous: string;

do {
previous = sanitized;

sanitized = sanitized
/**
* ========================================================
* Script Tag Neutralization
* ========================================================
*/

.replace(/<script.*?>.*?<\/script>/gi, '')

/**
* ========================================================
* Dangerous Inline Event Removal
* ========================================================
*/

.replace(/on\w+=".*?"/gi, '')

/**
* ========================================================
* HTML Tag Stripping
* ========================================================
*/

.replace(/<[^>]+>/g, '')
const htmlSanitized = sanitizeHtml(value, {
allowedTags: [],
allowedAttributes: {},
Expand All @@ -228,7 +258,9 @@ export class SanitizeInterceptor implements NestInterceptor {
* ========================================================
*/

.trim()
);
.trim();
} while (sanitized !== previous);

return sanitized;
}
}
Loading